@native-sdk/cli 0.10.1 → 0.11.1

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 (555) hide show
  1. package/README.md +8 -6
  2. package/bin/native.js +2 -1
  3. package/build/app.zig +393 -97
  4. package/build/corewire.zig +53 -0
  5. package/build/test_shards.zig +49 -0
  6. package/build/ts_run.mjs +3 -3
  7. package/build.zig +2030 -83
  8. package/native-sdk.d.ts +5 -1
  9. package/package.json +20 -14
  10. package/packages/core/compile-surface/core.ts +164 -72
  11. package/packages/core/package-lock.json +75 -357
  12. package/packages/core/package.json +25 -4
  13. package/packages/core/scripts/compiler_command.mjs +17 -12
  14. package/packages/core/scripts/compiler_typecheck.mjs +1 -0
  15. package/packages/core/scripts/gen_declarations.mjs +3 -2
  16. package/packages/core/scripts/gen_service_surface.mjs +22 -10
  17. package/packages/core/scripts/install_scriptc.mjs +182 -0
  18. package/packages/core/scripts/invoke_scriptc.mjs +18 -0
  19. package/packages/core/scripts/merge_static_archives.mjs +6 -1
  20. package/packages/core/scripts/npm_static_spike.mjs +2 -2
  21. package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
  22. package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
  23. package/packages/core/scripts/run_library_compiler.mjs +51 -0
  24. package/packages/core/scripts/run_native_tests.mjs +22 -0
  25. package/packages/core/scripts/scriptc-toolchain.json +101 -0
  26. package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
  27. package/packages/core/scripts/stage_external_core.mjs +68 -1
  28. package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
  29. package/packages/core/sdk/bytes.d.ts +2 -0
  30. package/packages/core/sdk/bytes.ts +86 -0
  31. package/packages/core/sdk/core.d.ts +332 -5
  32. package/packages/core/sdk/core.ts +371 -85
  33. package/packages/core/sdk/events.d.ts +252 -0
  34. package/packages/core/sdk/events.ts +240 -2
  35. package/packages/core/sdk/internal/image_identity.d.ts +7 -0
  36. package/packages/core/sdk/internal/image_identity.ts +71 -0
  37. package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
  38. package/packages/core/sdk/internal/markdown_policy.ts +878 -0
  39. package/packages/core/sdk/text.d.ts +27 -0
  40. package/packages/core/sdk/text.ts +206 -15
  41. package/packages/core/sdk/theme.d.ts +251 -0
  42. package/packages/core/sdk/theme.ts +267 -0
  43. package/packages/core/src/authorization.ts +137 -0
  44. package/packages/core/src/automation_commands.ts +201 -0
  45. package/packages/core/src/automation_interactions.ts +92 -0
  46. package/packages/core/src/bridge_descriptors.ts +104 -0
  47. package/packages/core/src/builtin_coordination.ts +172 -0
  48. package/packages/core/src/canvas_frame_coordination.ts +81 -0
  49. package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
  50. package/packages/core/src/canvas_scene_observation.ts +145 -0
  51. package/packages/core/src/chart_content.ts +161 -0
  52. package/packages/core/src/chart_plans.ts +432 -0
  53. package/packages/core/src/checker.ts +186 -19
  54. package/packages/core/src/cli.ts +2 -11
  55. package/packages/core/src/code_content.ts +580 -0
  56. package/packages/core/src/command_coordination.ts +140 -0
  57. package/packages/core/src/component_composition.ts +94 -0
  58. package/packages/core/src/component_construction.ts +149 -0
  59. package/packages/core/src/context_menus.ts +76 -0
  60. package/packages/core/src/contract.ts +25 -7
  61. package/packages/core/src/control_appearance.ts +232 -0
  62. package/packages/core/src/control_commands.ts +115 -0
  63. package/packages/core/src/control_content.ts +105 -0
  64. package/packages/core/src/control_geometry.ts +107 -0
  65. package/packages/core/src/control_payloads.ts +119 -0
  66. package/packages/core/src/control_primitives.ts +134 -0
  67. package/packages/core/src/devhost.ts +82 -7
  68. package/packages/core/src/devhost_journal.mjs +30 -7
  69. package/packages/core/src/diagnostics.ts +7 -0
  70. package/packages/core/src/effect_plans.ts +71 -0
  71. package/packages/core/src/extent_program.ts +53 -0
  72. package/packages/core/src/flow_measurement.ts +121 -0
  73. package/packages/core/src/font_registry.ts +37 -0
  74. package/packages/core/src/frontend.ts +12 -10
  75. package/packages/core/src/glyph_atlas.ts +86 -0
  76. package/packages/core/src/gpu_packet_preparation.ts +130 -0
  77. package/packages/core/src/gpu_planning.ts +123 -0
  78. package/packages/core/src/gpu_presentation.ts +55 -0
  79. package/packages/core/src/host_flow.ts +89 -0
  80. package/packages/core/src/host_input_regions.ts +165 -0
  81. package/packages/core/src/image_registry.ts +66 -0
  82. package/packages/core/src/indicator_plans.ts +132 -0
  83. package/packages/core/src/infer.ts +150 -8
  84. package/packages/core/src/input_composition.ts +116 -0
  85. package/packages/core/src/intrinsic_measure.ts +100 -0
  86. package/packages/core/src/layout_coordination.ts +207 -0
  87. package/packages/core/src/leaf_plans.ts +134 -0
  88. package/packages/core/src/markup_canonical.ts +140 -0
  89. package/packages/core/src/markup_construction.ts +189 -0
  90. package/packages/core/src/markup_development.ts +160 -0
  91. package/packages/core/src/markup_display.ts +43 -0
  92. package/packages/core/src/markup_document.ts +226 -0
  93. package/packages/core/src/markup_elements.ts +225 -0
  94. package/packages/core/src/markup_expressions.ts +79 -0
  95. package/packages/core/src/markup_imports.ts +146 -0
  96. package/packages/core/src/markup_parser.ts +228 -0
  97. package/packages/core/src/markup_runtime.ts +93 -0
  98. package/packages/core/src/markup_scalars.ts +143 -0
  99. package/packages/core/src/markup_shapes.ts +243 -0
  100. package/packages/core/src/markup_specialized.ts +242 -0
  101. package/packages/core/src/markup_text.ts +86 -0
  102. package/packages/core/src/markup_values.ts +336 -0
  103. package/packages/core/src/measurement_coordination.ts +185 -0
  104. package/packages/core/src/modules.ts +1 -1
  105. package/packages/core/src/motion_sampling.ts +100 -0
  106. package/packages/core/src/paragraph_layout.ts +192 -0
  107. package/packages/core/src/portable_sources.json +98 -0
  108. package/packages/core/src/portable_sources.ts +17 -0
  109. package/packages/core/src/registered_font.ts +92 -0
  110. package/packages/core/src/render_animation_lifecycle.ts +128 -0
  111. package/packages/core/src/render_coordination.ts +170 -0
  112. package/packages/core/src/render_resources.ts +234 -0
  113. package/packages/core/src/runtime_policy.ts +3954 -0
  114. package/packages/core/src/scalar_text.ts +82 -0
  115. package/packages/core/src/scroll_mutation.ts +86 -0
  116. package/packages/core/src/scroll_tree.ts +86 -0
  117. package/packages/core/src/service_contract.ts +55 -3
  118. package/packages/core/src/session_codecs.ts +309 -0
  119. package/packages/core/src/shell_admission.ts +126 -0
  120. package/packages/core/src/shell_coordination.ts +93 -0
  121. package/packages/core/src/sqlite_cli.ts +14 -46
  122. package/packages/core/src/sqlite_codegen.ts +84 -0
  123. package/packages/core/src/staged_rebuild.ts +60 -0
  124. package/packages/core/src/status_validation.ts +232 -0
  125. package/packages/core/src/stream_policy.ts +63 -0
  126. package/packages/core/src/surface_recipes.ts +136 -0
  127. package/packages/core/src/system_admission.ts +60 -0
  128. package/packages/core/src/terminal_paint.ts +436 -0
  129. package/packages/core/src/text_document_width.ts +81 -0
  130. package/packages/core/src/text_measurement_cache.ts +69 -0
  131. package/packages/core/src/text_query_layout.ts +179 -0
  132. package/packages/core/src/text_run_layout.ts +410 -0
  133. package/packages/core/src/text_span_queries.ts +355 -0
  134. package/packages/core/src/typed_ast.ts +18 -1
  135. package/packages/core/src/types.ts +7 -5
  136. package/packages/core/src/vector_effects.ts +98 -0
  137. package/packages/core/src/vector_raster.ts +243 -0
  138. package/packages/core/src/view_bridge.ts +161 -0
  139. package/packages/core/src/view_check.ts +145 -0
  140. package/packages/core/src/view_components.ts +2415 -0
  141. package/packages/core/src/view_coordination.ts +198 -0
  142. package/packages/core/src/view_evaluator.ts +823 -0
  143. package/packages/core/src/view_frontend.ts +1102 -0
  144. package/packages/core/src/view_program.ts +221 -0
  145. package/packages/core/src/view_reload.ts +166 -0
  146. package/packages/core/src/view_reload_watch.ts +98 -0
  147. package/packages/core/src/view_sources.ts +34 -0
  148. package/packages/core/src/virtual_windows.ts +88 -0
  149. package/packages/core/src/web_panes.ts +67 -0
  150. package/packages/core/src/widget_audits.ts +202 -0
  151. package/packages/core/src/widget_changes.ts +258 -0
  152. package/packages/core/src/widget_continuity.ts +37 -0
  153. package/packages/core/src/widget_metrics.ts +139 -0
  154. package/packages/core/src/widget_motion.ts +171 -0
  155. package/packages/core/src/widget_paint.ts +272 -0
  156. package/packages/core/src/widget_paint_walk.ts +203 -0
  157. package/packages/core/src/widget_presentation.ts +141 -0
  158. package/packages/core/src/widget_reconcile.ts +63 -0
  159. package/packages/core/src/widget_retention.ts +62 -0
  160. package/packages/core/src/widget_routing.ts +262 -0
  161. package/packages/core/src/window_lifecycle.ts +92 -0
  162. package/packages/core/testing/index.ts +430 -0
  163. package/schemas/app.schema.json +13 -0
  164. package/skill-data/core/SKILL.md +2 -2
  165. package/skill-data/native-ui/SKILL.md +77 -18
  166. package/skill-data/ts-core/SKILL.md +117 -11
  167. package/skill-data/ts-services/SKILL.md +1 -1
  168. package/skill-data/ts-services/references/service-surface.md +288 -144
  169. package/src/app_runner/root.zig +39 -12
  170. package/src/app_runner/ts_compiled_view.zig +1702 -0
  171. package/src/app_runner/ts_core_main.zig +185 -14
  172. package/src/app_runner/ts_core_mobile.zig +25 -13
  173. package/src/automation/server.zig +57 -6
  174. package/src/automation/snapshot.zig +9 -637
  175. package/src/automation/snapshot_reference.zig +656 -0
  176. package/src/automation/snapshot_serialization.zig +566 -0
  177. package/src/embed/host.zig +2 -0
  178. package/src/embed/tests.zig +2 -0
  179. package/src/embed/ui_host.zig +2 -0
  180. package/src/platform/keyboard_input.zig +32 -0
  181. package/src/platform/linux/gtk_host.c +36 -24
  182. package/src/platform/linux/gtk_pixels.h +118 -0
  183. package/src/platform/linux/gtk_pixels_test.c +241 -0
  184. package/src/platform/linux/root.zig +4 -0
  185. package/src/platform/macos/appkit_host.h +7 -2
  186. package/src/platform/macos/appkit_host.m +219 -39
  187. package/src/platform/macos/cef_host.mm +15 -1
  188. package/src/platform/macos/global_shortcuts.zig +138 -0
  189. package/src/platform/macos/key_codes.zig +102 -0
  190. package/src/platform/macos/keyboard_input.zig +81 -0
  191. package/src/platform/macos/pointer_motion_test.m +96 -0
  192. package/src/platform/macos/root.zig +25 -3
  193. package/src/platform/macos/scroll_driver_test.m +105 -0
  194. package/src/platform/macos/spectrum_bins.h +34 -0
  195. package/src/platform/macos/spectrum_bins_test.c +56 -0
  196. package/src/platform/macos/text_keyboard_test.m +80 -0
  197. package/src/platform/macos/webview_inspection_test.m +106 -0
  198. package/src/platform/macos/widget_focus_test.m +66 -0
  199. package/src/platform/null_platform.zig +130 -2
  200. package/src/platform/null_platform_tests.zig +13 -0
  201. package/src/platform/root.zig +15 -0
  202. package/src/platform/types.zig +115 -0
  203. package/src/platform/windows/global_shortcuts.zig +157 -0
  204. package/src/platform/windows/key_codes.zig +63 -0
  205. package/src/platform/windows/keyboard_input.zig +136 -0
  206. package/src/platform/windows/root.zig +17 -0
  207. package/src/platform/windows/webview2_host.cpp +7 -2
  208. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  209. package/src/primitives/app_manifest/root.zig +2 -0
  210. package/src/primitives/app_manifest/tests.zig +4 -1
  211. package/src/primitives/app_manifest/validation.zig +2 -0
  212. package/src/primitives/canvas/a11y_audit.zig +3 -1
  213. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  214. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  215. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  216. package/src/primitives/canvas/code_content_policy.zig +162 -0
  217. package/src/primitives/canvas/commands.zig +29 -1
  218. package/src/primitives/canvas/component_composition.zig +125 -0
  219. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  220. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  221. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  222. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  223. package/src/primitives/canvas/control_command_policy.zig +75 -0
  224. package/src/primitives/canvas/control_content_policy.zig +90 -0
  225. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  226. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  227. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  228. package/src/primitives/canvas/decision_reuse.zig +133 -0
  229. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  230. package/src/primitives/canvas/events.zig +1027 -1
  231. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  232. package/src/primitives/canvas/font_ttf.zig +27 -3
  233. package/src/primitives/canvas/fonts/Geist-Bold.ttf +0 -0
  234. package/src/primitives/canvas/fonts/Geist-Medium.ttf +0 -0
  235. package/src/primitives/canvas/fonts/OFL.txt +93 -0
  236. package/src/primitives/canvas/fonts/README.md +15 -0
  237. package/src/primitives/canvas/frame.zig +92 -23
  238. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  239. package/src/primitives/canvas/gpu.zig +10 -0
  240. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  241. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  242. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  243. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  244. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  245. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  246. package/src/primitives/canvas/intrinsic_measure_policy.zig +131 -0
  247. package/src/primitives/canvas/layout_audit.zig +5 -2
  248. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  249. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  250. package/src/primitives/canvas/markdown.zig +13 -3
  251. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  252. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  253. package/src/primitives/canvas/markdown_tests.zig +3 -3
  254. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  255. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  256. package/src/primitives/canvas/reference.zig +15 -11
  257. package/src/primitives/canvas/reference_tests.zig +58 -0
  258. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  259. package/src/primitives/canvas/render.zig +48 -0
  260. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  261. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  262. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  263. package/src/primitives/canvas/render_effects.zig +14 -0
  264. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  265. package/src/primitives/canvas/render_images.zig +14 -0
  266. package/src/primitives/canvas/render_layers.zig +14 -0
  267. package/src/primitives/canvas/render_override_policy.zig +119 -0
  268. package/src/primitives/canvas/render_paths.zig +14 -0
  269. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  270. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  271. package/src/primitives/canvas/root.zig +107 -4
  272. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  273. package/src/primitives/canvas/serialization.zig +8 -1
  274. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  275. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  276. package/src/primitives/canvas/terminal_grid.zig +10 -696
  277. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  278. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  279. package/src/primitives/canvas/text.zig +1 -0
  280. package/src/primitives/canvas/text_atlas.zig +113 -0
  281. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  282. package/src/primitives/canvas/text_document_policy.zig +120 -0
  283. package/src/primitives/canvas/text_layout.zig +51 -2
  284. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  285. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  286. package/src/primitives/canvas/text_layout_types.zig +3 -0
  287. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  288. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  289. package/src/primitives/canvas/text_metrics.zig +53 -37
  290. package/src/primitives/canvas/text_metrics_tests.zig +52 -7
  291. package/src/primitives/canvas/text_query_policy.zig +295 -0
  292. package/src/primitives/canvas/text_run_policy.zig +252 -0
  293. package/src/primitives/canvas/text_scalar_policy.zig +234 -0
  294. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  295. package/src/primitives/canvas/text_spans.zig +280 -8
  296. package/src/primitives/canvas/text_tests.zig +10 -0
  297. package/src/primitives/canvas/tokens.zig +47 -0
  298. package/src/primitives/canvas/ui.zig +251 -83
  299. package/src/primitives/canvas/ui_markup.zig +207 -46
  300. package/src/primitives/canvas/ui_markup_canonical.zig +237 -0
  301. package/src/primitives/canvas/ui_markup_compiled.zig +1724 -80
  302. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  303. package/src/primitives/canvas/ui_markup_compiled_values.zig +76 -0
  304. package/src/primitives/canvas/ui_markup_construction.zig +146 -0
  305. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  306. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  307. package/src/primitives/canvas/ui_markup_display.zig +82 -0
  308. package/src/primitives/canvas/ui_markup_document.zig +196 -0
  309. package/src/primitives/canvas/ui_markup_elements.zig +163 -0
  310. package/src/primitives/canvas/ui_markup_expr.zig +192 -2
  311. package/src/primitives/canvas/ui_markup_imports.zig +262 -0
  312. package/src/primitives/canvas/ui_markup_parser.zig +117 -0
  313. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  314. package/src/primitives/canvas/ui_markup_runtime.zig +76 -0
  315. package/src/primitives/canvas/ui_markup_scalars.zig +115 -0
  316. package/src/primitives/canvas/ui_markup_shapes.zig +224 -0
  317. package/src/primitives/canvas/ui_markup_specialized.zig +106 -0
  318. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  319. package/src/primitives/canvas/ui_markup_text.zig +128 -0
  320. package/src/primitives/canvas/ui_markup_values.zig +368 -0
  321. package/src/primitives/canvas/ui_markup_view.zig +3026 -57
  322. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  323. package/src/primitives/canvas/ui_schema.zig +13 -1
  324. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  325. package/src/primitives/canvas/ui_tests.zig +1 -0
  326. package/src/primitives/canvas/vector.zig +36 -2
  327. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  328. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  329. package/src/primitives/canvas/virtual_extent_policy.zig +350 -0
  330. package/src/primitives/canvas/virtual_extents.zig +113 -3
  331. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  332. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  333. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  334. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  335. package/src/primitives/canvas/widget_layout.zig +673 -128
  336. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  337. package/src/primitives/canvas/widget_metric_policy.zig +129 -0
  338. package/src/primitives/canvas/widget_metrics.zig +45 -6
  339. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  340. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  341. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  342. package/src/primitives/canvas/widget_render.zig +744 -74
  343. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  344. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  345. package/src/primitives/canvas/widget_render_style.zig +94 -0
  346. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  347. package/src/primitives/canvas/widget_routing.zig +75 -0
  348. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  349. package/src/primitives/canvas/widget_runtime.zig +21 -1
  350. package/src/primitives/canvas/widget_semantics.zig +25 -0
  351. package/src/primitives/canvas/widget_text_input.zig +86 -23
  352. package/src/primitives/canvas/widget_text_select.zig +1 -0
  353. package/src/primitives/canvas/widget_tree.zig +8 -1
  354. package/src/primitives/canvas/widgets.zig +42 -12
  355. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  356. package/src/root.zig +26 -0
  357. package/src/runtime/accessibility_policy.zig +122 -0
  358. package/src/runtime/api.zig +29 -0
  359. package/src/runtime/app_dispatch_policy.zig +68 -0
  360. package/src/runtime/authorization_policy.zig +150 -0
  361. package/src/runtime/automation_command_policy.zig +241 -0
  362. package/src/runtime/automation_interaction_policy.zig +107 -0
  363. package/src/runtime/automation_snapshot.zig +52 -22
  364. package/src/runtime/automation_snapshot_reference.zig +290 -0
  365. package/src/runtime/automation_widget_dispatch.zig +267 -355
  366. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  367. package/src/runtime/blob_policy.zig +58 -0
  368. package/src/runtime/blob_reference.zig +64 -0
  369. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  370. package/src/runtime/bridge_payload.zig +2 -0
  371. package/src/runtime/builtin_bridge.zig +180 -44
  372. package/src/runtime/builtin_coordination_policy.zig +121 -0
  373. package/src/runtime/callback_policy_test_reference.zig +97 -0
  374. package/src/runtime/canvas_drag_policy.zig +94 -0
  375. package/src/runtime/canvas_fonts.zig +38 -10
  376. package/src/runtime/canvas_frame.zig +590 -134
  377. package/src/runtime/canvas_frame_helpers.zig +1 -0
  378. package/src/runtime/canvas_hover_policy.zig +131 -0
  379. package/src/runtime/canvas_images.zig +59 -30
  380. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  381. package/src/runtime/canvas_limits.zig +1 -1
  382. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  383. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  384. package/src/runtime/canvas_widget_context_menu.zig +183 -4
  385. package/src/runtime/canvas_widget_context_menu_test_cases.zig +1147 -0
  386. package/src/runtime/canvas_widget_context_menu_tests.zig +23 -1098
  387. package/src/runtime/canvas_widget_display.zig +110 -9
  388. package/src/runtime/canvas_widget_events.zig +718 -328
  389. package/src/runtime/canvas_widget_runtime.zig +720 -150
  390. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  391. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  392. package/src/runtime/canvas_widget_state.zig +93 -56
  393. package/src/runtime/channel_sources.zig +80 -0
  394. package/src/runtime/command_policy.zig +161 -0
  395. package/src/runtime/component_policy.zig +83 -0
  396. package/src/runtime/context_menu_policy.zig +112 -0
  397. package/src/runtime/core.zig +170 -6
  398. package/src/runtime/desktop_files.zig +189 -0
  399. package/src/runtime/effects.zig +638 -33
  400. package/src/runtime/effects_host_tests.zig +25 -0
  401. package/src/runtime/effects_tests.zig +28 -0
  402. package/src/runtime/file_policy_test_reference.zig +113 -0
  403. package/src/runtime/flow.zig +419 -341
  404. package/src/runtime/flow_reference.zig +1427 -0
  405. package/src/runtime/font_registry_policy.zig +72 -0
  406. package/src/runtime/frame_profile.zig +24 -33
  407. package/src/runtime/global_shortcuts.zig +75 -0
  408. package/src/runtime/gpu_surface_events.zig +97 -35
  409. package/src/runtime/host_event_pump.zig +303 -0
  410. package/src/runtime/host_event_pump_reference.zig +268 -0
  411. package/src/runtime/host_flow_policy.zig +155 -0
  412. package/src/runtime/host_input_regions_policy.zig +156 -0
  413. package/src/runtime/image_registry_policy.zig +94 -0
  414. package/src/runtime/input_composition_policy.zig +138 -0
  415. package/src/runtime/journal_policy.zig +66 -0
  416. package/src/runtime/journal_reference.zig +53 -0
  417. package/src/runtime/keyboard_input.zig +86 -0
  418. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  419. package/src/runtime/markup_development_policy.zig +91 -0
  420. package/src/runtime/media_surface.zig +40 -1
  421. package/src/runtime/motion_sampling_policy.zig +159 -0
  422. package/src/runtime/recording_policy.zig +42 -0
  423. package/src/runtime/render_animation_policy.zig +206 -0
  424. package/src/runtime/replay_policy.zig +66 -0
  425. package/src/runtime/replay_policy_reference.zig +326 -0
  426. package/src/runtime/replay_progress_policy.zig +64 -0
  427. package/src/runtime/replay_progress_reference.zig +34 -0
  428. package/src/runtime/request_policy_test_reference.zig +188 -0
  429. package/src/runtime/root.zig +16 -0
  430. package/src/runtime/scroll_mutation_policy.zig +130 -0
  431. package/src/runtime/scroll_mutation_runtime.zig +158 -0
  432. package/src/runtime/scroll_tree_policy.zig +99 -0
  433. package/src/runtime/session_blobs.zig +157 -58
  434. package/src/runtime/session_blobs_reference.zig +692 -0
  435. package/src/runtime/session_codec.zig +361 -0
  436. package/src/runtime/session_codec_reference.zig +1027 -0
  437. package/src/runtime/session_journal.zig +246 -983
  438. package/src/runtime/session_record.zig +231 -45
  439. package/src/runtime/session_replay.zig +157 -415
  440. package/src/runtime/session_tests.zig +552 -0
  441. package/src/runtime/shell_admission_policy.zig +225 -0
  442. package/src/runtime/shell_coordination_policy.zig +138 -0
  443. package/src/runtime/shell_layout.zig +126 -1
  444. package/src/runtime/snapshot_policy.zig +60 -0
  445. package/src/runtime/snapshot_reference.zig +64 -0
  446. package/src/runtime/staged_rebuild_policy.zig +83 -0
  447. package/src/runtime/state.zig +16 -0
  448. package/src/runtime/status_validation.zig +190 -0
  449. package/src/runtime/system_admission_policy.zig +140 -0
  450. package/src/runtime/system_services.zig +65 -36
  451. package/src/runtime/tests.zig +2 -0
  452. package/src/runtime/ts_canvas_hooks.zig +261 -0
  453. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  454. package/src/runtime/ts_canvas_icons.zig +234 -0
  455. package/src/runtime/ts_core_host.zig +2451 -411
  456. package/src/runtime/ts_core_host_tests.zig +1982 -0
  457. package/src/runtime/ts_test_host.zig +699 -0
  458. package/src/runtime/ts_ui_app.zig +1111 -45
  459. package/src/runtime/ui_app.zig +1381 -650
  460. package/src/runtime/ui_app_provenance.zig +147 -5
  461. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  462. package/src/runtime/ui_app_tests.zig +667 -188
  463. package/src/runtime/ui_app_window_tests.zig +222 -0
  464. package/src/runtime/view.zig +25 -0
  465. package/src/runtime/view_canvas.zig +30 -6
  466. package/src/runtime/view_coordination_policy.zig +147 -0
  467. package/src/runtime/view_reload.zig +226 -0
  468. package/src/runtime/view_widget_control.zig +51 -14
  469. package/src/runtime/view_widget_scroll.zig +46 -26
  470. package/src/runtime/view_widget_text.zig +153 -68
  471. package/src/runtime/view_widget_tree.zig +503 -69
  472. package/src/runtime/virtual_window_policy.zig +128 -0
  473. package/src/runtime/web_pane_policy.zig +111 -0
  474. package/src/runtime/web_pane_test_cases.zig +204 -0
  475. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  476. package/src/runtime/widget_continuity_policy.zig +73 -0
  477. package/src/runtime/widget_motion_policy.zig +238 -0
  478. package/src/runtime/widget_reconcile_policy.zig +81 -0
  479. package/src/runtime/widget_retention_policy.zig +75 -0
  480. package/src/runtime/window_command_bridge_tests.zig +63 -0
  481. package/src/runtime/window_lifecycle_policy.zig +127 -0
  482. package/src/runtime/window_storage.zig +74 -8
  483. package/src/runtime/window_view_runtime.zig +148 -33
  484. package/src/runtime/window_views.zig +179 -11
  485. package/src/security/root.zig +1 -0
  486. package/src/tooling/components/identity_tests.zig +62 -36
  487. package/src/tooling/components/stepper.native +24 -0
  488. package/src/tooling/components/stepper.zig +0 -19
  489. package/src/tooling/components/timeline-item.native +22 -0
  490. package/src/tooling/components/timeline.native +5 -3
  491. package/src/tooling/components/timeline_item.zig +0 -32
  492. package/src/tooling/eject_components.zig +76 -8
  493. package/src/tooling/ios.zig +66 -12
  494. package/src/tooling/manifest.zig +35 -0
  495. package/src/tooling/raw_manifest.zig +6 -0
  496. package/src/tooling/templates.zig +23 -3
  497. package/src/tooling/ts_core.zig +97 -4
  498. package/src/tooling/verbs.zig +87 -1
  499. package/tools/corewire/build_profile.mjs +54 -0
  500. package/tools/corewire/contract_intake.ts +303 -0
  501. package/tools/corewire/contract_intake.zig +82 -0
  502. package/tools/corewire/core.test.ts +188 -0
  503. package/tools/corewire/core_abi.zig +55 -0
  504. package/tools/corewire/core_cases.ts +233 -0
  505. package/tools/corewire/core_contract.ts +407 -0
  506. package/tools/corewire/core_emission.ts +136 -0
  507. package/tools/corewire/core_emission.zig +69 -0
  508. package/tools/corewire/core_goldens.json +3110 -0
  509. package/tools/corewire/core_policy.ts +14 -0
  510. package/tools/corewire/core_policy.zig +48 -0
  511. package/tools/corewire/core_projection.ts +361 -0
  512. package/tools/corewire/core_vocabulary.ts +6 -0
  513. package/tools/corewire/emit.zig +19 -1590
  514. package/tools/corewire/emit_facade.ts +714 -0
  515. package/tools/corewire/emit_facade.zig +10 -3752
  516. package/tools/corewire/emit_mirror.ts +300 -0
  517. package/tools/corewire/emit_profile.ts +50 -0
  518. package/tools/corewire/emit_service.ts +331 -0
  519. package/tools/corewire/emit_service.zig +23 -842
  520. package/tools/corewire/entry.test.ts +95 -0
  521. package/tools/corewire/entry_coordination.ts +127 -0
  522. package/tools/corewire/entry_coordination.zig +190 -0
  523. package/tools/corewire/facade_templates.ts +85 -0
  524. package/tools/corewire/filesystem.test.ts +166 -0
  525. package/tools/corewire/filesystem_coordination.ts +213 -0
  526. package/tools/corewire/filesystem_coordination.zig +245 -0
  527. package/tools/corewire/intake.test.ts +39 -0
  528. package/tools/corewire/intake_cases.ts +55 -0
  529. package/tools/corewire/intake_goldens.json +12237 -0
  530. package/tools/corewire/invocation.test.ts +28 -0
  531. package/tools/corewire/invocation.ts +175 -0
  532. package/tools/corewire/invocation.zig +136 -0
  533. package/tools/corewire/invocation_cases.ts +60 -0
  534. package/tools/corewire/invocation_fixture.ts +33 -0
  535. package/tools/corewire/invocation_goldens.json +1143 -0
  536. package/tools/corewire/invocation_tests.zig +111 -0
  537. package/tools/corewire/invocation_usage.ts +2 -0
  538. package/tools/corewire/lossless_projection.ts +96 -0
  539. package/tools/corewire/main.zig +7 -680
  540. package/tools/corewire/main_reference.zig +415 -0
  541. package/tools/corewire/mirror_templates.ts +59 -0
  542. package/tools/corewire/profile.test.ts +248 -0
  543. package/tools/corewire/profile.zig +56 -0
  544. package/tools/corewire/profile_emission.ts +204 -0
  545. package/tools/corewire/profile_library.json +29 -0
  546. package/tools/corewire/profile_tests.zig +136 -0
  547. package/tools/corewire/service.test.ts +75 -0
  548. package/tools/corewire/service_cases.ts +61 -0
  549. package/tools/corewire/service_contract.zig +40 -146
  550. package/tools/corewire/service_goldens.json +650 -0
  551. package/tools/corewire/service_projection.zig +52 -0
  552. package/tools/corewire/service_templates.ts +14 -0
  553. package/tools/corewire/shim_rt.zig +9 -0
  554. package/tools/corewire/sidecar.zig +269 -1438
  555. package/tools/corewire/emit_profile.zig +0 -521
@@ -72,14 +72,15 @@ const builtin = @import("builtin");
72
72
  const canvas = @import("canvas");
73
73
  const canvas_limits = @import("canvas_limits.zig");
74
74
  const platform = @import("../platform/root.zig");
75
- const validation = @import("validation.zig");
76
75
  const runtime_clock = @import("clock.zig");
77
76
  const persist_store = @import("persist_store.zig");
78
77
  const record_store = @import("record_store.zig");
79
78
  const relational_store = @import("relational_store.zig");
80
79
  const credentials_store = @import("credentials_store.zig");
80
+ const keyboard_input = @import("keyboard_input.zig");
81
81
  const file_access = @import("file_access.zig");
82
82
  const pty_transport = @import("pty.zig");
83
+ const global_shortcuts_mod = @import("global_shortcuts.zig");
83
84
 
84
85
  /// Maximum in-flight effects (spawn slots / worker threads).
85
86
  pub const max_effects: usize = 16;
@@ -374,6 +375,9 @@ pub const WindowActionBinding = struct {
374
375
  minimize_fn: *const fn (context: *anyopaque, window_label: []const u8) bool,
375
376
  hide_fn: *const fn (context: *anyopaque, window_label: []const u8) bool,
376
377
  show_fn: *const fn (context: *anyopaque, window_label: []const u8) bool,
378
+ /// Replay the synchronous show bookkeeping without an OS call. The
379
+ /// later native frame event must not delay keyboard-focus loss.
380
+ replay_show_fn: ?*const fn (context: *anyopaque, window_label: []const u8) void = null,
377
381
  dock_presence_fn: *const fn (context: *anyopaque, visible: bool) bool,
378
382
  quit_fn: *const fn (context: *anyopaque) bool,
379
383
  };
@@ -387,6 +391,11 @@ pub const SystemServiceBinding = struct {
387
391
  open_external_url_fn: *const fn (context: *anyopaque, url: []const u8) anyerror!void,
388
392
  reveal_path_fn: *const fn (context: *anyopaque, path: []const u8) anyerror!void,
389
393
  format_local_time_fn: *const fn (context: *anyopaque, timestamp_ms: i64, style: platform.LocalTimeStyle, buffer: []u8) anyerror![]const u8,
394
+ execute_capability_fn: ?*const fn (context: *anyopaque, name: []const u8, payload: []const u8, output: []u8) anyerror![]const u8 = null,
395
+ /// Restore only runtime window bookkeeping from a journaled successful
396
+ /// capability, without invoking native window focus or close services.
397
+ replay_window_result_fn: ?*const fn (context: *anyopaque, label: []const u8, closed: bool) void = null,
398
+ keyboard_input: ?keyboard_input.Binding = null,
390
399
  };
391
400
 
392
401
  /// Type-erased handle to the embedding host's named-command services,
@@ -433,6 +442,21 @@ pub const HostChannelBinding = struct {
433
442
  acquire_fn: *const fn (context: *anyopaque, key: u64) ?ChannelHandle,
434
443
  };
435
444
 
445
+ /// Loop-thread startup only. Implementations copy arguments before returning
446
+ /// and may retain the generation-safe handle; they must not reenter the UI.
447
+ pub const HostChannelSourceBinding = struct {
448
+ context: *anyopaque,
449
+ start_fn: *const fn (context: *anyopaque, name: []const u8, payload: []const u8, handle: ChannelHandle) anyerror!void,
450
+ };
451
+ pub const EffectChannelSourceState = enum(u8) { skipped, started, failed };
452
+ pub const EffectChannelSourceResult = struct {
453
+ key: u64,
454
+ state: EffectChannelSourceState,
455
+ bytes: []const u8 = "",
456
+ };
457
+ pub const max_channel_source_payload = 4096;
458
+ const max_channel_source_request = 1 + max_effect_host_name_bytes + 4 + max_channel_source_payload;
459
+
436
460
  pub const HostCallCompletion = struct {
437
461
  key: u64,
438
462
  ok: bool,
@@ -1266,6 +1290,9 @@ pub const EffectAudioCaptureEvent = struct {
1266
1290
  const audio_capture_packet_header_bytes: usize = 24;
1267
1291
  const audio_capture_packet_magic = "AC01";
1268
1292
 
1293
+ pub const EffectGlobalShortcutEventKind = global_shortcuts_mod.EffectGlobalShortcutEventKind;
1294
+ pub const EffectGlobalShortcutEvent = global_shortcuts_mod.EffectGlobalShortcutEvent;
1295
+
1269
1296
  /// Convert the channel envelope used internally by capture into its public
1270
1297
  /// typed event. Also useful to native integrations that intentionally route
1271
1298
  /// capture through a generic `channelMsg` handler.
@@ -2030,6 +2057,12 @@ pub const EffectResultKind = enum(u8) {
2030
2057
  /// salted digest and length; replay synthesizes same-length placeholder
2031
2058
  /// bytes and never consults an OS keychain.
2032
2059
  credentials = 18,
2060
+ /// Successful native window bookkeeping, at execution rather than Msg
2061
+ /// delivery. `code` is 0 for focus and 1 for close; the complete copied
2062
+ /// request and correlated reply ride `payload` and `stderr_tail`.
2063
+ window_execution = 19,
2064
+ /// Immediate external producer startup; request rides payload, error rides stderr_tail.
2065
+ channel_source = 20,
2033
2066
  };
2034
2067
 
2035
2068
  /// Journaled wall-clock reads buffered for replay (`Effects.wallMs`).
@@ -2952,6 +2985,15 @@ pub fn Effects(comptime Msg: type) type {
2952
2985
  }.make;
2953
2986
  }
2954
2987
 
2988
+ /// Msg constructor for `setGlobalShortcuts` reports.
2989
+ pub fn globalShortcutMsg(comptime tag: std.meta.Tag(Msg)) ChannelMsgFn {
2990
+ return struct {
2991
+ fn make(event: EffectChannelEvent) Msg {
2992
+ return @unionInit(Msg, @tagName(tag), global_shortcuts_mod.decodeChannelEvent(event));
2993
+ }
2994
+ }.make;
2995
+ }
2996
+
2955
2997
  /// Comptime Msg constructor for `on_event` of pty effects:
2956
2998
  /// `ptyMsg(.shell)` builds `Msg{ .shell = event }` — the
2957
2999
  /// variant's payload type must be `native_sdk.EffectPtyEvent`.
@@ -3042,6 +3084,8 @@ pub fn Effects(comptime Msg: type) type {
3042
3084
  /// valid until the fetch's response is drained.
3043
3085
  pub const FetchRequest = struct {
3044
3086
  key: u64,
3087
+ generation: u64 = 0,
3088
+ timeout_ms: u32 = 0,
3045
3089
  method: std.http.Method,
3046
3090
  url: []const u8,
3047
3091
  headers: []const std.http.Header,
@@ -3083,9 +3127,10 @@ pub fn Effects(comptime Msg: type) type {
3083
3127
  /// valid until the result is fed and drained.
3084
3128
  pub const FileRequest = struct {
3085
3129
  key: u64,
3130
+ generation: u64 = 0,
3086
3131
  op: EffectFileOp,
3087
3132
  path: []const u8,
3088
- /// The bytes a `writeFile` would write; `""` for reads.
3133
+ /// The bytes a `writeFile` or `appendFile` would write; `""` for reads.
3089
3134
  bytes: []const u8 = "",
3090
3135
  };
3091
3136
 
@@ -3158,6 +3203,7 @@ pub fn Effects(comptime Msg: type) type {
3158
3203
  /// stays valid until the result is fed and drained.
3159
3204
  pub const ClipboardRequest = struct {
3160
3205
  key: u64,
3206
+ generation: u64 = 0,
3161
3207
  op: EffectClipboardOp,
3162
3208
  /// The text a `writeClipboard` would write; `""` for reads.
3163
3209
  text: []const u8 = "",
@@ -3436,6 +3482,12 @@ pub fn Effects(comptime Msg: type) type {
3436
3482
  max_pending: u32 = max_effect_channel_pending,
3437
3483
  };
3438
3484
 
3485
+ pub const SetGlobalShortcutsOptions = struct {
3486
+ key: u64,
3487
+ shortcuts: []const platform.Shortcut,
3488
+ on_event: ChannelMsgFn,
3489
+ };
3490
+
3439
3491
  pub const PtySpawnOptions = struct {
3440
3492
  /// Caller-chosen identity, stored in the model. Shares the
3441
3493
  /// keyed families' one key space, occupied from spawn until
@@ -4480,6 +4532,24 @@ pub fn Effects(comptime Msg: type) type {
4480
4532
  }
4481
4533
  };
4482
4534
 
4535
+ const ReplayChannelSource = struct {
4536
+ key: u64,
4537
+ state: EffectChannelSourceState,
4538
+ request_len: usize,
4539
+ request: [max_channel_source_request]u8,
4540
+ failure_len: u8,
4541
+ failure: [255]u8,
4542
+ };
4543
+
4544
+ const ReplayWindowExecution = struct {
4545
+ key: u64,
4546
+ closed: bool,
4547
+ request_len: u16,
4548
+ request: [293]u8,
4549
+ reply_len: u8,
4550
+ reply: [38]u8,
4551
+ };
4552
+
4483
4553
  const Slot = struct {
4484
4554
  state: std.atomic.Value(SlotState) = std.atomic.Value(SlotState).init(.idle),
4485
4555
  generation: u32 = 0,
@@ -4596,6 +4666,11 @@ pub fn Effects(comptime Msg: type) type {
4596
4666
  /// credential slots or letting an older set finish last.
4597
4667
  credentials_waiting: bool = false,
4598
4668
  credentials_sequence: u64 = 0,
4669
+ // Desktop calls can enter AppKit or remove runtime views. UiApp
4670
+ // executes them only after its current rebuild has settled.
4671
+ desktop_waiting: bool = false,
4672
+ replay_window_reply_len: u8 = 0,
4673
+ replay_window_reply: [38]u8 = undefined,
4599
4674
  // ---- image-only fields (kind == .image) ----
4600
4675
  on_image: ?ImageMsgFn = null,
4601
4676
  /// The local source path (the URL rides `url_storage`, a
@@ -4864,6 +4939,11 @@ pub fn Effects(comptime Msg: type) type {
4864
4939
  /// requests reject loudly in real mode, and the fake executor
4865
4940
  /// parks requests for `feedHostResult` regardless.
4866
4941
  host_calls: ?HostCallBinding = null,
4942
+ channel_sources: ?HostChannelSourceBinding = null,
4943
+ replay_channel_sources: [64]ReplayChannelSource = undefined,
4944
+ replay_channel_source_len: usize = 0,
4945
+ replay_channel_source_diverged: bool = false,
4946
+ channel_source_reply: [255]u8 = undefined,
4867
4947
  /// Capability-installed record-store service. Store commands are
4868
4948
  /// SDK-reserved routed requests, so their results reuse the request
4869
4949
  /// journal/replay path while the database handle stays host-owned.
@@ -4969,6 +5049,9 @@ pub fn Effects(comptime Msg: type) type {
4969
5049
  fetch_start_rejections: std.atomic.Value(u32) = std.atomic.Value(u32).init(0),
4970
5050
  next_generation: u32 = 1,
4971
5051
  next_credentials_sequence: u64 = 1,
5052
+ defer_desktop_capabilities: bool = false,
5053
+ flushing_desktop_capabilities: bool = false,
5054
+ system_admission_policy: ?*const fn ([]const u8, []u8) usize = null,
4972
5055
  /// The channel family's OWN generation counter — u64 and
4973
5056
  /// monotonic for the process's lifetime, never the shared u32
4974
5057
  /// `next_generation` above: channel handles live on app-owned
@@ -5008,6 +5091,7 @@ pub fn Effects(comptime Msg: type) type {
5008
5091
  /// channel table; this tiny loop-side mirror exists to quiesce native
5009
5092
  /// audio callbacks before closing/reusing their channel occupancy.
5010
5093
  audio_capture_slots: [2]AudioCaptureSlot = [_]AudioCaptureSlot{.{}} ** 2,
5094
+ global_shortcuts: global_shortcuts_mod.Session = .{},
5011
5095
  /// Monotonic post-order stamp shared by every channel's staging
5012
5096
  /// FIFO and the close markers: the cross-channel delivery order
5013
5097
  /// and the drain boundary's causality cut (posts stamped at or
@@ -5106,6 +5190,9 @@ pub fn Effects(comptime Msg: type) type {
5106
5190
  /// after (freed when the queue empties, and at `deinit`) — the
5107
5191
  /// pending stages' storage discipline.
5108
5192
  replay_video_sources: [max_effect_replay_video_source_entries]ReplayVideoSource = undefined,
5193
+ replay_window_executions: [64]ReplayWindowExecution = undefined,
5194
+ replay_window_execution_len: usize = 0,
5195
+ replay_window_diverged: bool = false,
5109
5196
  replay_video_source_spill: []ReplayVideoSource = &.{},
5110
5197
  replay_video_source_len: usize = 0,
5111
5198
  /// A journaled cascade resolution paired against a different
@@ -5113,6 +5200,7 @@ pub fn Effects(comptime Msg: type) type {
5113
5200
  /// for `finishReplay`, which turns it into the divergence
5114
5201
  /// refusal the void-returning `loadVideo` cannot raise itself.
5115
5202
  replay_video_diverged: bool = false,
5203
+ replay_audio_diverged: bool = false,
5116
5204
  /// Drain-pass counter (incremented in `drainBoundary`): the
5117
5205
  /// retired-video sweep's clock. Loop-thread only.
5118
5206
  drain_pass_seq: u64 = 0,
@@ -5251,6 +5339,10 @@ pub fn Effects(comptime Msg: type) type {
5251
5339
  }
5252
5340
  capture.* = .{};
5253
5341
  }
5342
+ if (self.global_shortcuts.platform_configured) {
5343
+ if (self.services) |services| services.configureGlobalShortcuts(&.{}, .{}, &.{}) catch {};
5344
+ }
5345
+ self.global_shortcuts = .{};
5254
5346
  // Silence the platform audio player (best effort) and clear
5255
5347
  // the channel.
5256
5348
  if (self.audio.active and !self.audio.fake) {
@@ -6337,12 +6429,21 @@ pub fn Effects(comptime Msg: type) type {
6337
6429
  }
6338
6430
 
6339
6431
  /// End-of-journal consistency check (the `.finish` replay
6340
- /// control): every journaled video cascade resolution must have
6432
+ /// control): synchronous audio deliveries must match and leave no
6433
+ /// fed results pending; every journaled video cascade resolution must have
6341
6434
  /// been consumed by the load it named, and none may have paired
6342
6435
  /// against a different key. A leftover or mismatched record
6343
6436
  /// means the replayed updates issued different loads than the
6344
6437
  /// recording — divergence, not success.
6345
- pub fn finishReplay(self: *Self) error{ReplayVideoDivergence}!void {
6438
+ pub fn finishReplay(self: *Self) error{ ReplayAudioDivergence, ReplayVideoDivergence, ReplayWindowDivergence, ReplayChannelSourceDivergence }!void {
6439
+ if (self.replay_channel_source_diverged or self.replay_channel_source_len != 0) return error.ReplayChannelSourceDivergence;
6440
+ if (self.replay_window_diverged or self.replay_window_execution_len != 0) return error.ReplayWindowDivergence;
6441
+ for (&self.slots) |*slot| if (slot.replay_window_reply_len != 0) return error.ReplayWindowDivergence;
6442
+ if (self.replay_audio_diverged) return error.ReplayAudioDivergence;
6443
+ for (0..self.pending_exit_len) |offset| {
6444
+ const entry = self.pending_exits[(self.pending_exit_head + offset) % max_effect_pending_exits];
6445
+ if (entry == .audio and entry.audio.resolve) return error.ReplayAudioDivergence;
6446
+ }
6346
6447
  if (self.replay_video_diverged) return error.ReplayVideoDivergence;
6347
6448
  if (self.replay_video_source_len > 0) {
6348
6449
  std.debug.print(
@@ -7695,11 +7796,76 @@ pub fn Effects(comptime Msg: type) type {
7695
7796
  return .{ .shared = shared, .generation = generation };
7696
7797
  }
7697
7798
 
7698
- /// The thread-safe posting handle of the OPEN channel with
7699
- /// `key`, for callers that did not keep `openChannel`'s return
7700
- /// (an embedder resolving a channel a transpiled core opened).
7701
- /// Null while no open channel holds the key — including the
7702
- /// `.closing` window, where posts could no longer land anyway.
7799
+ /// Capture startup truth before publishing the issuing dispatch. The
7800
+ /// handle must come from this open, never a same-key old occupancy.
7801
+ /// Returned failure bytes are borrowed until the next source start.
7802
+ pub fn startChannelSource(self: *Self, key: u64, handle: ?ChannelHandle, name: []const u8, payload: []const u8) EffectChannelSourceResult {
7803
+ std.debug.assert(name.len > 0 and name.len <= max_effect_host_name_bytes and payload.len <= max_channel_source_payload);
7804
+ var request: [max_channel_source_request]u8 = undefined;
7805
+ request[0] = @intCast(name.len);
7806
+ @memcpy(request[1..][0..name.len], name);
7807
+ std.mem.writeInt(u32, request[1 + name.len ..][0..4], @intCast(payload.len), .little);
7808
+ @memcpy(request[5 + name.len ..][0..payload.len], payload);
7809
+ const encoded = request[0 .. 5 + name.len + payload.len];
7810
+ if (self.replay) {
7811
+ if (self.replay_channel_source_len == 0) {
7812
+ self.replay_channel_source_diverged = true;
7813
+ return .{ .key = key, .state = .failed, .bytes = "replay_diverged" };
7814
+ }
7815
+ const entry = &self.replay_channel_sources[0];
7816
+ if (entry.key != key or !std.mem.eql(u8, encoded, entry.request[0..entry.request_len]) or
7817
+ ((entry.state == .skipped) != (handle == null))) self.replay_channel_source_diverged = true;
7818
+ const state = entry.state;
7819
+ const len = entry.failure_len;
7820
+ @memcpy(self.channel_source_reply[0..len], entry.failure[0..len]);
7821
+ self.replay_channel_source_len -= 1;
7822
+ std.mem.copyForwards(ReplayChannelSource, self.replay_channel_sources[0..self.replay_channel_source_len], self.replay_channel_sources[1 .. self.replay_channel_source_len + 1]);
7823
+ return .{ .key = key, .state = state, .bytes = self.channel_source_reply[0..len] };
7824
+ }
7825
+ var result: EffectChannelSourceResult = .{ .key = key, .state = .skipped };
7826
+ if (handle) |live| {
7827
+ if (live.live()) {
7828
+ result.state = .started;
7829
+ const outcome = if (self.channel_sources) |binding|
7830
+ binding.start_fn(binding.context, name, payload, live)
7831
+ else if (self.executor == .fake)
7832
+ error.UnsupportedChannelSource
7833
+ else
7834
+ @import("channel_sources.zig").start(name, payload, live);
7835
+ outcome catch |err| {
7836
+ result.state = .failed;
7837
+ const failure = @errorName(err);
7838
+ result.bytes = failure[0..@min(failure.len, self.channel_source_reply.len)];
7839
+ };
7840
+ }
7841
+ }
7842
+ self.journalNote(.{ .kind = .channel_source, .key = key, .code = @intFromEnum(result.state), .payload = encoded, .stderr_tail = result.bytes });
7843
+ return result;
7844
+ }
7845
+
7846
+ pub fn pushReplayChannelSource(self: *Self, record: EffectResultRecord) !void {
7847
+ const canonical: EffectResultRecord = .{ .kind = .channel_source, .key = record.key, .code = record.code, .payload = record.payload, .stderr_tail = record.stderr_tail };
7848
+ if (!self.replay or record.kind != .channel_source or record.code < 0 or record.code > 2 or
7849
+ !std.meta.eql(record, canonical) or record.payload.len < 6 or record.payload.len > max_channel_source_request or
7850
+ record.stderr_tail.len > 255 or (record.code == 2) != (record.stderr_tail.len != 0)) return error.ReplayDamagedRecord;
7851
+ const name_len: usize = record.payload[0];
7852
+ if (name_len == 0 or record.payload.len < 5 + name_len or
7853
+ !std.unicode.utf8ValidateSlice(record.payload[1..][0..name_len]) or
7854
+ std.mem.readInt(u32, record.payload[1 + name_len ..][0..4], .little) != record.payload.len - 5 - name_len or
7855
+ record.payload.len - 5 - name_len > max_channel_source_payload) return error.ReplayDamagedRecord;
7856
+ if (self.replay_channel_source_len == self.replay_channel_sources.len) return error.ReplayChannelSourceDivergence;
7857
+ const entry = &self.replay_channel_sources[self.replay_channel_source_len];
7858
+ entry.key = record.key;
7859
+ entry.state = @enumFromInt(record.code);
7860
+ entry.request_len = record.payload.len;
7861
+ @memcpy(entry.request[0..record.payload.len], record.payload);
7862
+ entry.failure_len = @intCast(record.stderr_tail.len);
7863
+ @memcpy(entry.failure[0..record.stderr_tail.len], record.stderr_tail);
7864
+ self.replay_channel_source_len += 1;
7865
+ }
7866
+
7867
+ /// Resolve the open occupancy's generation-safe posting handle.
7868
+ /// Closing and absent occupancies have no handle.
7703
7869
  pub fn channelHandle(self: *Self, key: u64) ?ChannelHandle {
7704
7870
  for (&self.channel_slots) |*slot| {
7705
7871
  if (slot.state == .open and slot.key == key) {
@@ -7806,6 +7972,80 @@ pub fn Effects(comptime Msg: type) type {
7806
7972
  if (result != .accepted) return error.EffectQueueFull;
7807
7973
  }
7808
7974
 
7975
+ /// Register or replace the app's global shortcut set.
7976
+ pub fn setGlobalShortcuts(self: *Self, options: SetGlobalShortcutsOptions) void {
7977
+ const session = &self.global_shortcuts;
7978
+ if (session.active and session.key != options.key) {
7979
+ self.rejectChannel(options.key, options.on_event, true);
7980
+ return;
7981
+ }
7982
+ if (!session.active) {
7983
+ if (self.keyOccupiedUntilDelivery(options.key)) {
7984
+ self.rejectChannel(options.key, options.on_event, true);
7985
+ return;
7986
+ }
7987
+ _ = self.openChannel(.{ .key = options.key, .on_event = options.on_event });
7988
+ if (self.findChannelSlot(options.key) == null) return;
7989
+ session.* = .{ .active = true, .key = options.key };
7990
+ }
7991
+ const handle = self.channelHandle(options.key) orelse return;
7992
+ if (!handle.live()) return;
7993
+
7994
+ var accepted: [platform.max_global_shortcuts]platform.Shortcut = undefined;
7995
+ var accepted_count: usize = 0;
7996
+ for (options.shortcuts) |shortcut| {
7997
+ if (global_shortcuts_mod.admissible(shortcut, accepted[0..accepted_count])) {
7998
+ accepted[accepted_count] = shortcut;
7999
+ accepted_count += 1;
8000
+ } else {
8001
+ postGlobalShortcutReport(handle, .rejected, shortcut);
8002
+ }
8003
+ }
8004
+
8005
+ var statuses: [platform.max_global_shortcuts]platform.GlobalShortcutStatus = undefined;
8006
+ var unsupported = false;
8007
+ if (self.executor == .fake) {
8008
+ for (accepted[0..accepted_count], 0..) |shortcut, index| {
8009
+ statuses[index] = .registered;
8010
+ for (accepted[0..index]) |earlier| {
8011
+ if (platform.sameShortcutCombination(earlier, shortcut)) statuses[index] = .conflict;
8012
+ }
8013
+ }
8014
+ } else if (self.services) |services| {
8015
+ services.configureGlobalShortcuts(accepted[0..accepted_count], globalShortcutSink(handle), statuses[0..accepted_count]) catch {
8016
+ unsupported = true;
8017
+ };
8018
+ session.platform_configured = session.platform_configured or !unsupported;
8019
+ } else {
8020
+ unsupported = true;
8021
+ }
8022
+
8023
+ var next: [platform.max_global_shortcuts]global_shortcuts_mod.Binding = undefined;
8024
+ for (accepted[0..accepted_count], 0..) |shortcut, index| {
8025
+ const kind: EffectGlobalShortcutEventKind = if (unsupported) .unsupported else switch (statuses[index]) {
8026
+ inline else => |status| @field(EffectGlobalShortcutEventKind, @tagName(status)),
8027
+ };
8028
+ const unchanged = if (session.find(shortcut.id)) |previous| previous.shortcut.matches(shortcut) and previous.kind == .registered else false;
8029
+ if (!unchanged or kind != .registered) postGlobalShortcutReport(handle, kind, shortcut);
8030
+ next[index] = .{ .shortcut = .init(shortcut), .kind = kind };
8031
+ }
8032
+ @memcpy(session.bindings[0..accepted_count], next[0..accepted_count]);
8033
+ session.count = accepted_count;
8034
+ }
8035
+
8036
+ /// Unregister the set; reports end with `stopped`.
8037
+ pub fn clearGlobalShortcuts(self: *Self, key: u64) void {
8038
+ if (!self.global_shortcuts.active or self.global_shortcuts.key != key) return;
8039
+ self.closeChannel(key);
8040
+ }
8041
+
8042
+ fn releaseGlobalShortcuts(self: *Self) void {
8043
+ if (self.global_shortcuts.platform_configured) {
8044
+ if (self.services) |services| services.configureGlobalShortcuts(&.{}, globalShortcutSink(self.channelHandle(self.global_shortcuts.key) orelse .{}), &.{}) catch {};
8045
+ }
8046
+ self.global_shortcuts = .{};
8047
+ }
8048
+
7809
8049
  /// Close the open channel with `key`: posts stop landing
7810
8050
  /// immediately (the handle answers `.closed`), the staged
7811
8051
  /// backlog flushes in post order, and exactly one terminal
@@ -7815,6 +8055,7 @@ pub fn Effects(comptime Msg: type) type {
7815
8055
  /// is NOT a channel's close (channels end the way audio does:
7816
8056
  /// through their own verb).
7817
8057
  pub fn closeChannel(self: *Self, key: u64) void {
8058
+ if (self.global_shortcuts.active and self.global_shortcuts.key == key) self.releaseGlobalShortcuts();
7818
8059
  if (self.findAudioCaptureByKey(key)) |capture| {
7819
8060
  if (capture.platform_started) {
7820
8061
  if (self.services) |services| services.audioCaptureStop(capture.source) catch {};
@@ -8592,7 +8833,7 @@ pub fn Effects(comptime Msg: type) type {
8592
8833
  /// user-visible side effect.
8593
8834
  pub fn showNotification(self: *Self, options: platform.NotificationOptions) void {
8594
8835
  if (self.executor == .fake or self.replay) return;
8595
- validation.validateNotificationOptions(options) catch return;
8836
+ @import("system_admission_policy.zig").notification(self.system_admission_policy, options) catch return;
8596
8837
  const services = self.services orelse return;
8597
8838
  services.showNotification(options) catch {};
8598
8839
  }
@@ -9346,6 +9587,40 @@ pub fn Effects(comptime Msg: type) type {
9346
9587
  self.startHostRequest(options, max_effect_host_payload_bytes, max_effect_host_result_bytes, null, null, null);
9347
9588
  }
9348
9589
 
9590
+ pub const KeyChordOptions = struct {
9591
+ key: u64,
9592
+ chord: platform.KeyChord,
9593
+ on_result: ?HostMsgFn = null,
9594
+ };
9595
+
9596
+ pub const KeyboardAccessOptions = struct {
9597
+ key: u64,
9598
+ prompt: bool = false,
9599
+ on_result: ?HostMsgFn = null,
9600
+ };
9601
+
9602
+ /// Post a key chord to the focused app; requires the `keyboard_input` permission.
9603
+ pub fn sendKeyChord(self: *Self, options: KeyChordOptions) void {
9604
+ var payload: [keyboard_input.max_chord_payload_bytes]u8 = undefined;
9605
+ self.hostRequest(.{
9606
+ .key = options.key,
9607
+ .name = keyboard_input.send_chord_name,
9608
+ .payload = keyboard_input.encodeChord(&payload, options.chord),
9609
+ .on_result = options.on_result,
9610
+ });
9611
+ }
9612
+
9613
+ /// Ask for the OS grant; the ok bytes are `granted`, `denied`, or `not_required`.
9614
+ pub fn keyboardAccessStatus(self: *Self, options: KeyboardAccessOptions) void {
9615
+ const payload = [_]u8{@intFromBool(options.prompt)};
9616
+ self.hostRequest(.{
9617
+ .key = options.key,
9618
+ .name = keyboard_input.access_status_name,
9619
+ .payload = &payload,
9620
+ .on_result = options.on_result,
9621
+ });
9622
+ }
9623
+
9349
9624
  fn startHostRequest(
9350
9625
  self: *Self,
9351
9626
  options: HostRequestOptions,
@@ -9470,6 +9745,8 @@ pub fn Effects(comptime Msg: type) type {
9470
9745
  slot.on_file = null;
9471
9746
  slot.on_clipboard = null;
9472
9747
  slot.on_host = options.on_result;
9748
+ slot.desktop_waiting = false;
9749
+ slot.replay_window_reply_len = 0;
9473
9750
  slot.on_credentials = credentials_fn;
9474
9751
  slot.cancel_requested.store(false, .release);
9475
9752
  // `cancelled_generation` stays sticky, exactly as in `spawn`.
@@ -9494,7 +9771,10 @@ pub fn Effects(comptime Msg: type) type {
9494
9771
 
9495
9772
  // Fake mode (tests and session replay) parks here: the feed
9496
9773
  // is the only terminal source.
9497
- if (fake) return;
9774
+ if (fake) {
9775
+ slot.desktop_waiting = self.defer_desktop_capabilities and @import("desktop_files.zig").isName(slot.hostName());
9776
+ return;
9777
+ }
9498
9778
  if (store_op) |operation| {
9499
9779
  if (operation == .get or operation == .scan) {
9500
9780
  self.performBoundStoreRequest(slot.hostName(), options.key, slot.fetchPayload());
@@ -9508,6 +9788,10 @@ pub fn Effects(comptime Msg: type) type {
9508
9788
  return;
9509
9789
  }
9510
9790
  if (native_request) {
9791
+ if (self.defer_desktop_capabilities and @import("desktop_files.zig").isName(slot.hostName())) {
9792
+ slot.desktop_waiting = true;
9793
+ return;
9794
+ }
9511
9795
  self.performNativeHostRequest(slot.hostName(), options.key, slot.fetchPayload());
9512
9796
  return;
9513
9797
  }
@@ -9516,27 +9800,163 @@ pub fn Effects(comptime Msg: type) type {
9516
9800
  }
9517
9801
 
9518
9802
  fn isNativeHostRequestName(name: []const u8) bool {
9519
- return std.mem.startsWith(u8, name, "core.store.") or
9803
+ return @import("desktop_files.zig").isName(name) or std.mem.startsWith(u8, name, "core.store.") or
9520
9804
  std.mem.eql(u8, name, "native-sdk.launch-at-login.status") or
9521
9805
  std.mem.eql(u8, name, "native-sdk.launch-at-login.set") or
9522
- std.mem.eql(u8, name, "native-sdk.time.formatLocal");
9806
+ std.mem.eql(u8, name, "native-sdk.time.formatLocal") or
9807
+ keyboard_input.isRequestName(name);
9523
9808
  }
9524
9809
 
9525
9810
  fn isNativeHostSendName(name: []const u8) bool {
9526
9811
  return std.mem.eql(u8, name, "native-sdk.os.openUrl") or
9812
+ std.mem.eql(u8, name, "native-sdk.debug.log") or
9527
9813
  std.mem.eql(u8, name, "native-sdk.os.revealPath");
9528
9814
  }
9529
9815
 
9530
9816
  fn performNativeHostSend(self: *Self, name: []const u8, payload: []const u8) void {
9817
+ if (std.mem.eql(u8, name, "native-sdk.debug.log")) {
9818
+ if (payload.len <= 4096) std.debug.print("{s}", .{payload});
9819
+ return;
9820
+ }
9531
9821
  const binding = self.system_services orelse return;
9532
9822
  if (std.mem.eql(u8, name, "native-sdk.os.openUrl")) {
9533
- binding.open_external_url_fn(binding.context, payload) catch {};
9823
+ binding.open_external_url_fn(binding.context, payload) catch |err| {
9824
+ if (err == error.NavigationDenied) {
9825
+ std.debug.print("native warning: external URL denied by security.navigation.external_links\n", .{});
9826
+ } else {
9827
+ std.debug.print("native warning: external URL open failed: {s}\n", .{@errorName(err)});
9828
+ }
9829
+ };
9534
9830
  } else {
9535
9831
  binding.reveal_path_fn(binding.context, payload) catch {};
9536
9832
  }
9537
9833
  }
9538
9834
 
9835
+ /// Execute a captured batch in issue order after the view transaction.
9836
+ /// Slots own copied payloads; cancellation and replacement invalidate
9837
+ /// captured generations. Calls queued by a nested native event belong
9838
+ /// to the next batch, and fake/replay executors never reach the OS.
9839
+ pub fn flushDesktopCapabilities(self: *Self) void {
9840
+ if (self.executor == .fake) {
9841
+ if (self.replay) self.flushReplayWindowExecutions();
9842
+ return;
9843
+ }
9844
+ if (self.flushing_desktop_capabilities) return;
9845
+ self.flushing_desktop_capabilities = true;
9846
+ defer self.flushing_desktop_capabilities = false;
9847
+ const Pending = struct { index: usize, generation: u32 };
9848
+ var pending: [total_effect_slots]Pending = undefined;
9849
+ var count: usize = 0;
9850
+ const boundary = self.next_generation;
9851
+ for (&self.slots, 0..) |*slot, index| {
9852
+ if (slot.kind != .host or slot.fake or !slot.desktop_waiting or slot.state.load(.acquire) != .running) continue;
9853
+ var at = count;
9854
+ while (at > 0 and boundary -% pending[at - 1].generation < boundary -% slot.generation) : (at -= 1) {
9855
+ pending[at] = pending[at - 1];
9856
+ }
9857
+ pending[at] = .{ .index = index, .generation = slot.generation };
9858
+ count += 1;
9859
+ }
9860
+ for (pending[0..count]) |entry| {
9861
+ const slot = &self.slots[entry.index];
9862
+ if (slot.generation != entry.generation or slot.kind != .host or slot.fake or !slot.desktop_waiting or slot.state.load(.acquire) != .running) continue;
9863
+ slot.desktop_waiting = false;
9864
+ self.performDesktopCapability(entry.index);
9865
+ }
9866
+ }
9867
+
9868
+ fn feedDesktopResult(self: *Self, index: usize, generation: u32, ok: bool, bytes: []const u8) void {
9869
+ const slot = &self.slots[index];
9870
+ if (slot.kind != .host or slot.generation != generation or slot.state.load(.acquire) != .running) return;
9871
+ self.feedHostResult(slot.key, ok, bytes) catch {};
9872
+ }
9873
+
9874
+ fn performDesktopCapability(self: *Self, index: usize) void {
9875
+ const slot = &self.slots[index];
9876
+ const generation = slot.generation;
9877
+ const key = slot.key;
9878
+ const binding = self.system_services orelse return self.feedDesktopResult(index, generation, false, "unsupported");
9879
+ const execute = binding.execute_capability_fn orelse return self.feedDesktopResult(index, generation, false, "unsupported");
9880
+ // A modal native call can reenter the event loop and replace or
9881
+ // cancel this slot. Keep its arguments alive independently and
9882
+ // deliver only to the original occupancy when the call returns.
9883
+ var name_storage: [max_effect_host_name_bytes]u8 = undefined;
9884
+ const name = name_storage[0..slot.url_len];
9885
+ @memcpy(name, slot.hostName());
9886
+ const payload = self.allocator.dupe(u8, slot.fetchPayload()) catch return self.feedDesktopResult(index, generation, false, "unsupported");
9887
+ defer self.allocator.free(payload);
9888
+ const output = self.allocator.alloc(u8, max_effect_host_result_bytes) catch return self.feedDesktopResult(index, generation, false, "unsupported");
9889
+ defer self.allocator.free(output);
9890
+ const result = execute(binding.context, name, payload, output) catch |err| {
9891
+ self.feedDesktopResult(index, generation, false, @errorName(err));
9892
+ return;
9893
+ };
9894
+ if (desktopWindowSuccess(name, payload, result)) {
9895
+ self.journalNote(.{ .kind = .window_execution, .key = key, .code = @intFromBool(std.mem.eql(u8, name, "native-sdk.window.closeResult")), .payload = payload, .stderr_tail = result });
9896
+ }
9897
+ self.feedDesktopResult(index, generation, true, result);
9898
+ }
9899
+
9900
+ fn desktopWindowSuccess(name: []const u8, payload: []const u8, reply: []const u8) bool {
9901
+ if (!std.mem.eql(u8, name, "native-sdk.window.focusResult") and !std.mem.eql(u8, name, "native-sdk.window.closeResult")) return false;
9902
+ const desktop = @import("desktop_files.zig");
9903
+ var request = desktop.request(payload) catch return false;
9904
+ var response = desktop.request(reply) catch return false;
9905
+ if (request.at != response.at or !std.mem.eql(u8, payload[0..request.at], reply[0..response.at])) return false;
9906
+ const label = request.field() catch return false;
9907
+ request.finish() catch return false;
9908
+ const failure = response.field() catch return false;
9909
+ response.finish() catch return false;
9910
+ return failure.len == 0 and label.len > 0 and label.len <= 255 and std.mem.indexOfScalar(u8, label, 0) == null;
9911
+ }
9912
+
9913
+ /// Execution facts can precede their triggering event, like clock
9914
+ /// reads. Copy them until that event's settled view transaction claims
9915
+ /// the exact request. Neither native calls nor application Msgs run.
9916
+ pub fn pushReplayWindowExecution(self: *Self, record: EffectResultRecord) !void {
9917
+ const name = if (record.code == 1) "native-sdk.window.closeResult" else "native-sdk.window.focusResult";
9918
+ const canonical: EffectResultRecord = .{ .kind = .window_execution, .key = record.key, .code = record.code, .payload = record.payload, .stderr_tail = record.stderr_tail };
9919
+ if (!self.replay or record.kind != .window_execution or record.code < 0 or record.code > 1 or
9920
+ !std.meta.eql(record, canonical) or
9921
+ record.payload.len > 293 or record.stderr_tail.len > 38 or
9922
+ !desktopWindowSuccess(name, record.payload, record.stderr_tail)) return error.ReplayDamagedRecord;
9923
+ if (self.replay_window_execution_len == self.replay_window_executions.len) return error.ReplayWindowDivergence;
9924
+ const entry = &self.replay_window_executions[self.replay_window_execution_len];
9925
+ entry.key = record.key;
9926
+ entry.closed = record.code == 1;
9927
+ entry.request_len = @intCast(record.payload.len);
9928
+ @memcpy(entry.request[0..record.payload.len], record.payload);
9929
+ entry.reply_len = @intCast(record.stderr_tail.len);
9930
+ @memcpy(entry.reply[0..record.stderr_tail.len], record.stderr_tail);
9931
+ self.replay_window_execution_len += 1;
9932
+ }
9933
+
9934
+ fn flushReplayWindowExecutions(self: *Self) void {
9935
+ while (self.replay_window_execution_len > 0) {
9936
+ const entry = &self.replay_window_executions[0];
9937
+ const index = self.findActiveSlot(entry.key) orelse break;
9938
+ const slot = &self.slots[index];
9939
+ const name = if (entry.closed) "native-sdk.window.closeResult" else "native-sdk.window.focusResult";
9940
+ if (slot.kind != .host or !slot.fake or (self.defer_desktop_capabilities and !slot.desktop_waiting) or slot.state.load(.acquire) != .running or
9941
+ !std.mem.eql(u8, slot.hostName(), name) or !std.mem.eql(u8, slot.fetchPayload(), entry.request[0..entry.request_len])) break;
9942
+ if (slot.replay_window_reply_len != 0) {
9943
+ self.replay_window_diverged = true;
9944
+ break;
9945
+ }
9946
+ slot.desktop_waiting = false;
9947
+ slot.replay_window_reply_len = entry.reply_len;
9948
+ @memcpy(slot.replay_window_reply[0..entry.reply_len], entry.reply[0..entry.reply_len]);
9949
+ self.restoreDesktopWindowResult(slot, entry.reply[0..entry.reply_len]);
9950
+ self.replay_window_execution_len -= 1;
9951
+ std.mem.copyForwards(ReplayWindowExecution, self.replay_window_executions[0..self.replay_window_execution_len], self.replay_window_executions[1 .. self.replay_window_execution_len + 1]);
9952
+ }
9953
+ }
9954
+
9539
9955
  fn performNativeHostRequest(self: *Self, name: []const u8, key: u64, payload: []const u8) void {
9956
+ if (@import("desktop_files.zig").isName(name)) {
9957
+ self.performDesktopCapability(self.findActiveSlot(key) orelse return);
9958
+ return;
9959
+ }
9540
9960
  if (std.mem.startsWith(u8, name, "core.store.")) {
9541
9961
  self.performBoundStoreRequest(name, key, payload);
9542
9962
  return;
@@ -9545,6 +9965,13 @@ pub fn Effects(comptime Msg: type) type {
9545
9965
  self.performBoundSystemRequest(name, key, payload);
9546
9966
  return;
9547
9967
  }
9968
+ if (keyboard_input.isRequestName(name)) {
9969
+ const binding = (self.system_services orelse return self.feedUnsupportedNativeRequest(key)).keyboard_input orelse
9970
+ return self.feedUnsupportedNativeRequest(key);
9971
+ const result = keyboard_input.execute(binding, name, payload);
9972
+ self.feedHostResult(key, result.ok, result.bytes) catch {};
9973
+ return;
9974
+ }
9548
9975
  const services = self.services orelse {
9549
9976
  self.feedHostResult(key, false, "unsupported") catch {};
9550
9977
  return;
@@ -9572,6 +9999,10 @@ pub fn Effects(comptime Msg: type) type {
9572
9999
  self.feedHostResult(key, true, launchAtLoginStatusName(status)) catch {};
9573
10000
  }
9574
10001
 
10002
+ fn feedUnsupportedNativeRequest(self: *Self, key: u64) void {
10003
+ self.feedHostResult(key, false, "unsupported") catch {};
10004
+ }
10005
+
9575
10006
  fn performBoundStoreRequest(self: *Self, name: []const u8, key: u64, payload: []const u8) void {
9576
10007
  const binding = self.record_store_binding orelse {
9577
10008
  self.feedHostResult(key, false, "rejected") catch {};
@@ -10007,6 +10438,25 @@ pub fn Effects(comptime Msg: type) type {
10007
10438
  } });
10008
10439
  }
10009
10440
 
10441
+ /// Cancel only an image load under this exact identity. A rejected
10442
+ /// image request may share a key with another live effect; that
10443
+ /// incumbent belongs to its original caller and must stay intact.
10444
+ pub fn cancelImage(self: *Self, key: u64) void {
10445
+ const index = self.findActiveSlot(key) orelse self.findFinishedSlot(key) orelse return;
10446
+ if (self.slots[index].kind != .image) return;
10447
+ self.cancel(key);
10448
+ }
10449
+
10450
+ /// Named bridge operations use their own keys, but full-width image
10451
+ /// identities may coincide with them. Preserve the image incumbent
10452
+ /// when a rejected named operation is cancelled before delivery.
10453
+ pub fn cancelNonImage(self: *Self, key: u64) void {
10454
+ if (self.findActiveSlot(key) orelse self.findFinishedSlot(key)) |index| {
10455
+ if (self.slots[index].kind == .image) return;
10456
+ }
10457
+ self.cancel(key);
10458
+ }
10459
+
10010
10460
  /// Cancel a running effect by key. After this returns, no
10011
10461
  /// further `on_line` Msgs for that spawn are dispatched; one
10012
10462
  /// `on_exit` Msg with reason `.cancelled` follows once the
@@ -10132,7 +10582,7 @@ pub fn Effects(comptime Msg: type) type {
10132
10582
  /// platform without a timer service delivers exactly one Msg
10133
10583
  /// with outcome `.rejected` on the next drain.
10134
10584
  pub fn startTimer(self: *Self, options: StartTimerOptions) void {
10135
- if (options.interval_ms == 0) return self.rejectTimer(options);
10585
+ if (options.interval_ms == 0 or options.interval_ms > std.math.maxInt(u64) / std.time.ns_per_ms) return self.rejectTimer(options);
10136
10586
  const fake = self.executor == .fake;
10137
10587
  // Services are bound before init_fx/update ever run; a null
10138
10588
  // here means a host without the platform timer arm.
@@ -10208,11 +10658,7 @@ pub fn Effects(comptime Msg: type) type {
10208
10658
  /// is its own namespace (like timer keys) and identifies the
10209
10659
  /// playback in every event; it consumes no `max_effects` slots.
10210
10660
  pub fn playAudio(self: *Self, options: PlayAudioOptions) void {
10211
- const rejected = (options.path.len == 0 and options.url.len == 0) or
10212
- options.path.len > max_effect_audio_path_bytes or
10213
- options.url.len > max_effect_audio_path_bytes or
10214
- options.cache_path.len > max_effect_audio_path_bytes;
10215
- if (rejected) {
10661
+ if (audioPlayRejected(options)) {
10216
10662
  self.deliverLoopAudio(.{ .key = options.key, .kind = .rejected }, options.on_event);
10217
10663
  return;
10218
10664
  }
@@ -10271,6 +10717,15 @@ pub fn Effects(comptime Msg: type) type {
10271
10717
  if (volume != 1.0) services.audioSetVolume(volume) catch {};
10272
10718
  }
10273
10719
 
10720
+ /// The native source admission boundary; rejected loads retain the
10721
+ /// active player and deliver their own deferred result.
10722
+ pub fn audioPlayRejected(options: PlayAudioOptions) bool {
10723
+ return (options.path.len == 0 and options.url.len == 0) or
10724
+ options.path.len > max_effect_audio_path_bytes or
10725
+ options.url.len > max_effect_audio_path_bytes or
10726
+ options.cache_path.len > max_effect_audio_path_bytes;
10727
+ }
10728
+
10274
10729
  /// Pause the current playback in place. Idle channels no-op; no
10275
10730
  /// event echoes — the caller commanded it, so the caller knows.
10276
10731
  pub fn pauseAudio(self: *Self) void {
@@ -10364,12 +10819,19 @@ pub fn Effects(comptime Msg: type) type {
10364
10819
  /// a `close_policy = .hide` hide and also brings back a minimized
10365
10820
  /// or merely backgrounded window. Fire-and-forget, same contract
10366
10821
  /// as `closeWindow`: no event echoes beyond the window's own
10367
- /// frame event, an unknown label is a no-op, and the fake
10368
- /// executor only records the request in the mirror.
10822
+ /// frame event, an unknown label is a no-op, and ordinary fake
10823
+ /// execution only records the request in the mirror. Replay also
10824
+ /// restores the synchronous visibility/focus transition before
10825
+ /// any checkpoint, without entering the native show service.
10369
10826
  pub fn showWindow(self: *Self, window_label: []const u8) void {
10370
10827
  self.window_action_state.show_count += 1;
10371
10828
  self.window_action_state.record(window_label);
10372
- if (self.executor == .fake) return;
10829
+ if (self.executor == .fake) {
10830
+ if (self.replay) if (self.window_actions) |binding| {
10831
+ if (binding.replay_show_fn) |restore| restore(binding.context, window_label);
10832
+ };
10833
+ return;
10834
+ }
10373
10835
  const binding = self.window_actions orelse return;
10374
10836
  _ = binding.show_fn(binding.context, window_label);
10375
10837
  }
@@ -10424,10 +10886,6 @@ pub fn Effects(comptime Msg: type) type {
10424
10886
  /// or has no handler. Loop-thread only; called by
10425
10887
  /// `UiApp.handleEvent` for `.audio` platform events.
10426
10888
  pub fn takeAudioMsg(self: *Self, platform_event: platform.AudioEvent) ?Msg {
10427
- // Under replay the journaled effect records are the ONLY
10428
- // Msg source (fed through `feedAudioEvent`); the replayed
10429
- // platform `.audio` events would double-deliver.
10430
- if (self.replay) return null;
10431
10889
  const kind: EffectAudioEventKind = switch (platform_event.kind) {
10432
10890
  .loaded => .loaded,
10433
10891
  .position => .position,
@@ -10445,6 +10903,21 @@ pub fn Effects(comptime Msg: type) type {
10445
10903
  .buffering = platform_event.buffering,
10446
10904
  .bands = platform_event.bands,
10447
10905
  }) orelse return null;
10906
+ if (self.replay) {
10907
+ // Live reports deliver synchronously. Pair the fed result
10908
+ // with this event now, leaving deferred rejections and other
10909
+ // completions in their original drain order.
10910
+ if (self.takePendingAudioMatching(event.key)) |recorded| {
10911
+ if (!std.meta.eql(recorded, event)) {
10912
+ self.replay_audio_diverged = true;
10913
+ return null;
10914
+ }
10915
+ const event_fn = audio_fn orelse return null;
10916
+ return event_fn(recorded);
10917
+ }
10918
+ if (audio_fn != null) self.replay_audio_diverged = true;
10919
+ return null;
10920
+ }
10448
10921
  const event_fn = audio_fn orelse return null;
10449
10922
  self.journalNote(.{
10450
10923
  .kind = .audio,
@@ -10490,6 +10963,36 @@ pub fn Effects(comptime Msg: type) type {
10490
10963
  };
10491
10964
  }
10492
10965
 
10966
+ /// Queue every field of a recorded delivery, including its owner
10967
+ /// key and spectrum transport flags. Platform audio events pair
10968
+ /// these records synchronously; fake executor feeds still drain.
10969
+ pub fn feedAudioRecord(self: *Self, event: EffectAudio) !void {
10970
+ if (!self.audio.active or self.audio.key != event.key) return error.EffectNotFound;
10971
+ self.deliverPending(.{ .audio = .{ .event = event, .audio_fn = null, .resolve = true } });
10972
+ }
10973
+
10974
+ /// Remove only the first fed audio result for this channel. Shift
10975
+ /// entries and their sequence stamps together so unrelated deferred
10976
+ /// completions retain their exact order, including wrapped rings.
10977
+ fn takePendingAudioMatching(self: *Self, key: u64) ?EffectAudio {
10978
+ for (0..self.pending_exit_len) |offset| {
10979
+ const index = (self.pending_exit_head + offset) % max_effect_pending_exits;
10980
+ const entry = self.pending_exits[index];
10981
+ if (entry != .audio or !entry.audio.resolve or entry.audio.event.key != key) continue;
10982
+ var hole = offset;
10983
+ while (hole + 1 < self.pending_exit_len) : (hole += 1) {
10984
+ const to = (self.pending_exit_head + hole) % max_effect_pending_exits;
10985
+ const from = (self.pending_exit_head + hole + 1) % max_effect_pending_exits;
10986
+ self.pending_exits[to] = self.pending_exits[from];
10987
+ self.pending_exit_seqs[to] = self.pending_exit_seqs[from];
10988
+ }
10989
+ self.pending_exit_len -= 1;
10990
+ if (self.pending_exit_len == 0) self.pending_exit_head = 0;
10991
+ return entry.audio.event;
10992
+ }
10993
+ return null;
10994
+ }
10995
+
10493
10996
  /// Fake executor / replay: feed one audio event as the platform
10494
10997
  /// would deliver it. The event resolves against the live channel
10495
10998
  /// at drain time (key and handler from the channel, mirrors
@@ -10499,9 +11002,8 @@ pub fn Effects(comptime Msg: type) type {
10499
11002
  return self.feedAudioEventBuffering(kind, position_ms, duration_ms, playing, false);
10500
11003
  }
10501
11004
 
10502
- /// `feedAudioEvent` with the stream-stall flag — the shape the
10503
- /// replayer feeds (journal records carry buffering) and stream
10504
- /// suites use; the plain feed keeps local-file tests terse.
11005
+ /// `feedAudioEvent` with the stream-stall flag for fake executor
11006
+ /// stream tests; the plain feed keeps local-file tests terse.
10505
11007
  pub fn feedAudioEventBuffering(self: *Self, kind: EffectAudioEventKind, position_ms: u64, duration_ms: u64, playing: bool, buffering: bool) !void {
10506
11008
  if (!self.audio.active) return error.EffectNotFound;
10507
11009
  self.deliverPending(.{ .audio = .{
@@ -11749,6 +12251,7 @@ pub fn Effects(comptime Msg: type) type {
11749
12251
  if (entry.retire_slot) |slot_index| {
11750
12252
  const parked = &self.channel_slots[slot_index];
11751
12253
  if (parked.state != .idle and parked.generation == entry.retire_generation) {
12254
+ if (self.global_shortcuts.active and self.global_shortcuts.key == parked.key) self.global_shortcuts = .{};
11752
12255
  retireChannelSlot(parked);
11753
12256
  }
11754
12257
  }
@@ -12751,6 +13254,8 @@ pub fn Effects(comptime Msg: type) type {
12751
13254
  if (seen == index) {
12752
13255
  return .{
12753
13256
  .key = slot.key,
13257
+ .generation = slot.generation,
13258
+ .timeout_ms = slot.timeout_ms,
12754
13259
  .method = slot.method,
12755
13260
  .url = slot.fetchUrl(),
12756
13261
  .headers = slot.fetchHeaders(),
@@ -12846,6 +13351,16 @@ pub fn Effects(comptime Msg: type) type {
12846
13351
  /// feed, which must deliver exactly the reason the recorded
12847
13352
  /// session delivered (`.signaled`, `.cancelled`, ...).
12848
13353
  pub fn feedExitReason(self: *Self, key: u64, code: i32, reason: EffectExitReason) error{EffectNotFound}!void {
13354
+ return self.feedExitWithMetadata(key, code, reason, .{});
13355
+ }
13356
+
13357
+ /// Preserve the complete journaled terminal, including loss that
13358
+ /// cannot be inferred from an already-truncated output/tail payload.
13359
+ pub fn feedExitWithMetadata(self: *Self, key: u64, code: i32, reason: EffectExitReason, metadata: struct {
13360
+ output_truncated: bool = false,
13361
+ stderr_truncated: bool = false,
13362
+ dropped_lines: ?u32 = null,
13363
+ }) error{EffectNotFound}!void {
12849
13364
  const slot_index = self.findActiveFakeSlot(key, .spawn) orelse return error.EffectNotFound;
12850
13365
  const slot = &self.slots[slot_index];
12851
13366
  var entry: Entry = .{
@@ -12855,12 +13370,16 @@ pub fn Effects(comptime Msg: type) type {
12855
13370
  .key = slot.key,
12856
13371
  .code = code,
12857
13372
  .reason = reason,
12858
- .dropped_lines = slot.dropped_total,
13373
+ .dropped_lines = metadata.dropped_lines orelse slot.dropped_total,
13374
+ .collect_truncated = metadata.output_truncated,
13375
+ .stderr_truncated = metadata.stderr_truncated,
12859
13376
  .exit_fn = slot.on_exit,
12860
13377
  };
12861
13378
  const exit_fn = slot.on_exit;
12862
13379
  if (slot.output_mode == .collect) {
12863
13380
  stampCollectExit(slot, &entry);
13381
+ entry.collect_truncated = entry.collect_truncated or metadata.output_truncated;
13382
+ entry.stderr_truncated = entry.stderr_truncated or metadata.stderr_truncated;
12864
13383
  slot.state.store(.draining, .release);
12865
13384
  if (!self.enqueue(&entry)) {
12866
13385
  self.releaseSpawnSlot(slot);
@@ -12890,6 +13409,8 @@ pub fn Effects(comptime Msg: type) type {
12890
13409
  .code = code,
12891
13410
  .reason = reason,
12892
13411
  .dropped_lines = entry.dropped_lines,
13412
+ .output_truncated = entry.collect_truncated,
13413
+ .stderr_truncated = entry.stderr_truncated,
12893
13414
  }, exit_fn);
12894
13415
  }
12895
13416
  self.wakeHost();
@@ -12998,9 +13519,10 @@ pub fn Effects(comptime Msg: type) type {
12998
13519
  if (seen == index) {
12999
13520
  return .{
13000
13521
  .key = slot.key,
13522
+ .generation = slot.generation,
13001
13523
  .op = slot.file_op,
13002
13524
  .path = slot.filePath(),
13003
- .bytes = if (slot.file_op == .write) slot.fetchPayload() else "",
13525
+ .bytes = if (slot.file_op == .write or slot.file_op == .append) slot.fetchPayload() else "",
13004
13526
  };
13005
13527
  }
13006
13528
  seen += 1;
@@ -13151,6 +13673,7 @@ pub fn Effects(comptime Msg: type) type {
13151
13673
  if (seen == index) {
13152
13674
  return .{
13153
13675
  .key = slot.key,
13676
+ .generation = slot.generation,
13154
13677
  .op = slot.clipboard_op,
13155
13678
  .text = if (slot.clipboard_op == .write) slot.fetchPayload() else "",
13156
13679
  };
@@ -13382,6 +13905,32 @@ pub fn Effects(comptime Msg: type) type {
13382
13905
  return count;
13383
13906
  }
13384
13907
 
13908
+ /// The index-th parked fake database operation, in slot order. Live
13909
+ /// query facts borrow engine-owned storage until the next operation.
13910
+ pub fn pendingDbAt(self: *Self, index: usize) ?struct {
13911
+ key: u64,
13912
+ generation: u64,
13913
+ kind: DbSlotKind,
13914
+ sql: []const u8,
13915
+ params: []const EffectDbValue,
13916
+ tables: []const []const u8,
13917
+ } {
13918
+ var seen: usize = 0;
13919
+ for (&self.db_slots) |*slot| {
13920
+ if (!slot.active or !slot.fake) continue;
13921
+ if (seen == index) return .{
13922
+ .key = slot.key,
13923
+ .generation = slot.generation,
13924
+ .kind = slot.kind,
13925
+ .sql = if (slot.live) |live| live.sql else "",
13926
+ .params = if (slot.live) |live| live.params else &.{},
13927
+ .tables = if (slot.live) |live| live.tables else &.{},
13928
+ };
13929
+ seen += 1;
13930
+ }
13931
+ return null;
13932
+ }
13933
+
13385
13934
  /// Number of parked (still-active) fake host requests.
13386
13935
  pub fn pendingHostCount(self: *Self) usize {
13387
13936
  var count: usize = 0;
@@ -13419,13 +13968,21 @@ pub fn Effects(comptime Msg: type) type {
13419
13968
  /// whole one); if the completion queue is somehow full, the
13420
13969
  /// terminal still lands through the pending ring as an err —
13421
13970
  /// never a silent ok with lost bytes.
13422
- pub fn feedHostResult(self: *Self, key: u64, ok: bool, bytes: []const u8) error{EffectNotFound}!void {
13971
+ pub fn feedHostResult(self: *Self, key: u64, ok: bool, bytes: []const u8) error{ EffectNotFound, ReplayWindowDivergence }!void {
13423
13972
  const slot_index = blk: {
13424
13973
  const index = self.findActiveSlot(key) orelse return error.EffectNotFound;
13425
13974
  if (self.slots[index].kind != .host and self.slots[index].kind != .store and self.slots[index].kind != .credentials) return error.EffectNotFound;
13426
13975
  break :blk index;
13427
13976
  };
13428
13977
  const slot = &self.slots[slot_index];
13978
+ if (self.replay and desktopWindowSuccess(slot.hostName(), slot.fetchPayload(), bytes)) {
13979
+ // Test-owned replies can arrive after the request's settled
13980
+ // view flush. Their execution fact belongs to this completion
13981
+ // boundary; live facts are normally claimed by the flush.
13982
+ self.flushReplayWindowExecutions();
13983
+ if (!ok or slot.replay_window_reply_len == 0 or !std.mem.eql(u8, bytes, slot.replay_window_reply[0..slot.replay_window_reply_len])) return error.ReplayWindowDivergence;
13984
+ } else if (self.replay and slot.replay_window_reply_len != 0) return error.ReplayWindowDivergence;
13985
+ slot.replay_window_reply_len = 0;
13429
13986
  const buffer = slot.fetch_buffer orelse return error.EffectNotFound;
13430
13987
  const capacity = buffer.len - slot.payload_len;
13431
13988
  var delivered_ok = ok;
@@ -13434,6 +13991,12 @@ pub fn Effects(comptime Msg: type) type {
13434
13991
  delivered_ok = false;
13435
13992
  delivered = "host result over budget";
13436
13993
  }
13994
+ if (slot.fake and !self.replay and delivered_ok) {
13995
+ if (desktopWindowSuccess(slot.hostName(), slot.fetchPayload(), delivered)) {
13996
+ self.journalNote(.{ .kind = .window_execution, .key = key, .code = @intFromBool(std.mem.eql(u8, slot.hostName(), "native-sdk.window.closeResult")), .payload = slot.fetchPayload(), .stderr_tail = delivered });
13997
+ }
13998
+ self.restoreDesktopWindowResult(slot, delivered);
13999
+ }
13437
14000
  @memcpy(buffer[slot.payload_len..][0..delivered.len], delivered);
13438
14001
  slot.body_len = delivered.len;
13439
14002
  var entry: Entry = .{
@@ -13466,6 +14029,23 @@ pub fn Effects(comptime Msg: type) type {
13466
14029
  self.wakeHost();
13467
14030
  }
13468
14031
 
14032
+ fn restoreDesktopWindowResult(self: *Self, slot: *Slot, bytes: []const u8) void {
14033
+ const closed = std.mem.eql(u8, slot.hostName(), "native-sdk.window.closeResult");
14034
+ if (!closed and !std.mem.eql(u8, slot.hostName(), "native-sdk.window.focusResult")) return;
14035
+ const binding = self.system_services orelse return;
14036
+ const restore = binding.replay_window_result_fn orelse return;
14037
+ const desktop = @import("desktop_files.zig");
14038
+ var request = desktop.request(slot.fetchPayload()) catch return;
14039
+ var reply = desktop.request(bytes) catch return;
14040
+ if (request.at != reply.at or !std.mem.eql(u8, request.bytes[0..request.at], bytes[0..reply.at])) return;
14041
+ const label = request.field() catch return;
14042
+ request.finish() catch return;
14043
+ const failure = reply.field() catch return;
14044
+ reply.finish() catch return;
14045
+ if (failure.len != 0 or label.len == 0 or label.len > 255 or std.mem.indexOfScalar(u8, label, 0) != null) return;
14046
+ restore(binding.context, label, closed);
14047
+ }
14048
+
13469
14049
  /// Replay one redacted credential result. A successful get receives a
13470
14050
  /// deterministic same-length placeholder derived from the recorded
13471
14051
  /// digest; no keychain is touched and no live secret is recoverable
@@ -13527,6 +14107,15 @@ pub fn Effects(comptime Msg: type) type {
13527
14107
  return null;
13528
14108
  }
13529
14109
 
14110
+ /// Build a fake timer's platform event without firing it. Harnesses
14111
+ /// that record sessions dispatch this event through Runtime so replay
14112
+ /// can regenerate the timer Msg from the same journaled input.
14113
+ pub fn fakeTimerEvent(self: *Self, key: u64, timestamp_ns: u64) error{EffectNotFound}!platform.TimerEvent {
14114
+ const index = self.findActiveTimerIndex(key) orelse return error.EffectNotFound;
14115
+ if (!self.timer_slots[index].fake) return error.EffectNotFound;
14116
+ return .{ .id = effectTimerPlatformId(index), .timestamp_ns = timestamp_ns };
14117
+ }
14118
+
13530
14119
  /// Fire the fake fx timer with `key` by hand: its `on_fire` Msg
13531
14120
  /// (timestamp 0 — the fake executor has no clock) lands through
13532
14121
  /// the pending ring and drains on the next `.effects_wake`
@@ -13692,6 +14281,20 @@ pub fn Effects(comptime Msg: type) type {
13692
14281
  return null;
13693
14282
  }
13694
14283
 
14284
+ fn postGlobalShortcutReport(handle: ChannelHandle, kind: EffectGlobalShortcutEventKind, shortcut: platform.Shortcut) void {
14285
+ var packet: [global_shortcuts_mod.max_packet_bytes]u8 = undefined;
14286
+ _ = handle.post(global_shortcuts_mod.encodePacket(&packet, kind, shortcut));
14287
+ }
14288
+
14289
+ fn globalShortcutSink(handle: ChannelHandle) platform.GlobalShortcutSink {
14290
+ return .{ .context = handle.shared, .generation = handle.generation, .push_fn = pushGlobalShortcutEvent };
14291
+ }
14292
+
14293
+ fn pushGlobalShortcutEvent(context: ?*anyopaque, generation: u64, event: platform.GlobalShortcutEvent) void {
14294
+ const handle: ChannelHandle = .{ .shared = @ptrCast(@alignCast(context orelse return)), .generation = generation };
14295
+ postGlobalShortcutReport(handle, if (event.phase == .pressed) .pressed else .released, event.shortcut);
14296
+ }
14297
+
13695
14298
  fn pushAudioCaptureEvent(context: ?*anyopaque, generation: u64, event: platform.AudioCaptureEvent) platform.AudioCapturePushResult {
13696
14299
  const shared: *ChannelShared = @ptrCast(@alignCast(context orelse return .closed));
13697
14300
  var packet: [max_effect_channel_bytes]u8 = undefined;
@@ -14453,6 +15056,8 @@ pub fn Effects(comptime Msg: type) type {
14453
15056
  slot.line_buffer = null;
14454
15057
  }
14455
15058
  if (slot.kind == .credentials) slot.credentials_waiting = false;
15059
+ slot.desktop_waiting = false;
15060
+ slot.replay_window_reply_len = 0;
14456
15061
  slot.state.store(.idle, .release);
14457
15062
  }
14458
15063