@native-sdk/cli 0.8.3 → 0.9.0

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 (188) hide show
  1. package/build/app.zig +905 -61
  2. package/build.zig +674 -373
  3. package/build.zig.zon +1 -0
  4. package/native-sdk.d.ts +6 -0
  5. package/package.json +12 -11
  6. package/packages/core/compile-surface/core.ts +455 -3
  7. package/packages/core/package-lock.json +11 -11
  8. package/packages/core/package.json +2 -2
  9. package/packages/core/scripts/compiler_typecheck.mjs +116 -15
  10. package/packages/core/scripts/gen_service_surface.mjs +268 -0
  11. package/packages/core/scripts/npm_static_spike.mjs +64 -0
  12. package/packages/core/scripts/run_external_core_compiler.mjs +77 -6
  13. package/packages/core/scripts/run_external_service_compiler.mjs +240 -0
  14. package/packages/core/scripts/stage_external_core.mjs +9 -1
  15. package/packages/core/scripts/stage_external_services.mjs +172 -0
  16. package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
  17. package/packages/core/scripts/vendor_service_packages.mjs +189 -0
  18. package/packages/core/sdk/core.d.ts +214 -2
  19. package/packages/core/sdk/core.ts +715 -42
  20. package/packages/core/sdk/events.d.ts +50 -0
  21. package/packages/core/sdk/events.ts +75 -0
  22. package/packages/core/src/checker.ts +528 -15
  23. package/packages/core/src/cli.ts +143 -3
  24. package/packages/core/src/contract.ts +26 -5
  25. package/packages/core/src/devhost.ts +1849 -18
  26. package/packages/core/src/devhost_journal.mjs +181 -0
  27. package/packages/core/src/devhost_resolver.mjs +17 -1
  28. package/packages/core/src/devhost_service_worker.mjs +90 -0
  29. package/packages/core/src/diagnostics.ts +84 -18
  30. package/packages/core/src/frontend.ts +204 -34
  31. package/packages/core/src/modules.ts +129 -80
  32. package/packages/core/src/service_contract.ts +597 -0
  33. package/packages/core/src/sqlite_cli.ts +93 -0
  34. package/packages/core/src/sqlite_codegen.ts +806 -0
  35. package/packages/core/src/sqlite_runtime_policy.ts +364 -0
  36. package/packages/core/src/typed_ast.ts +36 -8
  37. package/skill-data/core/SKILL.md +4 -2
  38. package/skill-data/core/references/project-anatomy.md +3 -2
  39. package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
  40. package/skill-data/native-ui/SKILL.md +55 -8
  41. package/skill-data/ts-core/SKILL.md +92 -40
  42. package/skill-data/ts-services/SKILL.md +126 -0
  43. package/skill-data/ts-services/references/service-surface.md +603 -0
  44. package/skill-data/zig/SKILL.md +1 -1
  45. package/skills/native-sdk/SKILL.md +1 -1
  46. package/src/app_runner/no_migrations.zig +3 -0
  47. package/src/app_runner/no_services.zig +20 -0
  48. package/src/app_runner/root.zig +104 -4
  49. package/src/app_runner/ts_core_main.zig +268 -4
  50. package/src/automation/snapshot.zig +23 -5
  51. package/src/embed/app_exports.zig +11 -1
  52. package/src/embed/c_api.zig +48 -2
  53. package/src/embed/conversions.zig +4 -5
  54. package/src/embed/host.zig +115 -1
  55. package/src/embed/root.zig +7 -0
  56. package/src/embed/tests.zig +213 -0
  57. package/src/embed/types.zig +51 -0
  58. package/src/embed/ui_host.zig +121 -5
  59. package/src/platform/android/NativeSdkActivity.java +131 -0
  60. package/src/platform/android/android_host.c +182 -1
  61. package/src/platform/android/native_sdk_app.h +17 -0
  62. package/src/platform/ios/native_sdk_app.h +17 -0
  63. package/src/platform/ios/uikit_host.m +115 -0
  64. package/src/platform/linux/cef_host.cpp +1 -1
  65. package/src/platform/linux/gtk_host.c +89 -17
  66. package/src/platform/linux/gtk_host.h +3 -0
  67. package/src/platform/linux/root.zig +41 -18
  68. package/src/platform/macos/appkit_host.h +26 -3
  69. package/src/platform/macos/appkit_host.m +1051 -129
  70. package/src/platform/macos/capture_info_plist.c +25 -0
  71. package/src/platform/macos/cef_host.mm +270 -36
  72. package/src/platform/macos/root.zig +312 -34
  73. package/src/platform/null_platform.zig +281 -19
  74. package/src/platform/null_platform_tests.zig +74 -0
  75. package/src/platform/root.zig +16 -0
  76. package/src/platform/types.zig +279 -15
  77. package/src/platform/windows/root.zig +243 -21
  78. package/src/platform/windows/webview2_host.cpp +464 -46
  79. package/src/primitives/app_manifest/comptime_scene.zig +2 -0
  80. package/src/primitives/app_manifest/root.zig +4 -0
  81. package/src/primitives/app_manifest/tests.zig +3 -0
  82. package/src/primitives/app_manifest/types.zig +34 -0
  83. package/src/primitives/app_manifest/validation.zig +19 -1
  84. package/src/primitives/canvas/code_tests.zig +9 -9
  85. package/src/primitives/canvas/events.zig +12 -11
  86. package/src/primitives/canvas/frame.zig +44 -9
  87. package/src/primitives/canvas/icons/mic.svg +1 -0
  88. package/src/primitives/canvas/icons.zig +2 -0
  89. package/src/primitives/canvas/root.zig +8 -0
  90. package/src/primitives/canvas/text_span_tests.zig +39 -0
  91. package/src/primitives/canvas/ui.zig +23 -4
  92. package/src/primitives/canvas/ui_markup.zig +15 -0
  93. package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
  94. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
  95. package/src/primitives/canvas/ui_markup_tests.zig +5 -0
  96. package/src/primitives/canvas/ui_markup_view.zig +9 -0
  97. package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
  98. package/src/primitives/canvas/ui_schema.zig +19 -10
  99. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  100. package/src/primitives/canvas/ui_tests.zig +18 -4
  101. package/src/primitives/canvas/widget_invalidation.zig +9 -2
  102. package/src/primitives/canvas/widget_render.zig +296 -114
  103. package/src/primitives/canvas/widget_runtime_tests.zig +133 -0
  104. package/src/primitives/canvas/widget_text_input.zig +10 -10
  105. package/src/primitives/canvas/widget_tree.zig +1 -1
  106. package/src/primitives/canvas/widgets.zig +29 -5
  107. package/src/root.zig +56 -0
  108. package/src/runtime/api.zig +11 -0
  109. package/src/runtime/automation_snapshot.zig +4 -0
  110. package/src/runtime/automation_widget_dispatch.zig +1 -0
  111. package/src/runtime/bridge_payload.zig +2 -0
  112. package/src/runtime/bridge_permission_tests.zig +23 -2
  113. package/src/runtime/bridge_responses.zig +3 -1
  114. package/src/runtime/canvas_frame.zig +31 -13
  115. package/src/runtime/canvas_frame_animation_tests.zig +4 -0
  116. package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
  117. package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
  118. package/src/runtime/canvas_widget_events.zig +69 -24
  119. package/src/runtime/canvas_widget_runtime.zig +101 -6
  120. package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
  121. package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
  122. package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
  123. package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
  124. package/src/runtime/canvas_widget_state.zig +6 -1
  125. package/src/runtime/canvas_widget_text_tests.zig +112 -3
  126. package/src/runtime/clock.zig +13 -1
  127. package/src/runtime/core.zig +133 -1
  128. package/src/runtime/credentials_store.zig +115 -0
  129. package/src/runtime/effects.zig +2568 -75
  130. package/src/runtime/effects_audio_capture_tests.zig +251 -0
  131. package/src/runtime/effects_credentials_tests.zig +332 -0
  132. package/src/runtime/effects_host_tests.zig +208 -1
  133. package/src/runtime/effects_relational_tests.zig +314 -0
  134. package/src/runtime/effects_store_tests.zig +211 -0
  135. package/src/runtime/flow.zig +14 -1
  136. package/src/runtime/gpu_surface_events.zig +6 -1
  137. package/src/runtime/native_command_event_tests.zig +42 -0
  138. package/src/runtime/persist_store.zig +666 -0
  139. package/src/runtime/record_store.zig +788 -0
  140. package/src/runtime/relational_store.zig +854 -0
  141. package/src/runtime/root.zig +52 -0
  142. package/src/runtime/runtime_event_tests.zig +70 -0
  143. package/src/runtime/service_host.zig +711 -0
  144. package/src/runtime/service_pool.zig +1314 -0
  145. package/src/runtime/session_blobs.zig +1 -1
  146. package/src/runtime/session_journal.zig +102 -0
  147. package/src/runtime/session_record.zig +177 -0
  148. package/src/runtime/session_replay.zig +109 -4
  149. package/src/runtime/shell_layout.zig +1 -0
  150. package/src/runtime/shell_layout_tests.zig +120 -0
  151. package/src/runtime/sqlite_engine.zig +474 -0
  152. package/src/runtime/state.zig +6 -0
  153. package/src/runtime/system_services.zig +49 -10
  154. package/src/runtime/tests.zig +5 -0
  155. package/src/runtime/ts_core_host.zig +1189 -118
  156. package/src/runtime/ts_core_host_tests.zig +638 -11
  157. package/src/runtime/ts_ui_app.zig +537 -1
  158. package/src/runtime/ui_app.zig +160 -19
  159. package/src/runtime/ui_app_tests.zig +203 -5
  160. package/src/runtime/validation.zig +22 -0
  161. package/src/runtime/view.zig +11 -0
  162. package/src/runtime/view_widget_scroll.zig +56 -5
  163. package/src/runtime/view_widget_text.zig +24 -5
  164. package/src/runtime/view_widget_tree.zig +1 -1
  165. package/src/runtime/window_storage.zig +1 -0
  166. package/src/runtime/window_view_runtime.zig +2 -3
  167. package/src/runtime/window_views.zig +19 -0
  168. package/src/tooling/android.zig +21 -16
  169. package/src/tooling/db.zig +160 -0
  170. package/src/tooling/ios.zig +7 -1
  171. package/src/tooling/manifest.zig +1248 -2
  172. package/src/tooling/package.zig +953 -6
  173. package/src/tooling/raw_manifest.zig +65 -0
  174. package/src/tooling/root.zig +1 -0
  175. package/src/tooling/templates.zig +216 -4
  176. package/src/tooling/ts_core.zig +283 -17
  177. package/src/tooling/verbs.zig +7 -0
  178. package/third_party/sqlite/README.md +13 -0
  179. package/third_party/sqlite/sqlite3.c +269649 -0
  180. package/third_party/sqlite/sqlite3.h +14349 -0
  181. package/tools/corewire/core_abi.zig +14 -2
  182. package/tools/corewire/emit.zig +98 -29
  183. package/tools/corewire/emit_facade.zig +414 -23
  184. package/tools/corewire/emit_profile.zig +6 -2
  185. package/tools/corewire/emit_service.zig +924 -0
  186. package/tools/corewire/main.zig +122 -0
  187. package/tools/corewire/service_contract.zig +250 -0
  188. package/tools/corewire/sidecar.zig +26 -15
@@ -203,7 +203,12 @@ pub const RuntimeView = struct {
203
203
  gpu_scale_factor: f32 = 1,
204
204
  gpu_frame_index: u64 = 0,
205
205
  gpu_timestamp_ns: u64 = 0,
206
+ /// Profiling-only completion stamp. Kept separate from gpu_timestamp_ns
207
+ /// so `profile on` can start an honest interval window without erasing
208
+ /// the live frame clock used by animation and diagnostics.
209
+ gpu_frame_profile_timestamp_ns: u64 = 0,
206
210
  gpu_frame_interval_ns: u64 = platform.default_gpu_frame_interval_ns,
211
+ gpu_input_event_count: u64 = 0,
207
212
  gpu_pending_input_timestamp_ns: u64 = 0,
208
213
  gpu_input_timestamp_ns: u64 = 0,
209
214
  gpu_input_latency_ns: u64 = 0,
@@ -218,6 +223,7 @@ pub const RuntimeView = struct {
218
223
  gpu_first_frame_latency_budget_ok: bool = true,
219
224
  gpu_first_frame_latency_recorded: bool = false,
220
225
  gpu_frame_nonblank: bool = false,
226
+ gpu_occluded: bool = false,
221
227
  gpu_sample_color: u32 = 0,
222
228
  /// Immutable creation-time backend request. `gpu_backend` below is
223
229
  /// completion state and changes to the concrete presenter reported by
@@ -836,6 +842,7 @@ pub const RuntimeView = struct {
836
842
  pub const pruneCanvasWidgetTextHistory = CanvasWidgetTextMethods.pruneCanvasWidgetTextHistory;
837
843
  pub const clearCanvasWidgetTextVerticalGoal = CanvasWidgetTextMethods.clearCanvasWidgetTextVerticalGoal;
838
844
  pub const canEditCanvasWidgetText = CanvasWidgetTextMethods.canEditCanvasWidgetText;
845
+ pub const ensureCanvasWidgetFocusedTextCaret = CanvasWidgetTextMethods.ensureCanvasWidgetFocusedTextCaret;
839
846
  pub const applyCanvasWidgetTextPointer = CanvasWidgetTextMethods.applyCanvasWidgetTextPointer;
840
847
  pub const clearCanvasWidgetStaticTextSelection = CanvasWidgetTextMethods.clearCanvasWidgetStaticTextSelection;
841
848
  pub const canvasWidgetCopyText = CanvasWidgetTextMethods.canvasWidgetCopyText;
@@ -856,6 +863,7 @@ pub const RuntimeView = struct {
856
863
  pub const applyCanvasWidgetTextareaScroll = CanvasWidgetScrollMethods.applyCanvasWidgetTextareaScroll;
857
864
  pub const applyCanvasWidgetScrollDriverOffset = CanvasWidgetScrollMethods.applyCanvasWidgetScrollDriverOffset;
858
865
  pub const applyCanvasWidgetScrollKeyboardTarget = CanvasWidgetScrollMethods.applyCanvasWidgetScrollKeyboardTarget;
866
+ pub const scrollCanvasWidgetIntoView = CanvasWidgetScrollMethods.scrollCanvasWidgetIntoView;
859
867
  pub const stepCanvasWidgetKineticScroll = CanvasWidgetScrollMethods.stepCanvasWidgetKineticScroll;
860
868
  pub const canvasWidgetScrollContentExtent = CanvasWidgetScrollMethods.canvasWidgetScrollContentExtent;
861
869
  pub const canvasWidgetScrollContentExtentX = CanvasWidgetScrollMethods.canvasWidgetScrollContentExtentX;
@@ -1087,6 +1095,7 @@ pub const RuntimeView = struct {
1087
1095
  .gpu_frame_index = self.gpu_frame_index,
1088
1096
  .gpu_timestamp_ns = self.gpu_timestamp_ns,
1089
1097
  .gpu_frame_interval_ns = self.gpu_frame_interval_ns,
1098
+ .gpu_input_event_count = self.gpu_input_event_count,
1090
1099
  .gpu_input_timestamp_ns = self.gpu_input_timestamp_ns,
1091
1100
  .gpu_input_latency_ns = self.gpu_input_latency_ns,
1092
1101
  .gpu_input_latency_budget_ns = self.gpu_input_latency_budget_ns,
@@ -1097,6 +1106,7 @@ pub const RuntimeView = struct {
1097
1106
  .gpu_first_frame_latency_budget_exceeded_count = self.gpu_first_frame_latency_budget_exceeded_count,
1098
1107
  .gpu_first_frame_latency_budget_ok = self.gpu_first_frame_latency_budget_ok,
1099
1108
  .gpu_frame_nonblank = self.gpu_frame_nonblank,
1109
+ .gpu_occluded = self.gpu_occluded,
1100
1110
  .gpu_sample_color = self.gpu_sample_color,
1101
1111
  .gpu_backend = self.gpu_backend,
1102
1112
  .gpu_pixel_format = self.gpu_pixel_format,
@@ -1190,6 +1200,7 @@ pub const RuntimeView = struct {
1190
1200
  }
1191
1201
 
1192
1202
  pub fn recordGpuSurfaceInputTimestamp(self: *RuntimeView, timestamp_ns: u64) void {
1203
+ self.gpu_input_event_count +|= 1;
1193
1204
  if (timestamp_ns == 0) return;
1194
1205
  self.gpu_pending_input_timestamp_ns = timestamp_ns;
1195
1206
  self.gpu_input_timestamp_ns = timestamp_ns;
@@ -35,7 +35,7 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
35
35
  for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |node, index| {
36
36
  if (node.widget.kind != .scroll_view or canvasWidgetModelDrivenVirtual(node.widget)) continue;
37
37
  // Native drivers own momentum + rubber-band recovery.
38
- if (node.widget.native_scroll) continue;
38
+ if (node.widget.runtime_flags.native_scroll) continue;
39
39
  const viewport = node.frame.inset(node.widget.layout.padding).normalized();
40
40
  if (viewport.isEmpty()) continue;
41
41
  const physics = canvas.widgetScrollPhysics(node.widget, self.widget_tokens.scroll);
@@ -215,7 +215,7 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
215
215
  // an engine overscroll here would have no kinetic step to
216
216
  // pull it back.
217
217
  const physics = canvas.widgetScrollPhysics(scroll_node.widget, self.widget_tokens.scroll);
218
- const rubberband = allow_rubberband and !scroll_node.widget.native_scroll;
218
+ const rubberband = allow_rubberband and !scroll_node.widget.runtime_flags.native_scroll;
219
219
  const next = switch (source) {
220
220
  .wheel => if (rubberband)
221
221
  current.applyWheel(delta, physics)
@@ -380,6 +380,57 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
380
380
  return self.canvasWidgetDirtyBounds(scroll_index, scroll_node.frame);
381
381
  }
382
382
 
383
+ /// Minimally scroll every runtime-owned ancestor viewport needed
384
+ /// to make `id` fully visible. Roving tree/list navigation resolves
385
+ /// the logical successor before geometry focusability, then calls
386
+ /// this seam before committing focus so an offscreen row becomes a
387
+ /// normal routable focus target in the same key event.
388
+ pub fn scrollCanvasWidgetIntoView(self: *RuntimeView, id: canvas.ObjectId) anyerror!?geometry.RectF {
389
+ const target_index = self.canvasWidgetNodeIndexById(id) orelse return null;
390
+ var dirty: ?geometry.RectF = null;
391
+ var current = self.widget_layout_nodes[target_index].parent_index;
392
+ while (current) |ancestor_index| {
393
+ if (ancestor_index >= self.widget_layout_node_count) break;
394
+ const ancestor = self.widget_layout_nodes[ancestor_index];
395
+
396
+ // Anchored surfaces escape ancestor clips rather than
397
+ // scrolling with their source branch.
398
+ if (canvas.widgetIsAnchored(ancestor.widget)) break;
399
+
400
+ if (canvasWidgetScrollableKind(ancestor.widget.kind) and ancestor.widget.kind != .textarea) {
401
+ const viewport = ancestor.frame.inset(ancestor.widget.layout.padding).normalized();
402
+ if (!viewport.isEmpty()) {
403
+ if (canvas.widgetScrollsAxis(ancestor.widget, .vertical)) {
404
+ const target = self.widget_layout_nodes[target_index].frame.normalized();
405
+ const delta_y: f32 = if (target.y < viewport.y)
406
+ target.y - viewport.y
407
+ else if (target.maxY() > viewport.maxY())
408
+ target.maxY() - viewport.maxY()
409
+ else
410
+ 0;
411
+ if (delta_y != 0) {
412
+ dirty = unionOptionalRects(dirty, try self.applyCanvasWidgetScrollAxis(ancestor_index, .vertical, delta_y, .discrete, false));
413
+ }
414
+ }
415
+ if (canvas.widgetScrollsAxis(ancestor.widget, .horizontal)) {
416
+ const target = self.widget_layout_nodes[target_index].frame.normalized();
417
+ const delta_x: f32 = if (target.x < viewport.x)
418
+ target.x - viewport.x
419
+ else if (target.maxX() > viewport.maxX())
420
+ target.maxX() - viewport.maxX()
421
+ else
422
+ 0;
423
+ if (delta_x != 0) {
424
+ dirty = unionOptionalRects(dirty, try self.applyCanvasWidgetScrollAxis(ancestor_index, .horizontal, delta_x, .discrete, false));
425
+ }
426
+ }
427
+ }
428
+ }
429
+ current = self.widget_layout_nodes[ancestor_index].parent_index;
430
+ }
431
+ return dirty;
432
+ }
433
+
383
434
  pub fn stepCanvasWidgetKineticScroll(self: *RuntimeView, dt_ms: f32) anyerror!?geometry.RectF {
384
435
  var dirty: ?geometry.RectF = null;
385
436
  var changed = false;
@@ -387,7 +438,7 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
387
438
  for (self.widget_layout_nodes[0..self.widget_layout_node_count], 0..) |scroll_node, scroll_index| {
388
439
  if (scroll_node.widget.kind != .scroll_view or canvasWidgetModelDrivenVirtual(scroll_node.widget)) continue;
389
440
  // Native drivers own momentum + rubber-band recovery.
390
- if (scroll_node.widget.native_scroll) continue;
441
+ if (scroll_node.widget.runtime_flags.native_scroll) continue;
391
442
 
392
443
  const viewport = scroll_node.frame.inset(scroll_node.widget.layout.padding).normalized();
393
444
  if (viewport.isEmpty()) {
@@ -473,7 +524,7 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
473
524
  if (scroll_index < self.widget_layout_node_count) {
474
525
  const widget = self.widget_layout_nodes[scroll_index].widget;
475
526
  if (widget.kind == .textarea) {
476
- return if (widget.code_editor)
527
+ return if (widget.runtime_flags.code_editor)
477
528
  @max(viewport.width, canvas.textInputContentWidthForWidget(widget, self.widget_tokens))
478
529
  else
479
530
  viewport.width;
@@ -524,7 +575,7 @@ pub fn RuntimeViewCanvasWidgetScroll(comptime RuntimeView: type) type {
524
575
  }
525
576
  if (widget.kind != .textarea) return;
526
577
 
527
- if (widget.code_editor and widget.text_no_wrap) {
578
+ if (widget.runtime_flags.code_editor and widget.text_no_wrap) {
528
579
  const next_x = canvas.textInputCaretVisibleScrollOffsetForWidget(widget, self.widget_tokens, widget.value_x);
529
580
  if (next_x != widget.value_x) {
530
581
  widget.value_x = next_x;
@@ -179,14 +179,16 @@ pub fn RuntimeViewCanvasWidgetText(comptime RuntimeView: type) type {
179
179
  return null;
180
180
  }
181
181
 
182
- // Multi-line editing contract: Enter (plain or shift) inserts
183
- // a newline; submit rides the primary-modifier chord instead.
184
- // Shared with the app dispatch path so the model's `on_input`
185
- // hears exactly the edit the retained text applied.
182
+ // Multi-line editing contract: Enter normally inserts a
183
+ // newline, while a submit-on-enter textarea leaves plain
184
+ // Enter for its submit handler and keeps Shift+Enter as the
185
+ // newline gesture. Shared with the app dispatch path so the
186
+ // model's `on_input` hears exactly the edit retained text
187
+ // applied.
186
188
  if (canvas.widgetCodeTabTextEditEvent(widget, keyboard)) |tab_edit| {
187
189
  return tab_edit;
188
190
  }
189
- if (canvas.widgetKeyboardNewlineTextEditEvent(widget.kind, keyboard)) |newline_edit| {
191
+ if (canvas.widgetKeyboardNewlineTextEditEvent(widget, keyboard)) |newline_edit| {
190
192
  return newline_edit;
191
193
  }
192
194
 
@@ -959,6 +961,23 @@ pub fn RuntimeViewCanvasWidgetText(comptime RuntimeView: type) type {
959
961
  return canvasWidgetEditableTextKind(widget.kind) and !widget.state.disabled;
960
962
  }
961
963
 
964
+ /// A controlled source replacement intentionally discards stale
965
+ /// selection state, but logical focus survives that rebuild. Give
966
+ /// the focused editor a fresh insertion point so an app clearing a
967
+ /// submitted composer never leaves a focused-but-caretless field.
968
+ /// Explicit source selections are left untouched.
969
+ pub fn ensureCanvasWidgetFocusedTextCaret(self: *RuntimeView) anyerror!bool {
970
+ const focused_id = self.canvas_widget_focused_id;
971
+ if (focused_id == 0 or !self.canEditCanvasWidgetText(focused_id)) return false;
972
+ const index = self.canvasWidgetNodeIndexById(focused_id) orelse return false;
973
+ const widget = &self.widget_layout_nodes[index].widget;
974
+ if (widget.text_selection != null) return false;
975
+ widget.text_selection = canvas.TextSelection.collapsed(widget.text.len);
976
+ try self.refreshCanvasWidgetSemantics();
977
+ self.widget_revision += 1;
978
+ return true;
979
+ }
980
+
962
981
  pub fn applyCanvasWidgetTextPointer(
963
982
  self: *RuntimeView,
964
983
  target_id: canvas.ObjectId,
@@ -911,7 +911,7 @@ pub fn RuntimeViewCanvasWidgetTree(comptime RuntimeView: type) type {
911
911
  /// Keyboard entry point into an anchored menu surface: the marked
912
912
  /// (`selected`) row when the menu has one, otherwise the first
913
913
  /// focusable row for an ArrowDown entry or the last for ArrowUp —
914
- /// the open-select keymap.
914
+ /// the open-menu keymap shared by picker and menu-button triggers.
915
915
  pub fn canvasWidgetMenuSurfaceEntryId(self: *const RuntimeView, surface_index: usize, from_end: bool) ?canvas.ObjectId {
916
916
  var first: ?canvas.ObjectId = null;
917
917
  var last: ?canvas.ObjectId = null;
@@ -178,6 +178,7 @@ pub fn RuntimeWindowStorage(comptime Runtime: type) type {
178
178
  self.windows[index].info.frame = native_info.frame;
179
179
  self.windows[index].info.scale_factor = native_info.scale_factor;
180
180
  self.windows[index].info.open = native_info.open;
181
+ self.windows[index].info.hidden = native_info.hidden;
181
182
  if (!self.windows[index].main_frame_set) {
182
183
  self.windows[index].main_frame = geometry.RectF.init(0, 0, native_info.frame.width, native_info.frame.height);
183
184
  }
@@ -26,8 +26,7 @@ const viewInfoFromWebView = bridge_responses.viewInfoFromWebView;
26
26
  const RuntimeWebView = runtime_state.RuntimeWebView;
27
27
  const FocusTraversalDirection = runtime_state.FocusTraversalDirection;
28
28
  const sourceWebViewUrl = runtime_state.sourceWebViewUrl;
29
- const nowNanoseconds = runtime_clock.nowNanoseconds;
30
- const timestampToU64 = runtime_clock.timestampToU64;
29
+ const monotonicNanoseconds = runtime_clock.monotonicNanoseconds;
31
30
  const CommandSource = runtime_api.CommandSource;
32
31
 
33
32
  fn copyInto(buffer: []u8, value: []const u8) ![]const u8 {
@@ -492,7 +491,7 @@ pub fn RuntimeWindowViewRuntime(comptime Runtime: type) type {
492
491
  .gpu_color_space = if (options.kind == .gpu_surface) options.gpu_surface.color_space else .none,
493
492
  .gpu_vsync = options.kind == .gpu_surface and options.gpu_surface.vsync,
494
493
  .gpu_status = if (options.kind == .gpu_surface) .ready else .unavailable,
495
- .gpu_surface_created_timestamp_ns = if (options.kind == .gpu_surface) timestampToU64(nowNanoseconds()) else 0,
494
+ .gpu_surface_created_timestamp_ns = if (options.kind == .gpu_surface) monotonicNanoseconds() else 0,
496
495
  .focused = false,
497
496
  .keyboard_active = windowKeyboardActive(self, options.window_id),
498
497
  .open = true,
@@ -146,6 +146,24 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
146
146
  try self.options.platform.services.minimizeWindow(window_id);
147
147
  }
148
148
 
149
+ /// Keep a live window and its views, but order it offscreen until
150
+ /// `showWindow` brings it back. This is an app-driven hide, not a
151
+ /// close, so identity and rendered state are retained.
152
+ pub fn hideWindow(self: *Runtime, window_id: platform.WindowId) anyerror!void {
153
+ const index = Self.findWindowIndexById(self, window_id) orelse return error.WindowNotFound;
154
+ if (!self.windows[index].info.open) return error.WindowNotFound;
155
+ const was_hidden = self.windows[index].info.hidden;
156
+ const was_focused = self.windows[index].info.focused;
157
+ self.windows[index].info.hidden = true;
158
+ self.windows[index].info.focused = false;
159
+ self.options.platform.services.hideWindow(window_id) catch |err| {
160
+ self.windows[index].info.hidden = was_hidden;
161
+ self.windows[index].info.focused = was_focused;
162
+ return err;
163
+ };
164
+ self.invalidated = true;
165
+ }
166
+
149
167
  /// The real OS show verb: unhide and order front — the counterpart
150
168
  /// to a `close_policy = .hide` hide, and what a tray "Open"
151
169
  /// action resolves to. Like `closeWindow`, the runtime flag
@@ -232,6 +250,7 @@ pub fn RuntimeWindowViews(comptime Runtime: type) type {
232
250
  .always_on_top = shell_window.always_on_top,
233
251
  .click_through = shell_window.click_through,
234
252
  .activate_on_show = shell_window.activate_on_show,
253
+ .allows_fullscreen = shell_window.allows_fullscreen,
235
254
  .min_width = shell_window.min_width,
236
255
  .min_height = shell_window.min_height,
237
256
  .close_policy = shell_layout.shellClosePolicy(shell_window.close_policy),
@@ -526,18 +526,18 @@ pub fn assembleApk(allocator: std.mem.Allocator, io: std.Io, options: ApkOptions
526
526
  const javac = try javaSiblingAlloc(allocator, options.java, "javac");
527
527
  defer allocator.free(javac);
528
528
  try runInherit(io, &.{
529
- javac, "--release", "17", "-encoding",
530
- "UTF-8", "-cp", options.toolchain.android_jar, "-d",
531
- classes_dir, activity_path,
529
+ javac, "--release", "17", "-encoding",
530
+ "UTF-8", "-cp", options.toolchain.android_jar, "-d",
531
+ classes_dir, activity_path,
532
532
  }, error.ApkAssemblyFailed);
533
533
 
534
534
  // Classes -> classes.dex at the APK root.
535
535
  var dex_argv: std.ArrayList([]const u8) = .empty;
536
536
  defer dex_argv.deinit(allocator);
537
537
  try dex_argv.appendSlice(allocator, &.{
538
- options.java, "-cp", options.toolchain.d8_jar, "com.android.tools.r8.D8",
539
- "--release", "--lib", options.toolchain.android_jar,
540
- "--min-api", min_sdk_version, "--output", root_dir,
538
+ options.java, "-cp", options.toolchain.d8_jar, "com.android.tools.r8.D8",
539
+ "--release", "--lib", options.toolchain.android_jar, "--min-api",
540
+ min_sdk_version, "--output", root_dir,
541
541
  });
542
542
  var class_files = try collectFilesAlloc(allocator, io, classes_dir, ".class");
543
543
  defer freePathList(allocator, &class_files);
@@ -603,11 +603,9 @@ pub fn assembleApk(allocator: std.mem.Allocator, io: std.Io, options: ApkOptions
603
603
 
604
604
  try ensureDebugKeystore(allocator, io, options.java, options.keystore_path);
605
605
  try runInherit(io, &.{
606
- options.java, "-jar", options.toolchain.apksigner_jar, "sign",
607
- "--ks", options.keystore_path,
608
- "--ks-pass", "pass:android",
609
- "--ks-key-alias", "native-sdk-debug",
610
- "--out", options.out_apk,
606
+ options.java, "-jar", options.toolchain.apksigner_jar, "sign",
607
+ "--ks", options.keystore_path, "--ks-pass", "pass:android",
608
+ "--ks-key-alias", "native-sdk-debug", "--out", options.out_apk,
611
609
  aligned,
612
610
  }, error.ApkAssemblyFailed);
613
611
  }
@@ -628,11 +626,11 @@ fn ensureDebugKeystore(allocator: std.mem.Allocator, io: std.Io, java: []const u
628
626
  defer allocator.free(keytool);
629
627
  std.debug.print("native (android): generating the debug signing keystore at {s}\n", .{keystore_path});
630
628
  try runInherit(io, &.{
631
- keytool, "-genkeypair", "-keystore", keystore_path,
632
- "-storepass", "android", "-keypass", "android",
633
- "-alias", "native-sdk-debug",
634
- "-keyalg", "RSA", "-keysize", "2048",
635
- "-validity", "10950", "-dname", "CN=Native SDK Debug",
629
+ keytool, "-genkeypair", "-keystore", keystore_path,
630
+ "-storepass", "android", "-keypass", "android",
631
+ "-alias", "native-sdk-debug", "-keyalg", "RSA",
632
+ "-keysize", "2048", "-validity", "10950",
633
+ "-dname", "CN=Native SDK Debug",
636
634
  }, error.ApkAssemblyFailed);
637
635
  }
638
636
 
@@ -1154,6 +1152,13 @@ test "the embedded host sources are the toolkit host" {
1154
1152
  try std.testing.expect(std.mem.indexOf(u8, host_bridge_source, "nativeAudioEvent") != null);
1155
1153
  try std.testing.expect(std.mem.indexOf(u8, host_header, "native_sdk_audio_service_t") != null);
1156
1154
  try std.testing.expect(std.mem.indexOf(u8, host_header, "native_sdk_app_audio_event") != null);
1155
+ // Tier-4 credentials: non-exportable AndroidKeyStore AES-GCM key,
1156
+ // ciphertext-only private preferences, and the shared embed ABI.
1157
+ try std.testing.expect(std.mem.indexOf(u8, host_activity_source, "nativeSetCredentialService") != null);
1158
+ try std.testing.expect(std.mem.indexOf(u8, host_activity_source, "AndroidKeyStore") != null);
1159
+ try std.testing.expect(std.mem.indexOf(u8, host_activity_source, "AES/GCM/NoPadding") != null);
1160
+ try std.testing.expect(std.mem.indexOf(u8, host_bridge_source, "native_sdk_app_set_credential_service") != null);
1161
+ try std.testing.expect(std.mem.indexOf(u8, host_header, "native_sdk_credential_service_t") != null);
1157
1162
  }
1158
1163
 
1159
1164
  test "adb device parsing prefers ready devices and honors requests" {
@@ -0,0 +1,160 @@
1
+ //! `native db`: append-only migration authoring and development database
2
+ //! inspection/reset. Paths are always resolved from app identity through
3
+ //! app_dirs; the CLI never accepts an arbitrary database path.
4
+
5
+ const std = @import("std");
6
+ const app_dirs = @import("app_dirs");
7
+ const debug = @import("debug");
8
+ const manifest_tool = @import("manifest.zig");
9
+ const sqlite = @import("sqlite_engine");
10
+
11
+ pub const Error = error{ InvalidArguments, InvalidMigrationName, MigrationLimitReached, ResetNeedsConfirmation };
12
+
13
+ pub fn run(allocator: std.mem.Allocator, io: std.Io, env: *std.process.Environ.Map, args: []const []const u8) !void {
14
+ if (args.len == 0 or std.mem.eql(u8, args[0], "--help") or std.mem.eql(u8, args[0], "-h")) {
15
+ usage();
16
+ return;
17
+ }
18
+ const verb = args[0];
19
+ if (std.mem.eql(u8, verb, "new-migration")) {
20
+ if (args.len != 2) return Error.InvalidArguments;
21
+ try newMigration(allocator, io, args[1]);
22
+ } else if (std.mem.eql(u8, verb, "status")) {
23
+ if (args.len != 1) return Error.InvalidArguments;
24
+ try status(allocator, io, env);
25
+ } else if (std.mem.eql(u8, verb, "reset")) {
26
+ if (args.len != 2 or !std.mem.eql(u8, args[1], "--yes")) return Error.ResetNeedsConfirmation;
27
+ try reset(allocator, io, env);
28
+ } else return Error.InvalidArguments;
29
+ }
30
+
31
+ fn usage() void {
32
+ std.debug.print(
33
+ \\usage: native db <command>
34
+ \\
35
+ \\commands:
36
+ \\ new-migration <name> append src/schema/NNNN_name.sql
37
+ \\ status show source and installed schema versions
38
+ \\ reset --yes delete this app's engine-owned development app.db
39
+ \\
40
+ , .{});
41
+ }
42
+
43
+ fn newMigration(allocator: std.mem.Allocator, io: std.Io, authored_name: []const u8) !void {
44
+ if (authored_name.len == 0 or authored_name.len > 64) return Error.InvalidMigrationName;
45
+ const safe = try allocator.alloc(u8, authored_name.len);
46
+ defer allocator.free(safe);
47
+ var previous_separator = false;
48
+ for (authored_name, 0..) |char, index| {
49
+ const lowered = std.ascii.toLower(char);
50
+ if ((lowered >= 'a' and lowered <= 'z') or (lowered >= '0' and lowered <= '9')) {
51
+ safe[index] = lowered;
52
+ previous_separator = false;
53
+ } else if ((char == '-' or char == '_' or char == ' ') and index > 0 and !previous_separator) {
54
+ safe[index] = '_';
55
+ previous_separator = true;
56
+ } else return Error.InvalidMigrationName;
57
+ }
58
+ if (safe[0] == '_' or safe[safe.len - 1] == '_') return Error.InvalidMigrationName;
59
+ try std.Io.Dir.cwd().createDirPath(io, "src/schema");
60
+ var dir = try std.Io.Dir.cwd().openDir(io, "src/schema", .{ .iterate = true });
61
+ defer dir.close(io);
62
+ var highest: u32 = 0;
63
+ var iterator = dir.iterate();
64
+ while (try iterator.next(io)) |entry| {
65
+ if (entry.kind != .file or entry.name.len < 9 or !std.mem.endsWith(u8, entry.name, ".sql")) continue;
66
+ const version = std.fmt.parseUnsigned(u32, entry.name[0..4], 10) catch continue;
67
+ if (entry.name[4] != '_') continue;
68
+ highest = @max(highest, version);
69
+ }
70
+ if (highest >= 9999) return Error.MigrationLimitReached;
71
+ const version = highest + 1;
72
+ const file_name = try std.fmt.allocPrint(allocator, "src/schema/{d:0>4}_{s}.sql", .{ version, safe });
73
+ defer allocator.free(file_name);
74
+ var file = try std.Io.Dir.cwd().createFile(io, file_name, .{ .exclusive = true });
75
+ defer file.close(io);
76
+ try file.writeStreamingAll(
77
+ io,
78
+ "-- Append-only SQLite migration. Use STRICT tables so generated types stay honest.\n" ++
79
+ "-- This version may never be edited after it is shipped.\n\n",
80
+ );
81
+ std.debug.print("created {s}\n", .{file_name});
82
+ }
83
+
84
+ fn status(allocator: std.mem.Allocator, io: std.Io, env: *std.process.Environ.Map) !void {
85
+ const target = try migrationSourceVersion(io);
86
+ var path_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
87
+ const db_path = try appDbPath(allocator, io, env, &path_buffer);
88
+ const installed = readUserVersion(allocator, io, db_path) catch |err| switch (err) {
89
+ error.FileNotFound => null,
90
+ else => return err,
91
+ };
92
+ if (installed) |version| {
93
+ const relation = if (version == target) "current" else if (version < target) "pending migrations" else "newer than this source (runtime will refuse it)";
94
+ std.debug.print("source schema: {d}\ninstalled schema: {d} ({s})\ndatabase: {s}\n", .{ target, version, relation, db_path });
95
+ } else {
96
+ std.debug.print("source schema: {d}\ninstalled schema: none (created on first launch)\ndatabase: {s}\n", .{ target, db_path });
97
+ }
98
+ }
99
+
100
+ fn reset(allocator: std.mem.Allocator, io: std.Io, env: *std.process.Environ.Map) !void {
101
+ var path_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
102
+ const db_path = try appDbPath(allocator, io, env, &path_buffer);
103
+ for ([_][]const u8{ "", "-wal", "-shm" }) |suffix| {
104
+ const path = try std.fmt.allocPrint(allocator, "{s}{s}", .{ db_path, suffix });
105
+ defer allocator.free(path);
106
+ std.Io.Dir.cwd().deleteFile(io, path) catch |err| switch (err) {
107
+ error.FileNotFound => {},
108
+ else => return err,
109
+ };
110
+ }
111
+ std.debug.print("reset relational database {s} (the next development launch reapplies every migration)\n", .{db_path});
112
+ }
113
+
114
+ fn migrationSourceVersion(io: std.Io) !u32 {
115
+ var dir = std.Io.Dir.cwd().openDir(io, "src/schema", .{ .iterate = true }) catch |err| switch (err) {
116
+ error.FileNotFound => return 0,
117
+ else => return err,
118
+ };
119
+ defer dir.close(io);
120
+ var count: u32 = 0;
121
+ var iterator = dir.iterate();
122
+ while (try iterator.next(io)) |entry| {
123
+ if (entry.kind == .file and entry.name.len >= 9 and entry.name[4] == '_' and std.mem.endsWith(u8, entry.name, ".sql")) count += 1;
124
+ }
125
+ return count;
126
+ }
127
+
128
+ fn appDbPath(allocator: std.mem.Allocator, io: std.Io, env: *std.process.Environ.Map, buffer: []u8) ![]const u8 {
129
+ const metadata = try manifest_tool.readMetadata(allocator, io, "app.zon");
130
+ var dir_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
131
+ const data_dir = try app_dirs.resolveOne(
132
+ .{ .name = metadata.id },
133
+ app_dirs.currentPlatform(),
134
+ debug.envFromMap(env),
135
+ .data,
136
+ &dir_buffer,
137
+ );
138
+ return std.fmt.bufPrint(buffer, "{s}/app.db", .{data_dir});
139
+ }
140
+
141
+ /// Read through SQLite rather than the file header: WAL may carry a newer
142
+ /// user_version than byte 60 in the main database until checkpoint.
143
+ fn readUserVersion(allocator: std.mem.Allocator, io: std.Io, path: []const u8) !u32 {
144
+ var file = try std.Io.Dir.cwd().openFile(io, path, .{});
145
+ file.close(io);
146
+ const path_z = try allocator.dupeZ(u8, path);
147
+ defer allocator.free(path_z);
148
+ var connection = try sqlite.Connection.open(path_z);
149
+ defer connection.close();
150
+ var statement = try connection.prepareOne("PRAGMA user_version;");
151
+ defer statement.finalize();
152
+ if ((try statement.step()) != .row) return error.InvalidDatabaseHeader;
153
+ const version = statement.columnInt(0);
154
+ if (version < 0 or version > 9999) return error.InvalidDatabaseHeader;
155
+ return @intCast(version);
156
+ }
157
+
158
+ test "migration author names are bounded and normalized" {
159
+ try std.testing.expectError(Error.InvalidMigrationName, newMigration(std.testing.allocator, std.testing.io, "../escape"));
160
+ }
@@ -312,7 +312,8 @@ pub fn runDev(allocator: std.mem.Allocator, io: std.Io, options: DevOptions) !vo
312
312
  "QuartzCore", "-framework", "Foundation",
313
313
  "-framework", "CoreGraphics", "-framework",
314
314
  "AVFoundation", "-framework", "ImageIO",
315
- "-o", executable_path,
315
+ "-framework", "Security", "-o",
316
+ executable_path,
316
317
  }, error.HostCompileFailed);
317
318
  try runInherit(io, &.{ "codesign", "--force", "--sign", "-", bundle_path }, error.HostCompileFailed);
318
319
 
@@ -497,6 +498,11 @@ test "the embedded host sources are the toolkit host" {
497
498
  try std.testing.expect(std.mem.indexOf(u8, host_source, "handleSessionInterruption") != null);
498
499
  try std.testing.expect(std.mem.indexOf(u8, host_header, "native_sdk_audio_service_t") != null);
499
500
  try std.testing.expect(std.mem.indexOf(u8, host_header, "native_sdk_app_audio_event") != null);
501
+ // Tier-4 credentials: generic-password Keychain entries registered
502
+ // through the shared mobile credential service ABI.
503
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "native_sdk_app_set_credential_service") != null);
504
+ try std.testing.expect(std.mem.indexOf(u8, host_source, "SecItemCopyMatching") != null);
505
+ try std.testing.expect(std.mem.indexOf(u8, host_header, "native_sdk_credential_service_t") != null);
500
506
  // Platform push/pop navigation: the depth projection poll, the REAL
501
507
  // interactive pop recognizer, and the completed gesture's exactly-once
502
508
  // back-command dispatch.