@native-sdk/cli 0.9.1 → 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 (156) hide show
  1. package/build/app.zig +26 -9
  2. package/build.zig +124 -1
  3. package/package.json +9 -9
  4. package/packages/core/package-lock.json +2 -2
  5. package/packages/core/package.json +1 -1
  6. package/packages/core/sdk/core.ts +3 -1
  7. package/packages/core/sdk/events.d.ts +7 -0
  8. package/packages/core/sdk/events.ts +26 -5
  9. package/packages/core/sdk/text.d.ts +4 -0
  10. package/packages/core/sdk/text.ts +51 -0
  11. package/packages/core/src/checker.ts +58 -1
  12. package/packages/core/src/contract.ts +5 -4
  13. package/packages/core/src/devhost_journal.mjs +2 -2
  14. package/packages/core/src/diagnostics.ts +2 -2
  15. package/packages/core/src/service_contract.ts +10 -0
  16. package/packages/core/src/typed_ast.ts +9 -7
  17. package/packages/core/src/types.ts +28 -8
  18. package/skill-data/automation/SKILL.md +4 -3
  19. package/skill-data/native-ui/SKILL.md +10 -8
  20. package/skill-data/ts-core/SKILL.md +8 -5
  21. package/src/app_runner/root.zig +301 -12
  22. package/src/app_runner/ts_core_main.zig +6 -4
  23. package/src/app_runner/window_placement.zig +63 -0
  24. package/src/automation/protocol.zig +5 -1
  25. package/src/automation/snapshot.zig +119 -0
  26. package/src/embed/app_exports.zig +2 -1
  27. package/src/embed/conversions.zig +1 -0
  28. package/src/embed/host.zig +10 -3
  29. package/src/embed/root.zig +1 -0
  30. package/src/embed/tests.zig +13 -1
  31. package/src/embed/types.zig +2 -0
  32. package/src/embed/ui_host.zig +26 -2
  33. package/src/platform/android/NativeSdkActivity.java +49 -4
  34. package/src/platform/android/android_host.c +3 -3
  35. package/src/platform/android/native_sdk_app.h +1 -1
  36. package/src/platform/ios/apple_image_fit.h +38 -0
  37. package/src/platform/ios/files.zig +1 -0
  38. package/src/platform/ios/native_sdk_app.h +1 -1
  39. package/src/platform/ios/uikit_host.m +28 -5
  40. package/src/platform/linux/cef_host.cpp +10 -2
  41. package/src/platform/linux/gtk_host.c +43 -10
  42. package/src/platform/linux/gtk_host.h +3 -3
  43. package/src/platform/linux/root.zig +22 -7
  44. package/src/platform/macos/appkit_host.h +7 -4
  45. package/src/platform/macos/appkit_host.m +271 -52
  46. package/src/platform/macos/cef_host.mm +132 -34
  47. package/src/platform/macos/image_fit_test.m +44 -0
  48. package/src/platform/macos/root.zig +222 -14
  49. package/src/platform/null_platform.zig +17 -3
  50. package/src/platform/null_platform_tests.zig +58 -4
  51. package/src/platform/root.zig +2 -0
  52. package/src/platform/types.zig +69 -19
  53. package/src/platform/windows/root.zig +22 -7
  54. package/src/platform/windows/webview2_host.cpp +31 -6
  55. package/src/primitives/app_manifest/root.zig +3 -0
  56. package/src/primitives/app_manifest/tests.zig +24 -0
  57. package/src/primitives/app_manifest/types.zig +13 -0
  58. package/src/primitives/app_manifest/validation.zig +24 -0
  59. package/src/primitives/canvas/a11y_audit.zig +9 -7
  60. package/src/primitives/canvas/a11y_audit_tests.zig +24 -0
  61. package/src/primitives/canvas/events.zig +129 -1
  62. package/src/primitives/canvas/layout_audit.zig +6 -6
  63. package/src/primitives/canvas/markdown.zig +4 -0
  64. package/src/primitives/canvas/markdown_tests.zig +1 -0
  65. package/src/primitives/canvas/png.zig +138 -0
  66. package/src/primitives/canvas/root.zig +14 -2
  67. package/src/primitives/canvas/text_interaction.zig +23 -0
  68. package/src/primitives/canvas/text_span_tests.zig +5 -3
  69. package/src/primitives/canvas/text_spans.zig +2 -0
  70. package/src/primitives/canvas/text_tests.zig +65 -0
  71. package/src/primitives/canvas/ui.zig +66 -10
  72. package/src/primitives/canvas/ui_markup.zig +40 -13
  73. package/src/primitives/canvas/ui_markup_binary.zig +8 -6
  74. package/src/primitives/canvas/ui_markup_binary_tests.zig +14 -4
  75. package/src/primitives/canvas/ui_markup_compiled.zig +5 -1
  76. package/src/primitives/canvas/ui_markup_compiled_tests.zig +55 -0
  77. package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
  78. package/src/primitives/canvas/ui_markup_tests.zig +11 -2
  79. package/src/primitives/canvas/ui_markup_view.zig +8 -2
  80. package/src/primitives/canvas/ui_markup_view_tests.zig +67 -6
  81. package/src/primitives/canvas/ui_schema.zig +17 -13
  82. package/src/primitives/canvas/ui_tests.zig +84 -0
  83. package/src/primitives/canvas/widget_access.zig +3 -3
  84. package/src/primitives/canvas/widget_anchored_tests.zig +106 -0
  85. package/src/primitives/canvas/widget_builtin_tests.zig +593 -32
  86. package/src/primitives/canvas/widget_invalidation.zig +33 -6
  87. package/src/primitives/canvas/widget_layout.zig +333 -126
  88. package/src/primitives/canvas/widget_layout_tests.zig +169 -0
  89. package/src/primitives/canvas/widget_metrics.zig +7 -8
  90. package/src/primitives/canvas/widget_render.zig +76 -44
  91. package/src/primitives/canvas/widget_render_controls.zig +110 -32
  92. package/src/primitives/canvas/widget_render_style.zig +58 -18
  93. package/src/primitives/canvas/widget_render_surfaces.zig +45 -14
  94. package/src/primitives/canvas/widget_routing.zig +40 -34
  95. package/src/primitives/canvas/widget_runtime.zig +11 -2
  96. package/src/primitives/canvas/widget_runtime_tests.zig +10 -14
  97. package/src/primitives/canvas/widget_semantics.zig +8 -3
  98. package/src/primitives/canvas/widget_semantics_tests.zig +6 -2
  99. package/src/primitives/canvas/widget_tree.zig +99 -5
  100. package/src/primitives/canvas/widgets.zig +20 -7
  101. package/src/root.zig +3 -0
  102. package/src/runtime/api.zig +6 -0
  103. package/src/runtime/automation_snapshot.zig +4 -0
  104. package/src/runtime/automation_widget_dispatch.zig +48 -6
  105. package/src/runtime/builtin_bridge.zig +5 -2
  106. package/src/runtime/canvas_frame_packet_tests.zig +22 -13
  107. package/src/runtime/canvas_image_tests.zig +146 -2
  108. package/src/runtime/canvas_images.zig +35 -16
  109. package/src/runtime/canvas_limits.zig +13 -3
  110. package/src/runtime/canvas_widget_accessibility_tests.zig +279 -4
  111. package/src/runtime/canvas_widget_anchored_tests.zig +54 -0
  112. package/src/runtime/canvas_widget_control_tests.zig +33 -1
  113. package/src/runtime/canvas_widget_events.zig +151 -26
  114. package/src/runtime/canvas_widget_floating_tests.zig +48 -0
  115. package/src/runtime/canvas_widget_runtime.zig +322 -102
  116. package/src/runtime/canvas_widget_scroll_driver_tests.zig +34 -0
  117. package/src/runtime/canvas_widget_scroll_drivers.zig +12 -10
  118. package/src/runtime/canvas_widget_scroll_tests.zig +193 -2
  119. package/src/runtime/canvas_widget_semantics_tests.zig +337 -3
  120. package/src/runtime/canvas_widget_split_tree_tests.zig +55 -0
  121. package/src/runtime/canvas_widget_state.zig +33 -7
  122. package/src/runtime/canvas_widget_text_tests.zig +124 -0
  123. package/src/runtime/core.zig +16 -0
  124. package/src/runtime/effects.zig +14 -14
  125. package/src/runtime/effects_image_tests.zig +91 -0
  126. package/src/runtime/gpu_surface_events.zig +25 -2
  127. package/src/runtime/native_command_event_tests.zig +29 -0
  128. package/src/runtime/root.zig +2 -0
  129. package/src/runtime/session_journal.zig +21 -2
  130. package/src/runtime/session_replay.zig +13 -8
  131. package/src/runtime/session_tests.zig +111 -4
  132. package/src/runtime/shell_layout_tests.zig +12 -0
  133. package/src/runtime/ts_core_host_tests.zig +47 -0
  134. package/src/runtime/ts_ui_app.zig +164 -1
  135. package/src/runtime/ui_app.zig +100 -21
  136. package/src/runtime/ui_app_tests.zig +351 -32
  137. package/src/runtime/ui_app_window_tests.zig +13 -1
  138. package/src/runtime/view.zig +3 -0
  139. package/src/runtime/view_widget_control.zig +18 -0
  140. package/src/runtime/view_widget_scroll.zig +112 -18
  141. package/src/runtime/view_widget_text.zig +1 -1
  142. package/src/runtime/view_widget_tree.zig +110 -13
  143. package/src/runtime/widget_bridge.zig +2 -0
  144. package/src/runtime/window_command_bridge_tests.zig +86 -0
  145. package/src/runtime/window_storage.zig +16 -1
  146. package/src/runtime/window_views.zig +1 -0
  147. package/src/tooling/ios.zig +3 -0
  148. package/src/tooling/manifest.zig +90 -2
  149. package/src/tooling/package.zig +67 -2
  150. package/src/tooling/raw_manifest.zig +10 -0
  151. package/src/tooling/templates.zig +128 -18
  152. package/src/tooling/verbs.zig +1 -0
  153. package/src/tooling/web_engine.zig +1 -1
  154. package/tools/corewire/emit.zig +31 -12
  155. package/tools/corewire/emit_facade.zig +57 -2
  156. package/tools/corewire/shim_rt.zig +20 -0
@@ -3,9 +3,18 @@ const build_options = @import("build_options");
3
3
  const native_sdk = @import("native_sdk");
4
4
  const app_manifest = @import("app_manifest_zon");
5
5
  const built_relational_migrations = @import("relational_migrations");
6
+ const window_placement = @import("window_placement.zig");
7
+ const manifest_commands = if (@hasField(@TypeOf(app_manifest), "commands")) app_manifest.commands else .{};
6
8
  const manifest_shortcuts = if (@hasField(@TypeOf(app_manifest), "shortcuts")) app_manifest.shortcuts else .{};
9
+ const manifest_menus = if (@hasField(@TypeOf(app_manifest), "menus")) app_manifest.menus else .{};
7
10
  const manifest_windows = if (@hasField(@TypeOf(app_manifest), "windows")) app_manifest.windows else .{};
8
11
 
12
+ fn manifestImagePixelBudget() usize {
13
+ if (comptime !@hasField(@TypeOf(app_manifest), "images")) return native_sdk.max_registered_canvas_image_pixel_bytes;
14
+ if (comptime !@hasField(@TypeOf(app_manifest.images), "max_image_pixel_bytes")) return native_sdk.max_registered_canvas_image_pixel_bytes;
15
+ return app_manifest.images.max_image_pixel_bytes;
16
+ }
17
+
9
18
  pub const app_assets = @import("app_assets.zig");
10
19
 
11
20
  pub const StdoutTraceSink = struct {
@@ -49,11 +58,14 @@ pub const RunOptions = struct {
49
58
  icon_path: []const u8 = "assets/icon.png",
50
59
  default_frame: native_sdk.geometry.RectF = native_sdk.geometry.RectF.init(0, 0, 1100, 760),
51
60
  restore_state: bool = true,
61
+ restore_policy: native_sdk.WindowRestorePolicy = .clamp_to_visible_screen,
62
+ initial_placement: native_sdk.WindowInitialPlacement = .default,
52
63
  bridge: ?native_sdk.BridgeDispatcher = null,
53
64
  builtin_bridge: native_sdk.BridgePolicy = .{},
54
65
  js_window_api: bool = false,
55
66
  security: native_sdk.SecurityPolicy = .{},
56
- menus: []const native_sdk.Menu = &.{},
67
+ commands: ?[]const native_sdk.Command = null,
68
+ menus: ?[]const native_sdk.Menu = null,
57
69
  shortcuts: ?[]const native_sdk.Shortcut = null,
58
70
  /// Filled by `runWithOptions` from the manifest capability. App entry
59
71
  /// points do not set this themselves; the field only carries the owned
@@ -79,6 +91,7 @@ pub const RunOptions = struct {
79
91
  .description = manifestStringField("description"),
80
92
  .has_web_content = manifestHasWebContent(),
81
93
  .declares_tray = manifestDeclaresTrayCapability(),
94
+ .dock_visible = manifestDockVisible(),
82
95
  .window_title = self.window_title,
83
96
  .bundle_id = self.bundle_id,
84
97
  .icon_path = self.icon_path,
@@ -88,6 +101,8 @@ pub const RunOptions = struct {
88
101
  .title = self.window_title,
89
102
  .default_frame = self.default_frame,
90
103
  .restore_state = self.restore_state,
104
+ .restore_policy = self.restore_policy,
105
+ .initial_placement = self.initial_placement,
91
106
  },
92
107
  };
93
108
  const windows = manifestWindowOptions(buffers);
@@ -103,8 +118,12 @@ pub const RunOptions = struct {
103
118
  // a canvas-first startup window is created ordered-out and
104
119
  // shown after its first canvas frame presents, so launch
105
120
  // never flashes a blank window.
121
+ info.main_window.default_frame = manifestShellStartupFrame(info.main_window.default_frame);
122
+ info.main_window.restore_state = manifestShellStartupRestoreState(info.main_window.restore_state);
106
123
  info.main_window.titlebar = manifestShellStartupTitlebar();
107
124
  info.main_window.resizable = manifestShellStartupResizable();
125
+ info.main_window.restore_policy = manifestShellStartupRestorePolicy(info.main_window.restore_policy);
126
+ info.main_window.initial_placement = manifestShellStartupInitialPlacement(info.main_window.initial_placement);
108
127
  info.main_window.show = manifestShellStartupShowMode();
109
128
  info.main_window.transparent = manifestShellStartupBool("transparent", false);
110
129
  info.main_window.always_on_top = manifestShellStartupBool("always_on_top", false);
@@ -126,6 +145,72 @@ pub const RunOptions = struct {
126
145
  fn resolvedShortcuts(self: RunOptions, storage: *ShortcutStorage) []const native_sdk.Shortcut {
127
146
  return self.shortcuts orelse storage.fromManifest();
128
147
  }
148
+
149
+ fn resolvedCommands(self: RunOptions, storage: *CommandStorage) []const native_sdk.Command {
150
+ return self.commands orelse storage.fromManifest();
151
+ }
152
+
153
+ fn resolvedMenus(self: RunOptions, storage: *MenuStorage) []const native_sdk.Menu {
154
+ return self.menus orelse storage.fromManifest();
155
+ }
156
+ };
157
+
158
+ const CommandStorage = struct {
159
+ commands: [native_sdk.app_manifest.max_commands]native_sdk.Command = undefined,
160
+
161
+ fn fromManifest(self: *CommandStorage) []const native_sdk.Command {
162
+ comptime {
163
+ if (manifest_commands.len > native_sdk.app_manifest.max_commands) {
164
+ @compileError("app.zon defines too many commands");
165
+ }
166
+ }
167
+
168
+ inline for (manifest_commands, 0..) |command, index| {
169
+ self.commands[index] = .{
170
+ .id = command.id,
171
+ .title = if (@hasField(@TypeOf(command), "title")) command.title else "",
172
+ .enabled = if (@hasField(@TypeOf(command), "enabled")) command.enabled else true,
173
+ .checked = if (@hasField(@TypeOf(command), "checked")) command.checked else false,
174
+ };
175
+ }
176
+ return self.commands[0..manifest_commands.len];
177
+ }
178
+ };
179
+
180
+ const MenuStorage = struct {
181
+ menus: [native_sdk.platform.max_menus]native_sdk.Menu = undefined,
182
+ items: [native_sdk.platform.max_menu_items]native_sdk.MenuItem = undefined,
183
+
184
+ fn fromManifest(self: *MenuStorage) []const native_sdk.Menu {
185
+ comptime {
186
+ if (manifest_menus.len > native_sdk.platform.max_menus) {
187
+ @compileError("app.zon defines too many menus");
188
+ }
189
+ var item_count: usize = 0;
190
+ for (manifest_menus) |menu| {
191
+ const items = if (@hasField(@TypeOf(menu), "items")) menu.items else .{};
192
+ item_count += items.len;
193
+ }
194
+ if (item_count > native_sdk.platform.max_menu_items) {
195
+ @compileError("app.zon defines too many menu items");
196
+ }
197
+ }
198
+
199
+ var item_index: usize = 0;
200
+ inline for (manifest_menus, 0..) |menu, menu_index| {
201
+ const items = if (@hasField(@TypeOf(menu), "items")) menu.items else .{};
202
+ const first_item = item_index;
203
+ inline for (items) |item| {
204
+ self.items[item_index] = menuItem(item);
205
+ item_index += 1;
206
+ }
207
+ self.menus[menu_index] = .{
208
+ .title = menu.title,
209
+ .items = self.items[first_item..item_index],
210
+ };
211
+ }
212
+ return self.menus[0..manifest_menus.len];
213
+ }
129
214
  };
130
215
 
131
216
  const ShortcutStorage = struct {
@@ -176,6 +261,7 @@ fn manifestWindow(comptime window: anytype, comptime index: usize) native_sdk.Wi
176
261
  .resizable = windowBool(window, "resizable", true),
177
262
  .restore_state = windowBool(window, "restore_state", true),
178
263
  .restore_policy = windowRestorePolicy(window),
264
+ .initial_placement = if (windowHasExplicitOrigin(window)) .explicit else .default,
179
265
  .titlebar = windowTitlebarStyle(window),
180
266
  .show = if (windowBool(window, "initially_hidden", false)) .hidden else .immediate,
181
267
  .transparent = windowBool(window, "transparent", false),
@@ -411,6 +497,60 @@ fn windowRestorePolicy(comptime window: anytype) native_sdk.WindowRestorePolicy
411
497
  @compileError("unknown app.zon window restore_policy");
412
498
  }
413
499
 
500
+ fn windowHasExplicitOrigin(comptime window: anytype) bool {
501
+ return @hasField(@TypeOf(window), "x") or @hasField(@TypeOf(window), "y");
502
+ }
503
+
504
+ /// The host creates the first scene window before the scene loads, so its
505
+ /// authored frame must ride AppInfo with the other creation-time options.
506
+ /// Omitted fields preserve RunOptions' direct-SDK fallback independently.
507
+ fn manifestShellStartupFrame(fallback: native_sdk.geometry.RectF) native_sdk.geometry.RectF {
508
+ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
509
+ const shell = app_manifest.shell;
510
+ if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
511
+ if (comptime shell.windows.len == 0) return fallback;
512
+ const window = shell.windows[0];
513
+ return native_sdk.geometry.RectF.init(
514
+ windowFloatFallback(window, "x", fallback.x),
515
+ windowFloatFallback(window, "y", fallback.y),
516
+ windowFloatFallback(window, "width", fallback.width),
517
+ windowFloatFallback(window, "height", fallback.height),
518
+ );
519
+ }
520
+
521
+ fn windowFloatFallback(comptime window: anytype, comptime field: []const u8, fallback: f32) f32 {
522
+ if (comptime @hasField(@TypeOf(window), field)) return @field(window, field);
523
+ return fallback;
524
+ }
525
+
526
+ fn manifestShellStartupRestoreState(fallback: bool) bool {
527
+ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
528
+ const shell = app_manifest.shell;
529
+ if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
530
+ if (comptime shell.windows.len == 0) return fallback;
531
+ const window = shell.windows[0];
532
+ if (comptime @hasField(@TypeOf(window), "restore_state")) return window.restore_state;
533
+ return fallback;
534
+ }
535
+
536
+ fn manifestShellStartupRestorePolicy(fallback: native_sdk.WindowRestorePolicy) native_sdk.WindowRestorePolicy {
537
+ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
538
+ const shell = app_manifest.shell;
539
+ if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
540
+ if (comptime shell.windows.len == 0) return fallback;
541
+ const window = shell.windows[0];
542
+ const declared: ?native_sdk.WindowRestorePolicy = if (comptime @hasField(@TypeOf(window), "restore_policy")) windowRestorePolicy(window) else null;
543
+ return window_placement.applyShellRestorePolicy(fallback, declared);
544
+ }
545
+
546
+ fn manifestShellStartupInitialPlacement(fallback: native_sdk.WindowInitialPlacement) native_sdk.WindowInitialPlacement {
547
+ if (comptime !@hasField(@TypeOf(app_manifest), "shell")) return fallback;
548
+ const shell = app_manifest.shell;
549
+ if (comptime !@hasField(@TypeOf(shell), "windows")) return fallback;
550
+ if (comptime shell.windows.len == 0) return fallback;
551
+ return window_placement.applyShellInitialPlacement(fallback, windowHasExplicitOrigin(shell.windows[0]));
552
+ }
553
+
414
554
  /// What the window's close affordance does, from app.zon. `.hide` is
415
555
  /// validated against the TARGET platform at comptime: a host with no
416
556
  /// affordance to bring a hidden window back (GTK has no status item;
@@ -447,6 +587,17 @@ fn manifestDeclaresTrayCapability() bool {
447
587
  return false;
448
588
  }
449
589
 
590
+ /// Initial Dock/app-switcher presence. The validation is repeated at
591
+ /// comptime so a custom/ejected build cannot bypass the same safety
592
+ /// rule as `native validate` and strand an accessory app with no tray.
593
+ fn manifestDockVisible() bool {
594
+ const visible = if (comptime @hasField(@TypeOf(app_manifest), "dock_visible")) app_manifest.dock_visible else true;
595
+ if (comptime !visible and !manifestDeclaresTrayCapability()) {
596
+ @compileError("app.zon dock_visible = false requires the \"tray\" capability: an accessory app has no Dock/app-switcher route back to hidden windows - add \"tray\" to .capabilities and install a status item, or keep dock_visible = true (the default)");
597
+ }
598
+ return visible;
599
+ }
600
+
450
601
  /// Whether app.zon declares the Tier-2 record store. This is comptime so
451
602
  /// apps without the capability never analyze the SQLite open/deinit path.
452
603
  fn manifestDeclaresStore() bool {
@@ -476,6 +627,18 @@ fn manifestDeclaresCredentials() bool {
476
627
  return false;
477
628
  }
478
629
 
630
+ fn menuItem(comptime item: anytype) native_sdk.MenuItem {
631
+ return .{
632
+ .label = if (@hasField(@TypeOf(item), "label")) item.label else "",
633
+ .command = if (@hasField(@TypeOf(item), "command")) item.command else "",
634
+ .key = if (@hasField(@TypeOf(item), "key")) item.key else "",
635
+ .modifiers = shortcutModifiers(item),
636
+ .separator = if (@hasField(@TypeOf(item), "separator")) item.separator else false,
637
+ .enabled = if (@hasField(@TypeOf(item), "enabled")) item.enabled else true,
638
+ .checked = if (@hasField(@TypeOf(item), "checked")) item.checked else false,
639
+ };
640
+ }
641
+
479
642
  fn shortcutModifiers(comptime shortcut: anytype) native_sdk.ShortcutModifiers {
480
643
  const values = if (@hasField(@TypeOf(shortcut), "modifiers")) shortcut.modifiers else .{};
481
644
  var modifiers: native_sdk.ShortcutModifiers = .{};
@@ -615,6 +778,10 @@ fn runNull(app: native_sdk.App, options: RunOptions, init: std.process.Init) !vo
615
778
  runtime_trace_sink = filtered_trace_sink.sink();
616
779
  var shortcut_storage: ShortcutStorage = .{};
617
780
  const shortcuts = options.resolvedShortcuts(&shortcut_storage);
781
+ var menu_storage: MenuStorage = .{};
782
+ const menus = options.resolvedMenus(&menu_storage);
783
+ var command_storage: CommandStorage = .{};
784
+ const commands = options.resolvedCommands(&command_storage);
618
785
  // The Runtime is multi-megabyte; Linux's default 8 MB main-thread
619
786
  // stack overflows on a stack instance, so construct it on the heap.
620
787
  const runtime = try std.heap.page_allocator.create(native_sdk.Runtime);
@@ -626,6 +793,7 @@ fn runNull(app: native_sdk.App, options: RunOptions, init: std.process.Init) !vo
626
793
  defer runtime.deinit();
627
794
  native_sdk.Runtime.initAt(runtime, .{
628
795
  .platform = null_platform.platform(),
796
+ .max_image_pixel_bytes = manifestImagePixelBudget(),
629
797
  .trace_sink = runtime_trace_sink,
630
798
  .log_path = if (log_setup) |setup| setup.paths.log_file else null,
631
799
  .bridge = options.bridge,
@@ -634,7 +802,8 @@ fn runNull(app: native_sdk.App, options: RunOptions, init: std.process.Init) !vo
634
802
  .web_layer = webLayerEnabled(),
635
803
  .gpu_surface_frame_diagnostics = false,
636
804
  .security = options.security,
637
- .menus = options.menus,
805
+ .commands = commands,
806
+ .menus = menus,
638
807
  .shortcuts = shortcuts,
639
808
  .automation = if (build_options.automation) native_sdk.automation.Server.init(init.io, ".zig-cache/native-sdk-automation", app_info.resolvedWindowTitle()) else null,
640
809
  .window_state_store = store,
@@ -683,6 +852,10 @@ fn runMacos(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
683
852
  runtime_trace_sink = filtered_trace_sink.sink();
684
853
  var shortcut_storage: ShortcutStorage = .{};
685
854
  const shortcuts = options.resolvedShortcuts(&shortcut_storage);
855
+ var menu_storage: MenuStorage = .{};
856
+ const menus = options.resolvedMenus(&menu_storage);
857
+ var command_storage: CommandStorage = .{};
858
+ const commands = options.resolvedCommands(&command_storage);
686
859
  // The Runtime is multi-megabyte; Linux's default 8 MB main-thread
687
860
  // stack overflows on a stack instance, so construct it on the heap.
688
861
  const runtime = try std.heap.page_allocator.create(native_sdk.Runtime);
@@ -694,6 +867,7 @@ fn runMacos(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
694
867
  defer runtime.deinit();
695
868
  native_sdk.Runtime.initAt(runtime, .{
696
869
  .platform = mac_platform.platform(),
870
+ .max_image_pixel_bytes = manifestImagePixelBudget(),
697
871
  .trace_sink = runtime_trace_sink,
698
872
  .log_path = if (log_setup) |setup| setup.paths.log_file else null,
699
873
  .bridge = options.bridge,
@@ -702,7 +876,8 @@ fn runMacos(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
702
876
  .web_layer = webLayerEnabled(),
703
877
  .gpu_surface_frame_diagnostics = false,
704
878
  .security = options.security,
705
- .menus = options.menus,
879
+ .commands = commands,
880
+ .menus = menus,
706
881
  .shortcuts = shortcuts,
707
882
  .automation = if (build_options.automation) native_sdk.automation.Server.init(init.io, ".zig-cache/native-sdk-automation", app_info.resolvedWindowTitle()) else null,
708
883
  .window_state_store = store,
@@ -748,6 +923,10 @@ fn runLinux(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
748
923
  runtime_trace_sink = filtered_trace_sink.sink();
749
924
  var shortcut_storage: ShortcutStorage = .{};
750
925
  const shortcuts = options.resolvedShortcuts(&shortcut_storage);
926
+ var menu_storage: MenuStorage = .{};
927
+ const menus = options.resolvedMenus(&menu_storage);
928
+ var command_storage: CommandStorage = .{};
929
+ const commands = options.resolvedCommands(&command_storage);
751
930
  // The Runtime is multi-megabyte; Linux's default 8 MB main-thread
752
931
  // stack overflows on a stack instance, so construct it on the heap.
753
932
  const runtime = try std.heap.page_allocator.create(native_sdk.Runtime);
@@ -759,6 +938,7 @@ fn runLinux(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
759
938
  defer runtime.deinit();
760
939
  native_sdk.Runtime.initAt(runtime, .{
761
940
  .platform = linux_platform.platform(),
941
+ .max_image_pixel_bytes = manifestImagePixelBudget(),
762
942
  .trace_sink = runtime_trace_sink,
763
943
  .log_path = if (log_setup) |setup| setup.paths.log_file else null,
764
944
  .bridge = options.bridge,
@@ -767,7 +947,8 @@ fn runLinux(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
767
947
  .web_layer = webLayerEnabled(),
768
948
  .gpu_surface_frame_diagnostics = false,
769
949
  .security = options.security,
770
- .menus = options.menus,
950
+ .commands = commands,
951
+ .menus = menus,
771
952
  .shortcuts = shortcuts,
772
953
  .automation = if (build_options.automation) native_sdk.automation.Server.init(init.io, ".zig-cache/native-sdk-automation", app_info.resolvedWindowTitle()) else null,
773
954
  .window_state_store = store,
@@ -812,6 +993,10 @@ fn runWindows(app: native_sdk.App, options: RunOptions, init: std.process.Init)
812
993
  runtime_trace_sink = filtered_trace_sink.sink();
813
994
  var shortcut_storage: ShortcutStorage = .{};
814
995
  const shortcuts = options.resolvedShortcuts(&shortcut_storage);
996
+ var menu_storage: MenuStorage = .{};
997
+ const menus = options.resolvedMenus(&menu_storage);
998
+ var command_storage: CommandStorage = .{};
999
+ const commands = options.resolvedCommands(&command_storage);
815
1000
  // The Runtime is multi-megabyte; Linux's default 8 MB main-thread
816
1001
  // stack overflows on a stack instance, so construct it on the heap.
817
1002
  const runtime = try std.heap.page_allocator.create(native_sdk.Runtime);
@@ -823,6 +1008,7 @@ fn runWindows(app: native_sdk.App, options: RunOptions, init: std.process.Init)
823
1008
  defer runtime.deinit();
824
1009
  native_sdk.Runtime.initAt(runtime, .{
825
1010
  .platform = windows_platform.platform(),
1011
+ .max_image_pixel_bytes = manifestImagePixelBudget(),
826
1012
  .trace_sink = runtime_trace_sink,
827
1013
  .log_path = if (log_setup) |setup| setup.paths.log_file else null,
828
1014
  .bridge = options.bridge,
@@ -831,7 +1017,8 @@ fn runWindows(app: native_sdk.App, options: RunOptions, init: std.process.Init)
831
1017
  .web_layer = webLayerEnabled(),
832
1018
  .gpu_surface_frame_diagnostics = false,
833
1019
  .security = options.security,
834
- .menus = options.menus,
1020
+ .commands = commands,
1021
+ .menus = menus,
835
1022
  .shortcuts = shortcuts,
836
1023
  .automation = if (build_options.automation) native_sdk.automation.Server.init(init.io, ".zig-cache/native-sdk-automation", app_info.resolvedWindowTitle()) else null,
837
1024
  .window_state_store = store,
@@ -972,18 +1159,27 @@ fn runSessionReplay(app: native_sdk.App, options: RunOptions, init: std.process.
972
1159
  // (and disarm the producer wake bindings) before the runtime
973
1160
  // storage itself goes.
974
1161
  defer runtime.deinit();
1162
+ var shortcut_storage: ShortcutStorage = .{};
1163
+ const shortcuts = options.resolvedShortcuts(&shortcut_storage);
1164
+ var menu_storage: MenuStorage = .{};
1165
+ const menus = options.resolvedMenus(&menu_storage);
1166
+ var command_storage: CommandStorage = .{};
1167
+ const commands = options.resolvedCommands(&command_storage);
975
1168
  // Bridge policy and security must match what the recording ran
976
1169
  // under (they gate replayed bridge_message dispatch); automation,
977
1170
  // window-state restore, and tracing stay off — replay consumes only
978
1171
  // the journal and restores nothing.
979
1172
  native_sdk.Runtime.initAt(runtime, .{
980
1173
  .platform = replay_platform,
1174
+ .max_image_pixel_bytes = manifestImagePixelBudget(),
981
1175
  .bridge = options.bridge,
982
1176
  .builtin_bridge = options.builtin_bridge,
983
1177
  .js_window_api = options.js_window_api,
984
1178
  .web_layer = webLayerEnabled(),
985
1179
  .security = options.security,
986
- .menus = options.menus,
1180
+ .commands = commands,
1181
+ .menus = menus,
1182
+ .shortcuts = shortcuts,
987
1183
  });
988
1184
 
989
1185
  const verify = if (init.environ_map.get("NATIVE_SDK_SESSION_VERIFY")) |value|
@@ -1055,6 +1251,99 @@ fn webEngine() native_sdk.WebEngine {
1055
1251
  return .system;
1056
1252
  }
1057
1253
 
1254
+ test "RunOptions resolves manifest commands menus and shortcuts" {
1255
+ const options: RunOptions = .{
1256
+ .app_name = "runner-fixture",
1257
+ .bundle_id = "dev.native_sdk.runner_fixture",
1258
+ };
1259
+
1260
+ var command_storage: CommandStorage = .{};
1261
+ const commands = options.resolvedCommands(&command_storage);
1262
+ try std.testing.expectEqual(@as(usize, 2), commands.len);
1263
+ try std.testing.expectEqualStrings("app.refresh", commands[0].id);
1264
+ try std.testing.expectEqualStrings("Refresh", commands[0].title);
1265
+ try std.testing.expect(!commands[0].enabled);
1266
+ try std.testing.expect(commands[0].checked);
1267
+ try std.testing.expectEqualStrings("app.defaults", commands[1].id);
1268
+ try std.testing.expectEqualStrings("", commands[1].title);
1269
+ try std.testing.expect(commands[1].enabled);
1270
+ try std.testing.expect(!commands[1].checked);
1271
+
1272
+ var menu_storage: MenuStorage = .{};
1273
+ const menus = options.resolvedMenus(&menu_storage);
1274
+ try std.testing.expectEqual(@as(usize, 2), menus.len);
1275
+ try std.testing.expectEqualStrings("View", menus[0].title);
1276
+ try std.testing.expectEqual(@as(usize, 3), menus[0].items.len);
1277
+ try std.testing.expectEqualStrings("Refresh", menus[0].items[0].label);
1278
+ try std.testing.expectEqualStrings("app.refresh", menus[0].items[0].command);
1279
+ try std.testing.expectEqualStrings("r", menus[0].items[0].key);
1280
+ try std.testing.expect(menus[0].items[0].modifiers.option);
1281
+ try std.testing.expect(menus[0].items[0].modifiers.shift);
1282
+ try std.testing.expect(!menus[0].items[0].enabled);
1283
+ try std.testing.expect(menus[0].items[0].checked);
1284
+ try std.testing.expect(menus[0].items[1].separator);
1285
+ try std.testing.expectEqualStrings("Defaults", menus[0].items[2].label);
1286
+ try std.testing.expect(menus[0].items[2].enabled);
1287
+ try std.testing.expect(!menus[0].items[2].checked);
1288
+ try std.testing.expectEqualStrings("Help", menus[1].title);
1289
+ try std.testing.expectEqual(@as(usize, 0), menus[1].items.len);
1290
+
1291
+ var shortcut_storage: ShortcutStorage = .{};
1292
+ const shortcuts = options.resolvedShortcuts(&shortcut_storage);
1293
+ try std.testing.expectEqual(@as(usize, 1), shortcuts.len);
1294
+ try std.testing.expectEqualStrings("app.refresh", shortcuts[0].id);
1295
+ try std.testing.expectEqualStrings("r", shortcuts[0].key);
1296
+ try std.testing.expect(shortcuts[0].modifiers.primary);
1297
+ }
1298
+
1299
+ test "RunOptions explicit command menu and shortcut slices override manifest values" {
1300
+ const override_commands = [_]native_sdk.Command{
1301
+ .{ .id = "override.command", .title = "Override Command" },
1302
+ };
1303
+ const override_items = [_]native_sdk.MenuItem{
1304
+ .{ .label = "Override Item", .command = "override.command" },
1305
+ };
1306
+ const override_menus = [_]native_sdk.Menu{
1307
+ .{ .title = "Override Menu", .items = &override_items },
1308
+ };
1309
+ const override_shortcuts = [_]native_sdk.Shortcut{
1310
+ .{ .id = "override.command", .key = "o", .modifiers = .{ .primary = true } },
1311
+ };
1312
+ const options: RunOptions = .{
1313
+ .app_name = "runner-fixture",
1314
+ .bundle_id = "dev.native_sdk.runner_fixture",
1315
+ .commands = &override_commands,
1316
+ .menus = &override_menus,
1317
+ .shortcuts = &override_shortcuts,
1318
+ };
1319
+
1320
+ var command_storage: CommandStorage = .{};
1321
+ const commands = options.resolvedCommands(&command_storage);
1322
+ try std.testing.expectEqual(@as(usize, 1), commands.len);
1323
+ try std.testing.expectEqualStrings("override.command", commands[0].id);
1324
+
1325
+ var menu_storage: MenuStorage = .{};
1326
+ const menus = options.resolvedMenus(&menu_storage);
1327
+ try std.testing.expectEqual(@as(usize, 1), menus.len);
1328
+ try std.testing.expectEqualStrings("Override Menu", menus[0].title);
1329
+
1330
+ var shortcut_storage: ShortcutStorage = .{};
1331
+ const shortcuts = options.resolvedShortcuts(&shortcut_storage);
1332
+ try std.testing.expectEqual(@as(usize, 1), shortcuts.len);
1333
+ try std.testing.expectEqualStrings("override.command", shortcuts[0].id);
1334
+
1335
+ const empty_options: RunOptions = .{
1336
+ .app_name = "runner-fixture",
1337
+ .bundle_id = "dev.native_sdk.runner_fixture",
1338
+ .commands = &.{},
1339
+ .menus = &.{},
1340
+ .shortcuts = &.{},
1341
+ };
1342
+ try std.testing.expectEqual(@as(usize, 0), empty_options.resolvedCommands(&command_storage).len);
1343
+ try std.testing.expectEqual(@as(usize, 0), empty_options.resolvedMenus(&menu_storage).len);
1344
+ try std.testing.expectEqual(@as(usize, 0), empty_options.resolvedShortcuts(&shortcut_storage).len);
1345
+ }
1346
+
1058
1347
  const StateBuffers = struct {
1059
1348
  state_dir: [1024]u8 = undefined,
1060
1349
  file_path: [1200]u8 = undefined,
@@ -1069,15 +1358,15 @@ fn prepareStateStore(io: std.Io, env_map: *std.process.Environ.Map, app_info: *n
1069
1358
  const restored_windows = buffers.restored_windows[0..app_info.windows.len];
1070
1359
  for (restored_windows, 0..) |*window, index| {
1071
1360
  if (!window.restore_state) continue;
1072
- if (store.loadWindow(window.label, &buffers.read) catch null) |saved| {
1073
- window.default_frame = saved.frame;
1074
- if (index == 0) app_info.main_window.default_frame = saved.frame;
1361
+ if (window_placement.applySavedWindow(window, store.loadWindow(window.label, &buffers.read) catch null)) {
1362
+ if (index == 0) {
1363
+ app_info.main_window.default_frame = window.default_frame;
1364
+ app_info.main_window.initial_placement = .restored;
1365
+ }
1075
1366
  }
1076
1367
  }
1077
1368
  } else if (app_info.main_window.restore_state) {
1078
- if (store.loadWindow(app_info.main_window.label, &buffers.read) catch null) |saved| {
1079
- app_info.main_window.default_frame = saved.frame;
1080
- }
1369
+ _ = window_placement.applySavedWindow(&app_info.main_window, store.loadWindow(app_info.main_window.label, &buffers.read) catch null);
1081
1370
  }
1082
1371
  return store;
1083
1372
  }
@@ -399,10 +399,10 @@ const ImageAsset = struct {
399
399
  path: []const u8,
400
400
  };
401
401
 
402
- /// Encoded-size bound for one boot image: over-bound files skip their
403
- /// entry (the views keep the initials fallback) instead of holding the
404
- /// launch path hostage to a mis-sized asset.
405
- const max_boot_image_bytes: usize = 4 * 1024 * 1024;
402
+ /// Boot images and runtime image loads share one encoded-source contract:
403
+ /// over-bound files skip their entry (the views keep the initials fallback)
404
+ /// instead of holding the launch path hostage to a mis-sized asset.
405
+ const max_boot_image_bytes: usize = native_sdk.max_effect_image_source_bytes;
406
406
 
407
407
  fn manifestImages() []const ImageAsset {
408
408
  comptime {
@@ -477,6 +477,7 @@ fn manifestPersistDebounce(comptime config: anytype) u32 {
477
477
  }
478
478
 
479
479
  fn validatePersistRoutes(comptime routes: anytype) void {
480
+ @setEvalBranchQuota(Adapter.persist_route_scan_quota);
480
481
  if (!persistRouteMatches(routes.ok, void)) {
481
482
  @compileError("app.zon .persist.restore.ok must name a void Msg arm in src/core.ts");
482
483
  }
@@ -489,6 +490,7 @@ fn validatePersistRoutes(comptime routes: anytype) void {
489
490
  }
490
491
 
491
492
  fn persistRouteMatches(comptime name: []const u8, comptime Payload: type) bool {
493
+ @setEvalBranchQuota(Adapter.msg_scan_quota);
492
494
  const info = @typeInfo(core.Msg);
493
495
  if (info != .@"union") return false;
494
496
  inline for (info.@"union".fields) |field| {
@@ -0,0 +1,63 @@
1
+ const std = @import("std");
2
+ const native_sdk = @import("native_sdk");
3
+
4
+ /// Apply the state-store lookup result at the one layer that can distinguish
5
+ /// an actual restore from a fresh launch with persistence merely enabled.
6
+ pub fn applySavedWindow(window: *native_sdk.WindowOptions, saved: ?native_sdk.WindowState) bool {
7
+ const state = saved orelse return false;
8
+ window.default_frame = state.frame;
9
+ window.initial_placement = .restored;
10
+ return true;
11
+ }
12
+
13
+ /// An omitted shell field must not erase the caller's direct-SDK fallback.
14
+ pub fn applyShellRestorePolicy(fallback: native_sdk.WindowRestorePolicy, declared: ?native_sdk.WindowRestorePolicy) native_sdk.WindowRestorePolicy {
15
+ return declared orelse fallback;
16
+ }
17
+
18
+ /// Only an authored shell origin overrides the caller's placement reason.
19
+ pub fn applyShellInitialPlacement(fallback: native_sdk.WindowInitialPlacement, has_explicit_origin: bool) native_sdk.WindowInitialPlacement {
20
+ return if (has_explicit_origin) .explicit else fallback;
21
+ }
22
+
23
+ test "fresh default-restoring window keeps default placement on a store miss" {
24
+ var window: native_sdk.WindowOptions = .{ .restore_state = true };
25
+ try std.testing.expect(!applySavedWindow(&window, null));
26
+ try std.testing.expectEqual(native_sdk.WindowInitialPlacement.default, window.initial_placement);
27
+ }
28
+
29
+ test "fresh explicitly positioned window keeps explicit placement on a store miss" {
30
+ var window: native_sdk.WindowOptions = .{ .initial_placement = .explicit };
31
+ try std.testing.expect(!applySavedWindow(&window, null));
32
+ try std.testing.expectEqual(native_sdk.WindowInitialPlacement.explicit, window.initial_placement);
33
+ }
34
+
35
+ test "state-store hit replaces the frame and marks it restored" {
36
+ var window: native_sdk.WindowOptions = .{ .initial_placement = .explicit };
37
+ const frame = native_sdk.geometry.RectF.init(40, 60, 900, 640);
38
+ try std.testing.expect(applySavedWindow(&window, .{ .frame = frame }));
39
+ try std.testing.expectEqual(frame, window.default_frame);
40
+ try std.testing.expectEqual(native_sdk.WindowInitialPlacement.restored, window.initial_placement);
41
+ }
42
+
43
+ test "omitted shell placement fields preserve direct runner fallbacks" {
44
+ try std.testing.expectEqual(
45
+ native_sdk.WindowRestorePolicy.center_on_primary,
46
+ applyShellRestorePolicy(.center_on_primary, null),
47
+ );
48
+ try std.testing.expectEqual(
49
+ native_sdk.WindowInitialPlacement.restored,
50
+ applyShellInitialPlacement(.restored, false),
51
+ );
52
+ }
53
+
54
+ test "authored shell placement fields override direct runner fallbacks" {
55
+ try std.testing.expectEqual(
56
+ native_sdk.WindowRestorePolicy.clamp_to_visible_screen,
57
+ applyShellRestorePolicy(.center_on_primary, .clamp_to_visible_screen),
58
+ );
59
+ try std.testing.expectEqual(
60
+ native_sdk.WindowInitialPlacement.explicit,
61
+ applyShellInitialPlacement(.restored, true),
62
+ );
63
+ }
@@ -55,7 +55,11 @@ pub const fingerprint: u64 = layout_fingerprint.hash(layoutDescription(semantic_
55
55
  /// visibility, and `tray-action` gained the explicit
56
56
  /// `<status-item-id> <menu-item-id>` form (the old one-id primary-item
57
57
  /// shorthand remains valid).
58
- pub const semantic_epoch: u32 = 2;
58
+ /// Epoch 3: automation snapshots expose the app menus configured on the
59
+ /// runtime, including command ids and enabled/checked/key state.
60
+ /// Epoch 4: command and app-menu catalog strings in snapshots use
61
+ /// JSON-style escapes so every catalog entry remains exactly one line.
62
+ pub const semantic_epoch: u32 = 4;
59
63
 
60
64
  /// The canonical description the protocol fingerprint hashes: the
61
65
  /// command vocabulary (the `Action` enum, reflected — names and values,