@native-sdk/cli 0.10.1 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (462) hide show
  1. package/README.md +8 -6
  2. package/bin/native.js +2 -1
  3. package/build/app.zig +320 -60
  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 +1796 -83
  8. package/package.json +19 -14
  9. package/packages/core/compile-surface/core.ts +134 -72
  10. package/packages/core/package-lock.json +75 -357
  11. package/packages/core/package.json +25 -4
  12. package/packages/core/scripts/compiler_command.mjs +17 -12
  13. package/packages/core/scripts/compiler_typecheck.mjs +1 -0
  14. package/packages/core/scripts/gen_declarations.mjs +3 -2
  15. package/packages/core/scripts/gen_service_surface.mjs +22 -10
  16. package/packages/core/scripts/install_scriptc.mjs +182 -0
  17. package/packages/core/scripts/invoke_scriptc.mjs +18 -0
  18. package/packages/core/scripts/merge_static_archives.mjs +6 -1
  19. package/packages/core/scripts/npm_static_spike.mjs +2 -2
  20. package/packages/core/scripts/run_external_core_compiler.mjs +22 -10
  21. package/packages/core/scripts/run_external_service_compiler.mjs +15 -15
  22. package/packages/core/scripts/run_library_compiler.mjs +51 -0
  23. package/packages/core/scripts/run_native_tests.mjs +22 -0
  24. package/packages/core/scripts/scriptc-toolchain.json +101 -0
  25. package/packages/core/scripts/scriptc_toolchain.mjs +121 -0
  26. package/packages/core/scripts/stage_external_core.mjs +57 -1
  27. package/packages/core/scripts/surface_manifest_diff.mjs +19 -12
  28. package/packages/core/sdk/bytes.d.ts +2 -0
  29. package/packages/core/sdk/bytes.ts +86 -0
  30. package/packages/core/sdk/core.d.ts +308 -4
  31. package/packages/core/sdk/core.ts +320 -84
  32. package/packages/core/sdk/events.d.ts +247 -0
  33. package/packages/core/sdk/events.ts +230 -2
  34. package/packages/core/sdk/internal/image_identity.d.ts +7 -0
  35. package/packages/core/sdk/internal/image_identity.ts +71 -0
  36. package/packages/core/sdk/internal/markdown_policy.d.ts +5 -0
  37. package/packages/core/sdk/internal/markdown_policy.ts +878 -0
  38. package/packages/core/sdk/text.d.ts +27 -0
  39. package/packages/core/sdk/text.ts +206 -15
  40. package/packages/core/sdk/theme.d.ts +251 -0
  41. package/packages/core/sdk/theme.ts +267 -0
  42. package/packages/core/src/authorization.ts +137 -0
  43. package/packages/core/src/automation_commands.ts +201 -0
  44. package/packages/core/src/automation_interactions.ts +92 -0
  45. package/packages/core/src/bridge_descriptors.ts +104 -0
  46. package/packages/core/src/builtin_coordination.ts +172 -0
  47. package/packages/core/src/canvas_frame_coordination.ts +81 -0
  48. package/packages/core/src/canvas_presentation_lifecycle.ts +84 -0
  49. package/packages/core/src/canvas_scene_observation.ts +145 -0
  50. package/packages/core/src/chart_content.ts +161 -0
  51. package/packages/core/src/chart_plans.ts +432 -0
  52. package/packages/core/src/checker.ts +166 -19
  53. package/packages/core/src/code_content.ts +580 -0
  54. package/packages/core/src/command_coordination.ts +140 -0
  55. package/packages/core/src/component_composition.ts +94 -0
  56. package/packages/core/src/component_construction.ts +149 -0
  57. package/packages/core/src/contract.ts +25 -7
  58. package/packages/core/src/control_appearance.ts +232 -0
  59. package/packages/core/src/control_commands.ts +115 -0
  60. package/packages/core/src/control_content.ts +105 -0
  61. package/packages/core/src/control_geometry.ts +107 -0
  62. package/packages/core/src/control_payloads.ts +119 -0
  63. package/packages/core/src/control_primitives.ts +134 -0
  64. package/packages/core/src/devhost.ts +82 -7
  65. package/packages/core/src/devhost_journal.mjs +30 -7
  66. package/packages/core/src/effect_plans.ts +71 -0
  67. package/packages/core/src/flow_measurement.ts +121 -0
  68. package/packages/core/src/font_registry.ts +37 -0
  69. package/packages/core/src/glyph_atlas.ts +86 -0
  70. package/packages/core/src/gpu_packet_preparation.ts +130 -0
  71. package/packages/core/src/gpu_planning.ts +123 -0
  72. package/packages/core/src/gpu_presentation.ts +55 -0
  73. package/packages/core/src/host_flow.ts +89 -0
  74. package/packages/core/src/host_input_regions.ts +165 -0
  75. package/packages/core/src/image_registry.ts +66 -0
  76. package/packages/core/src/indicator_plans.ts +132 -0
  77. package/packages/core/src/infer.ts +150 -8
  78. package/packages/core/src/input_composition.ts +116 -0
  79. package/packages/core/src/intrinsic_measure.ts +100 -0
  80. package/packages/core/src/layout_coordination.ts +207 -0
  81. package/packages/core/src/leaf_plans.ts +134 -0
  82. package/packages/core/src/markup_development.ts +160 -0
  83. package/packages/core/src/measurement_coordination.ts +185 -0
  84. package/packages/core/src/modules.ts +1 -1
  85. package/packages/core/src/motion_sampling.ts +100 -0
  86. package/packages/core/src/paragraph_layout.ts +192 -0
  87. package/packages/core/src/portable_sources.json +74 -0
  88. package/packages/core/src/portable_sources.ts +17 -0
  89. package/packages/core/src/registered_font.ts +93 -0
  90. package/packages/core/src/render_animation_lifecycle.ts +128 -0
  91. package/packages/core/src/render_coordination.ts +170 -0
  92. package/packages/core/src/render_resources.ts +234 -0
  93. package/packages/core/src/runtime_policy.ts +3930 -0
  94. package/packages/core/src/scalar_text.ts +84 -0
  95. package/packages/core/src/service_contract.ts +2 -1
  96. package/packages/core/src/session_codecs.ts +309 -0
  97. package/packages/core/src/shell_admission.ts +126 -0
  98. package/packages/core/src/shell_coordination.ts +93 -0
  99. package/packages/core/src/sqlite_cli.ts +11 -0
  100. package/packages/core/src/status_validation.ts +232 -0
  101. package/packages/core/src/stream_policy.ts +63 -0
  102. package/packages/core/src/surface_recipes.ts +136 -0
  103. package/packages/core/src/system_admission.ts +60 -0
  104. package/packages/core/src/terminal_paint.ts +436 -0
  105. package/packages/core/src/text_document_width.ts +81 -0
  106. package/packages/core/src/text_measurement_cache.ts +69 -0
  107. package/packages/core/src/text_query_layout.ts +179 -0
  108. package/packages/core/src/text_run_layout.ts +410 -0
  109. package/packages/core/src/text_span_queries.ts +355 -0
  110. package/packages/core/src/typed_ast.ts +18 -1
  111. package/packages/core/src/types.ts +7 -5
  112. package/packages/core/src/vector_effects.ts +98 -0
  113. package/packages/core/src/vector_raster.ts +243 -0
  114. package/packages/core/src/view_components.ts +2415 -0
  115. package/packages/core/src/view_coordination.ts +198 -0
  116. package/packages/core/src/view_frontend.ts +980 -0
  117. package/packages/core/src/widget_audits.ts +202 -0
  118. package/packages/core/src/widget_changes.ts +258 -0
  119. package/packages/core/src/widget_metrics.ts +139 -0
  120. package/packages/core/src/widget_motion.ts +171 -0
  121. package/packages/core/src/widget_paint.ts +272 -0
  122. package/packages/core/src/widget_paint_walk.ts +203 -0
  123. package/packages/core/src/widget_presentation.ts +141 -0
  124. package/packages/core/src/widget_routing.ts +262 -0
  125. package/packages/core/src/window_lifecycle.ts +92 -0
  126. package/packages/core/testing/index.ts +430 -0
  127. package/schemas/app.schema.json +13 -0
  128. package/skill-data/core/SKILL.md +2 -2
  129. package/skill-data/native-ui/SKILL.md +76 -17
  130. package/skill-data/ts-core/SKILL.md +113 -9
  131. package/skill-data/ts-services/SKILL.md +1 -1
  132. package/skill-data/ts-services/references/service-surface.md +264 -144
  133. package/src/app_runner/root.zig +25 -12
  134. package/src/app_runner/ts_compiled_view.zig +1631 -0
  135. package/src/app_runner/ts_core_main.zig +143 -10
  136. package/src/app_runner/ts_core_mobile.zig +24 -12
  137. package/src/automation/server.zig +1 -3
  138. package/src/automation/snapshot.zig +9 -637
  139. package/src/automation/snapshot_reference.zig +656 -0
  140. package/src/automation/snapshot_serialization.zig +566 -0
  141. package/src/platform/linux/gtk_host.c +36 -24
  142. package/src/platform/linux/gtk_pixels.h +118 -0
  143. package/src/platform/linux/gtk_pixels_test.c +241 -0
  144. package/src/platform/linux/root.zig +2 -0
  145. package/src/platform/macos/appkit_host.m +188 -30
  146. package/src/platform/macos/pointer_motion_test.m +96 -0
  147. package/src/platform/macos/scroll_driver_test.m +105 -0
  148. package/src/platform/macos/spectrum_bins.h +34 -0
  149. package/src/platform/macos/spectrum_bins_test.c +56 -0
  150. package/src/platform/macos/text_keyboard_test.m +80 -0
  151. package/src/platform/macos/widget_focus_test.m +66 -0
  152. package/src/platform/null_platform.zig +26 -2
  153. package/src/platform/null_platform_tests.zig +13 -0
  154. package/src/platform/root.zig +1 -0
  155. package/src/platform/types.zig +13 -0
  156. package/src/platform/windows/root.zig +2 -0
  157. package/src/platform/windows/webview2_host.cpp +7 -2
  158. package/src/primitives/app_manifest/comptime_scene.zig +1 -1
  159. package/src/primitives/app_manifest/root.zig +2 -0
  160. package/src/primitives/app_manifest/tests.zig +4 -1
  161. package/src/primitives/app_manifest/validation.zig +2 -0
  162. package/src/primitives/canvas/a11y_audit.zig +3 -1
  163. package/src/primitives/canvas/canvas_frame_coordination_policy.zig +134 -0
  164. package/src/primitives/canvas/chart_content_policy.zig +75 -0
  165. package/src/primitives/canvas/chart_plan_policy.zig +196 -0
  166. package/src/primitives/canvas/code_content_policy.zig +162 -0
  167. package/src/primitives/canvas/commands.zig +29 -1
  168. package/src/primitives/canvas/component_composition.zig +125 -0
  169. package/src/primitives/canvas/component_composition_policy.zig +44 -0
  170. package/src/primitives/canvas/component_construction_policy.zig +187 -0
  171. package/src/primitives/canvas/container_layout_policy.zig +87 -0
  172. package/src/primitives/canvas/control_appearance_policy.zig +142 -0
  173. package/src/primitives/canvas/control_command_policy.zig +75 -0
  174. package/src/primitives/canvas/control_content_policy.zig +90 -0
  175. package/src/primitives/canvas/control_geometry_policy.zig +165 -0
  176. package/src/primitives/canvas/control_payload_policy.zig +48 -0
  177. package/src/primitives/canvas/control_primitive_policy.zig +129 -0
  178. package/src/primitives/canvas/effect_plan_policy.zig +96 -0
  179. package/src/primitives/canvas/events.zig +1027 -1
  180. package/src/primitives/canvas/flow_measurement_policy.zig +237 -0
  181. package/src/primitives/canvas/frame.zig +92 -23
  182. package/src/primitives/canvas/glyph_atlas_policy.zig +40 -0
  183. package/src/primitives/canvas/gpu.zig +10 -0
  184. package/src/primitives/canvas/gpu_packet_preparation_policy.zig +325 -0
  185. package/src/primitives/canvas/gpu_planning_policy.zig +364 -0
  186. package/src/primitives/canvas/gpu_presentation_policy.zig +74 -0
  187. package/src/primitives/canvas/grid_layout_policy.zig +51 -0
  188. package/src/primitives/canvas/indicator_plan_policy.zig +128 -0
  189. package/src/primitives/canvas/intrinsic_layout_policy.zig +87 -0
  190. package/src/primitives/canvas/intrinsic_measure_policy.zig +128 -0
  191. package/src/primitives/canvas/layout_audit.zig +5 -2
  192. package/src/primitives/canvas/layout_coordination_policy.zig +262 -0
  193. package/src/primitives/canvas/leaf_plan_policy.zig +117 -0
  194. package/src/primitives/canvas/markdown.zig +13 -3
  195. package/src/primitives/canvas/markdown_content_policy.zig +227 -0
  196. package/src/primitives/canvas/markdown_image_binding.zig +81 -0
  197. package/src/primitives/canvas/measurement_coordination_policy.zig +288 -0
  198. package/src/primitives/canvas/numeric_capabilities.zig +14 -0
  199. package/src/primitives/canvas/reference.zig +12 -6
  200. package/src/primitives/canvas/registered_font_policy.zig +152 -0
  201. package/src/primitives/canvas/render.zig +48 -0
  202. package/src/primitives/canvas/render_cache_policy.zig +184 -0
  203. package/src/primitives/canvas/render_coordination_policy.zig +163 -0
  204. package/src/primitives/canvas/render_damage_policy.zig +160 -0
  205. package/src/primitives/canvas/render_effects.zig +14 -0
  206. package/src/primitives/canvas/render_generic_resources.zig +14 -0
  207. package/src/primitives/canvas/render_images.zig +14 -0
  208. package/src/primitives/canvas/render_layers.zig +14 -0
  209. package/src/primitives/canvas/render_override_policy.zig +119 -0
  210. package/src/primitives/canvas/render_paths.zig +14 -0
  211. package/src/primitives/canvas/render_plan_policy.zig +199 -0
  212. package/src/primitives/canvas/render_resource_policy.zig +476 -0
  213. package/src/primitives/canvas/root.zig +100 -0
  214. package/src/primitives/canvas/semantic_tree_policy.zig +158 -0
  215. package/src/primitives/canvas/serialization.zig +8 -1
  216. package/src/primitives/canvas/surface_layout_policy.zig +36 -0
  217. package/src/primitives/canvas/surface_recipe_policy.zig +231 -0
  218. package/src/primitives/canvas/terminal_grid.zig +10 -696
  219. package/src/primitives/canvas/terminal_grid_reference.zig +709 -0
  220. package/src/primitives/canvas/terminal_paint_policy.zig +191 -0
  221. package/src/primitives/canvas/text.zig +1 -0
  222. package/src/primitives/canvas/text_atlas.zig +113 -0
  223. package/src/primitives/canvas/text_cache_policy.zig +94 -0
  224. package/src/primitives/canvas/text_document_policy.zig +120 -0
  225. package/src/primitives/canvas/text_layout.zig +51 -2
  226. package/src/primitives/canvas/text_layout_cache.zig +29 -0
  227. package/src/primitives/canvas/text_layout_hash.zig +1 -0
  228. package/src/primitives/canvas/text_layout_types.zig +3 -0
  229. package/src/primitives/canvas/text_measure_cache.zig +46 -0
  230. package/src/primitives/canvas/text_measurement_policy.zig +124 -0
  231. package/src/primitives/canvas/text_metrics.zig +23 -0
  232. package/src/primitives/canvas/text_query_policy.zig +156 -0
  233. package/src/primitives/canvas/text_run_policy.zig +252 -0
  234. package/src/primitives/canvas/text_scalar_policy.zig +156 -0
  235. package/src/primitives/canvas/text_span_query_policy.zig +232 -0
  236. package/src/primitives/canvas/text_spans.zig +280 -8
  237. package/src/primitives/canvas/text_tests.zig +10 -0
  238. package/src/primitives/canvas/tokens.zig +38 -0
  239. package/src/primitives/canvas/ui.zig +250 -83
  240. package/src/primitives/canvas/ui_markup.zig +139 -33
  241. package/src/primitives/canvas/ui_markup_compiled.zig +319 -59
  242. package/src/primitives/canvas/ui_markup_compiled_tests.zig +225 -0
  243. package/src/primitives/canvas/ui_markup_contract.zig +146 -14
  244. package/src/primitives/canvas/ui_markup_contract_tests.zig +77 -0
  245. package/src/primitives/canvas/ui_markup_reflect.zig +56 -0
  246. package/src/primitives/canvas/ui_markup_tests.zig +116 -0
  247. package/src/primitives/canvas/ui_markup_view.zig +258 -32
  248. package/src/primitives/canvas/ui_markup_view_tests.zig +142 -10
  249. package/src/primitives/canvas/ui_schema.zig +13 -1
  250. package/src/primitives/canvas/ui_schema_tests.zig +11 -7
  251. package/src/primitives/canvas/ui_tests.zig +1 -0
  252. package/src/primitives/canvas/vector.zig +36 -2
  253. package/src/primitives/canvas/vector_effect_policy.zig +236 -0
  254. package/src/primitives/canvas/vector_raster_policy.zig +190 -0
  255. package/src/primitives/canvas/virtual_extent_policy.zig +292 -0
  256. package/src/primitives/canvas/virtual_extents.zig +99 -3
  257. package/src/primitives/canvas/virtual_flow_policy.zig +108 -0
  258. package/src/primitives/canvas/widget_audit_policy.zig +293 -0
  259. package/src/primitives/canvas/widget_change_policy.zig +298 -0
  260. package/src/primitives/canvas/widget_invalidation.zig +113 -2
  261. package/src/primitives/canvas/widget_layout.zig +673 -128
  262. package/src/primitives/canvas/widget_layout_tests.zig +4 -0
  263. package/src/primitives/canvas/widget_metric_policy.zig +126 -0
  264. package/src/primitives/canvas/widget_metrics.zig +45 -6
  265. package/src/primitives/canvas/widget_paint_policy.zig +166 -0
  266. package/src/primitives/canvas/widget_paint_walk_policy.zig +252 -0
  267. package/src/primitives/canvas/widget_presentation_policy.zig +168 -0
  268. package/src/primitives/canvas/widget_render.zig +744 -74
  269. package/src/primitives/canvas/widget_render_controls.zig +1217 -133
  270. package/src/primitives/canvas/widget_render_scroll.zig +11 -3
  271. package/src/primitives/canvas/widget_render_style.zig +94 -0
  272. package/src/primitives/canvas/widget_render_surfaces.zig +61 -50
  273. package/src/primitives/canvas/widget_routing.zig +75 -0
  274. package/src/primitives/canvas/widget_routing_policy.zig +135 -0
  275. package/src/primitives/canvas/widget_runtime.zig +20 -1
  276. package/src/primitives/canvas/widget_semantics.zig +25 -0
  277. package/src/primitives/canvas/widget_text_input.zig +86 -23
  278. package/src/primitives/canvas/widget_text_select.zig +1 -0
  279. package/src/primitives/canvas/widget_tree.zig +8 -1
  280. package/src/primitives/canvas/widgets.zig +42 -12
  281. package/src/primitives/canvas/wrapped_layout_policy.zig +104 -0
  282. package/src/root.zig +21 -0
  283. package/src/runtime/accessibility_policy.zig +122 -0
  284. package/src/runtime/api.zig +28 -0
  285. package/src/runtime/app_dispatch_policy.zig +68 -0
  286. package/src/runtime/authorization_policy.zig +150 -0
  287. package/src/runtime/automation_command_policy.zig +241 -0
  288. package/src/runtime/automation_interaction_policy.zig +107 -0
  289. package/src/runtime/automation_snapshot.zig +52 -22
  290. package/src/runtime/automation_snapshot_reference.zig +290 -0
  291. package/src/runtime/automation_widget_dispatch.zig +267 -355
  292. package/src/runtime/automation_widget_dispatch_reference.zig +900 -0
  293. package/src/runtime/blob_policy.zig +58 -0
  294. package/src/runtime/blob_reference.zig +64 -0
  295. package/src/runtime/bridge_descriptor_policy.zig +206 -0
  296. package/src/runtime/builtin_bridge.zig +180 -44
  297. package/src/runtime/builtin_coordination_policy.zig +121 -0
  298. package/src/runtime/callback_policy_test_reference.zig +97 -0
  299. package/src/runtime/canvas_drag_policy.zig +94 -0
  300. package/src/runtime/canvas_fonts.zig +38 -10
  301. package/src/runtime/canvas_frame.zig +590 -134
  302. package/src/runtime/canvas_frame_helpers.zig +1 -0
  303. package/src/runtime/canvas_hover_policy.zig +131 -0
  304. package/src/runtime/canvas_images.zig +59 -30
  305. package/src/runtime/canvas_keyboard_focus_policy.zig +154 -0
  306. package/src/runtime/canvas_limits.zig +1 -1
  307. package/src/runtime/canvas_presentation_lifecycle_policy.zig +86 -0
  308. package/src/runtime/canvas_scene_observation_policy.zig +181 -0
  309. package/src/runtime/canvas_widget_context_menu.zig +4 -4
  310. package/src/runtime/canvas_widget_display.zig +110 -9
  311. package/src/runtime/canvas_widget_events.zig +718 -328
  312. package/src/runtime/canvas_widget_runtime.zig +437 -81
  313. package/src/runtime/canvas_widget_scroll_drivers.zig +39 -1
  314. package/src/runtime/canvas_widget_scroll_tests.zig +31 -0
  315. package/src/runtime/canvas_widget_state.zig +93 -56
  316. package/src/runtime/channel_sources.zig +80 -0
  317. package/src/runtime/command_policy.zig +161 -0
  318. package/src/runtime/component_policy.zig +83 -0
  319. package/src/runtime/core.zig +156 -6
  320. package/src/runtime/desktop_files.zig +189 -0
  321. package/src/runtime/effects.zig +466 -29
  322. package/src/runtime/effects_tests.zig +28 -0
  323. package/src/runtime/file_policy_test_reference.zig +113 -0
  324. package/src/runtime/flow.zig +418 -341
  325. package/src/runtime/flow_reference.zig +1426 -0
  326. package/src/runtime/font_registry_policy.zig +72 -0
  327. package/src/runtime/frame_profile.zig +24 -33
  328. package/src/runtime/gpu_surface_events.zig +97 -35
  329. package/src/runtime/host_event_pump.zig +303 -0
  330. package/src/runtime/host_event_pump_reference.zig +268 -0
  331. package/src/runtime/host_flow_policy.zig +155 -0
  332. package/src/runtime/host_input_regions_policy.zig +156 -0
  333. package/src/runtime/image_registry_policy.zig +94 -0
  334. package/src/runtime/input_composition_policy.zig +138 -0
  335. package/src/runtime/journal_policy.zig +66 -0
  336. package/src/runtime/journal_reference.zig +53 -0
  337. package/src/runtime/lifecycle_policy_test_reference.zig +97 -0
  338. package/src/runtime/markup_development_policy.zig +91 -0
  339. package/src/runtime/media_surface.zig +40 -1
  340. package/src/runtime/motion_sampling_policy.zig +159 -0
  341. package/src/runtime/recording_policy.zig +42 -0
  342. package/src/runtime/render_animation_policy.zig +206 -0
  343. package/src/runtime/replay_policy.zig +66 -0
  344. package/src/runtime/replay_policy_reference.zig +326 -0
  345. package/src/runtime/replay_progress_policy.zig +64 -0
  346. package/src/runtime/replay_progress_reference.zig +34 -0
  347. package/src/runtime/request_policy_test_reference.zig +188 -0
  348. package/src/runtime/root.zig +13 -0
  349. package/src/runtime/session_blobs.zig +157 -58
  350. package/src/runtime/session_blobs_reference.zig +692 -0
  351. package/src/runtime/session_codec.zig +361 -0
  352. package/src/runtime/session_codec_reference.zig +1027 -0
  353. package/src/runtime/session_journal.zig +246 -983
  354. package/src/runtime/session_record.zig +224 -45
  355. package/src/runtime/session_replay.zig +157 -415
  356. package/src/runtime/session_tests.zig +552 -0
  357. package/src/runtime/shell_admission_policy.zig +225 -0
  358. package/src/runtime/shell_coordination_policy.zig +138 -0
  359. package/src/runtime/shell_layout.zig +126 -1
  360. package/src/runtime/snapshot_policy.zig +60 -0
  361. package/src/runtime/snapshot_reference.zig +64 -0
  362. package/src/runtime/state.zig +16 -0
  363. package/src/runtime/status_validation.zig +190 -0
  364. package/src/runtime/system_admission_policy.zig +140 -0
  365. package/src/runtime/system_services.zig +46 -36
  366. package/src/runtime/tests.zig +1 -0
  367. package/src/runtime/ts_canvas_hooks.zig +261 -0
  368. package/src/runtime/ts_canvas_hooks_tests.zig +279 -0
  369. package/src/runtime/ts_canvas_icons.zig +234 -0
  370. package/src/runtime/ts_core_host.zig +2325 -411
  371. package/src/runtime/ts_core_host_tests.zig +1982 -0
  372. package/src/runtime/ts_test_host.zig +699 -0
  373. package/src/runtime/ts_ui_app.zig +1087 -45
  374. package/src/runtime/ui_app.zig +1117 -629
  375. package/src/runtime/ui_app_provenance.zig +147 -5
  376. package/src/runtime/ui_app_provenance_reference.zig +370 -0
  377. package/src/runtime/ui_app_tests.zig +619 -9
  378. package/src/runtime/ui_app_window_tests.zig +89 -0
  379. package/src/runtime/view.zig +25 -0
  380. package/src/runtime/view_canvas.zig +30 -6
  381. package/src/runtime/view_coordination_policy.zig +147 -0
  382. package/src/runtime/view_widget_control.zig +51 -14
  383. package/src/runtime/view_widget_scroll.zig +16 -5
  384. package/src/runtime/view_widget_text.zig +153 -68
  385. package/src/runtime/view_widget_tree.zig +460 -56
  386. package/src/runtime/webview_view_bridge_tests.zig +2 -0
  387. package/src/runtime/widget_motion_policy.zig +238 -0
  388. package/src/runtime/window_command_bridge_tests.zig +63 -0
  389. package/src/runtime/window_lifecycle_policy.zig +127 -0
  390. package/src/runtime/window_storage.zig +74 -8
  391. package/src/runtime/window_view_runtime.zig +148 -33
  392. package/src/runtime/window_views.zig +163 -10
  393. package/src/tooling/components/identity_tests.zig +62 -36
  394. package/src/tooling/components/stepper.native +24 -0
  395. package/src/tooling/components/stepper.zig +0 -19
  396. package/src/tooling/components/timeline-item.native +22 -0
  397. package/src/tooling/components/timeline.native +5 -3
  398. package/src/tooling/components/timeline_item.zig +0 -32
  399. package/src/tooling/eject_components.zig +76 -8
  400. package/src/tooling/ios.zig +66 -12
  401. package/src/tooling/manifest.zig +35 -0
  402. package/src/tooling/raw_manifest.zig +6 -0
  403. package/src/tooling/templates.zig +15 -3
  404. package/src/tooling/ts_core.zig +13 -3
  405. package/src/tooling/verbs.zig +22 -0
  406. package/tools/corewire/build_profile.mjs +54 -0
  407. package/tools/corewire/contract_intake.ts +303 -0
  408. package/tools/corewire/contract_intake.zig +82 -0
  409. package/tools/corewire/core.test.ts +166 -0
  410. package/tools/corewire/core_abi.zig +51 -0
  411. package/tools/corewire/core_cases.ts +233 -0
  412. package/tools/corewire/core_contract.ts +407 -0
  413. package/tools/corewire/core_emission.ts +136 -0
  414. package/tools/corewire/core_emission.zig +69 -0
  415. package/tools/corewire/core_goldens.json +3110 -0
  416. package/tools/corewire/core_policy.ts +14 -0
  417. package/tools/corewire/core_policy.zig +48 -0
  418. package/tools/corewire/core_projection.ts +360 -0
  419. package/tools/corewire/core_vocabulary.ts +6 -0
  420. package/tools/corewire/emit.zig +19 -1590
  421. package/tools/corewire/emit_facade.ts +714 -0
  422. package/tools/corewire/emit_facade.zig +10 -3752
  423. package/tools/corewire/emit_mirror.ts +290 -0
  424. package/tools/corewire/emit_profile.ts +50 -0
  425. package/tools/corewire/emit_service.ts +331 -0
  426. package/tools/corewire/emit_service.zig +23 -842
  427. package/tools/corewire/entry.test.ts +95 -0
  428. package/tools/corewire/entry_coordination.ts +127 -0
  429. package/tools/corewire/entry_coordination.zig +190 -0
  430. package/tools/corewire/facade_templates.ts +85 -0
  431. package/tools/corewire/filesystem.test.ts +166 -0
  432. package/tools/corewire/filesystem_coordination.ts +213 -0
  433. package/tools/corewire/filesystem_coordination.zig +245 -0
  434. package/tools/corewire/intake.test.ts +35 -0
  435. package/tools/corewire/intake_cases.ts +55 -0
  436. package/tools/corewire/intake_goldens.json +12237 -0
  437. package/tools/corewire/invocation.test.ts +24 -0
  438. package/tools/corewire/invocation.ts +175 -0
  439. package/tools/corewire/invocation.zig +136 -0
  440. package/tools/corewire/invocation_cases.ts +60 -0
  441. package/tools/corewire/invocation_fixture.ts +33 -0
  442. package/tools/corewire/invocation_goldens.json +1143 -0
  443. package/tools/corewire/invocation_tests.zig +111 -0
  444. package/tools/corewire/invocation_usage.ts +2 -0
  445. package/tools/corewire/lossless_projection.ts +96 -0
  446. package/tools/corewire/main.zig +7 -680
  447. package/tools/corewire/main_reference.zig +415 -0
  448. package/tools/corewire/mirror_templates.ts +55 -0
  449. package/tools/corewire/profile.test.ts +248 -0
  450. package/tools/corewire/profile.zig +56 -0
  451. package/tools/corewire/profile_emission.ts +202 -0
  452. package/tools/corewire/profile_library.json +29 -0
  453. package/tools/corewire/profile_tests.zig +136 -0
  454. package/tools/corewire/service.test.ts +75 -0
  455. package/tools/corewire/service_cases.ts +61 -0
  456. package/tools/corewire/service_contract.zig +40 -146
  457. package/tools/corewire/service_goldens.json +650 -0
  458. package/tools/corewire/service_projection.zig +52 -0
  459. package/tools/corewire/service_templates.ts +14 -0
  460. package/tools/corewire/shim_rt.zig +9 -0
  461. package/tools/corewire/sidecar.zig +267 -1438
  462. package/tools/corewire/emit_profile.zig +0 -521
@@ -72,7 +72,6 @@ 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");
@@ -387,6 +386,10 @@ pub const SystemServiceBinding = struct {
387
386
  open_external_url_fn: *const fn (context: *anyopaque, url: []const u8) anyerror!void,
388
387
  reveal_path_fn: *const fn (context: *anyopaque, path: []const u8) anyerror!void,
389
388
  format_local_time_fn: *const fn (context: *anyopaque, timestamp_ms: i64, style: platform.LocalTimeStyle, buffer: []u8) anyerror![]const u8,
389
+ execute_capability_fn: ?*const fn (context: *anyopaque, name: []const u8, payload: []const u8, output: []u8) anyerror![]const u8 = null,
390
+ /// Restore only runtime window bookkeeping from a journaled successful
391
+ /// capability, without invoking native window focus or close services.
392
+ replay_window_result_fn: ?*const fn (context: *anyopaque, label: []const u8, closed: bool) void = null,
390
393
  };
391
394
 
392
395
  /// Type-erased handle to the embedding host's named-command services,
@@ -433,6 +436,21 @@ pub const HostChannelBinding = struct {
433
436
  acquire_fn: *const fn (context: *anyopaque, key: u64) ?ChannelHandle,
434
437
  };
435
438
 
439
+ /// Loop-thread startup only. Implementations copy arguments before returning
440
+ /// and may retain the generation-safe handle; they must not reenter the UI.
441
+ pub const HostChannelSourceBinding = struct {
442
+ context: *anyopaque,
443
+ start_fn: *const fn (context: *anyopaque, name: []const u8, payload: []const u8, handle: ChannelHandle) anyerror!void,
444
+ };
445
+ pub const EffectChannelSourceState = enum(u8) { skipped, started, failed };
446
+ pub const EffectChannelSourceResult = struct {
447
+ key: u64,
448
+ state: EffectChannelSourceState,
449
+ bytes: []const u8 = "",
450
+ };
451
+ pub const max_channel_source_payload = 4096;
452
+ const max_channel_source_request = 1 + max_effect_host_name_bytes + 4 + max_channel_source_payload;
453
+
436
454
  pub const HostCallCompletion = struct {
437
455
  key: u64,
438
456
  ok: bool,
@@ -2030,6 +2048,12 @@ pub const EffectResultKind = enum(u8) {
2030
2048
  /// salted digest and length; replay synthesizes same-length placeholder
2031
2049
  /// bytes and never consults an OS keychain.
2032
2050
  credentials = 18,
2051
+ /// Successful native window bookkeeping, at execution rather than Msg
2052
+ /// delivery. `code` is 0 for focus and 1 for close; the complete copied
2053
+ /// request and correlated reply ride `payload` and `stderr_tail`.
2054
+ window_execution = 19,
2055
+ /// Immediate external producer startup; request rides payload, error rides stderr_tail.
2056
+ channel_source = 20,
2033
2057
  };
2034
2058
 
2035
2059
  /// Journaled wall-clock reads buffered for replay (`Effects.wallMs`).
@@ -3042,6 +3066,8 @@ pub fn Effects(comptime Msg: type) type {
3042
3066
  /// valid until the fetch's response is drained.
3043
3067
  pub const FetchRequest = struct {
3044
3068
  key: u64,
3069
+ generation: u64 = 0,
3070
+ timeout_ms: u32 = 0,
3045
3071
  method: std.http.Method,
3046
3072
  url: []const u8,
3047
3073
  headers: []const std.http.Header,
@@ -3083,9 +3109,10 @@ pub fn Effects(comptime Msg: type) type {
3083
3109
  /// valid until the result is fed and drained.
3084
3110
  pub const FileRequest = struct {
3085
3111
  key: u64,
3112
+ generation: u64 = 0,
3086
3113
  op: EffectFileOp,
3087
3114
  path: []const u8,
3088
- /// The bytes a `writeFile` would write; `""` for reads.
3115
+ /// The bytes a `writeFile` or `appendFile` would write; `""` for reads.
3089
3116
  bytes: []const u8 = "",
3090
3117
  };
3091
3118
 
@@ -3158,6 +3185,7 @@ pub fn Effects(comptime Msg: type) type {
3158
3185
  /// stays valid until the result is fed and drained.
3159
3186
  pub const ClipboardRequest = struct {
3160
3187
  key: u64,
3188
+ generation: u64 = 0,
3161
3189
  op: EffectClipboardOp,
3162
3190
  /// The text a `writeClipboard` would write; `""` for reads.
3163
3191
  text: []const u8 = "",
@@ -4480,6 +4508,24 @@ pub fn Effects(comptime Msg: type) type {
4480
4508
  }
4481
4509
  };
4482
4510
 
4511
+ const ReplayChannelSource = struct {
4512
+ key: u64,
4513
+ state: EffectChannelSourceState,
4514
+ request_len: usize,
4515
+ request: [max_channel_source_request]u8,
4516
+ failure_len: u8,
4517
+ failure: [255]u8,
4518
+ };
4519
+
4520
+ const ReplayWindowExecution = struct {
4521
+ key: u64,
4522
+ closed: bool,
4523
+ request_len: u16,
4524
+ request: [293]u8,
4525
+ reply_len: u8,
4526
+ reply: [38]u8,
4527
+ };
4528
+
4483
4529
  const Slot = struct {
4484
4530
  state: std.atomic.Value(SlotState) = std.atomic.Value(SlotState).init(.idle),
4485
4531
  generation: u32 = 0,
@@ -4596,6 +4642,11 @@ pub fn Effects(comptime Msg: type) type {
4596
4642
  /// credential slots or letting an older set finish last.
4597
4643
  credentials_waiting: bool = false,
4598
4644
  credentials_sequence: u64 = 0,
4645
+ // Desktop calls can enter AppKit or remove runtime views. UiApp
4646
+ // executes them only after its current rebuild has settled.
4647
+ desktop_waiting: bool = false,
4648
+ replay_window_reply_len: u8 = 0,
4649
+ replay_window_reply: [38]u8 = undefined,
4599
4650
  // ---- image-only fields (kind == .image) ----
4600
4651
  on_image: ?ImageMsgFn = null,
4601
4652
  /// The local source path (the URL rides `url_storage`, a
@@ -4864,6 +4915,11 @@ pub fn Effects(comptime Msg: type) type {
4864
4915
  /// requests reject loudly in real mode, and the fake executor
4865
4916
  /// parks requests for `feedHostResult` regardless.
4866
4917
  host_calls: ?HostCallBinding = null,
4918
+ channel_sources: ?HostChannelSourceBinding = null,
4919
+ replay_channel_sources: [64]ReplayChannelSource = undefined,
4920
+ replay_channel_source_len: usize = 0,
4921
+ replay_channel_source_diverged: bool = false,
4922
+ channel_source_reply: [255]u8 = undefined,
4867
4923
  /// Capability-installed record-store service. Store commands are
4868
4924
  /// SDK-reserved routed requests, so their results reuse the request
4869
4925
  /// journal/replay path while the database handle stays host-owned.
@@ -4969,6 +5025,9 @@ pub fn Effects(comptime Msg: type) type {
4969
5025
  fetch_start_rejections: std.atomic.Value(u32) = std.atomic.Value(u32).init(0),
4970
5026
  next_generation: u32 = 1,
4971
5027
  next_credentials_sequence: u64 = 1,
5028
+ defer_desktop_capabilities: bool = false,
5029
+ flushing_desktop_capabilities: bool = false,
5030
+ system_admission_policy: ?*const fn ([]const u8, []u8) usize = null,
4972
5031
  /// The channel family's OWN generation counter — u64 and
4973
5032
  /// monotonic for the process's lifetime, never the shared u32
4974
5033
  /// `next_generation` above: channel handles live on app-owned
@@ -5106,6 +5165,9 @@ pub fn Effects(comptime Msg: type) type {
5106
5165
  /// after (freed when the queue empties, and at `deinit`) — the
5107
5166
  /// pending stages' storage discipline.
5108
5167
  replay_video_sources: [max_effect_replay_video_source_entries]ReplayVideoSource = undefined,
5168
+ replay_window_executions: [64]ReplayWindowExecution = undefined,
5169
+ replay_window_execution_len: usize = 0,
5170
+ replay_window_diverged: bool = false,
5109
5171
  replay_video_source_spill: []ReplayVideoSource = &.{},
5110
5172
  replay_video_source_len: usize = 0,
5111
5173
  /// A journaled cascade resolution paired against a different
@@ -5113,6 +5175,7 @@ pub fn Effects(comptime Msg: type) type {
5113
5175
  /// for `finishReplay`, which turns it into the divergence
5114
5176
  /// refusal the void-returning `loadVideo` cannot raise itself.
5115
5177
  replay_video_diverged: bool = false,
5178
+ replay_audio_diverged: bool = false,
5116
5179
  /// Drain-pass counter (incremented in `drainBoundary`): the
5117
5180
  /// retired-video sweep's clock. Loop-thread only.
5118
5181
  drain_pass_seq: u64 = 0,
@@ -6337,12 +6400,21 @@ pub fn Effects(comptime Msg: type) type {
6337
6400
  }
6338
6401
 
6339
6402
  /// End-of-journal consistency check (the `.finish` replay
6340
- /// control): every journaled video cascade resolution must have
6403
+ /// control): synchronous audio deliveries must match and leave no
6404
+ /// fed results pending; every journaled video cascade resolution must have
6341
6405
  /// been consumed by the load it named, and none may have paired
6342
6406
  /// against a different key. A leftover or mismatched record
6343
6407
  /// means the replayed updates issued different loads than the
6344
6408
  /// recording — divergence, not success.
6345
- pub fn finishReplay(self: *Self) error{ReplayVideoDivergence}!void {
6409
+ pub fn finishReplay(self: *Self) error{ ReplayAudioDivergence, ReplayVideoDivergence, ReplayWindowDivergence, ReplayChannelSourceDivergence }!void {
6410
+ if (self.replay_channel_source_diverged or self.replay_channel_source_len != 0) return error.ReplayChannelSourceDivergence;
6411
+ if (self.replay_window_diverged or self.replay_window_execution_len != 0) return error.ReplayWindowDivergence;
6412
+ for (&self.slots) |*slot| if (slot.replay_window_reply_len != 0) return error.ReplayWindowDivergence;
6413
+ if (self.replay_audio_diverged) return error.ReplayAudioDivergence;
6414
+ for (0..self.pending_exit_len) |offset| {
6415
+ const entry = self.pending_exits[(self.pending_exit_head + offset) % max_effect_pending_exits];
6416
+ if (entry == .audio and entry.audio.resolve) return error.ReplayAudioDivergence;
6417
+ }
6346
6418
  if (self.replay_video_diverged) return error.ReplayVideoDivergence;
6347
6419
  if (self.replay_video_source_len > 0) {
6348
6420
  std.debug.print(
@@ -7695,11 +7767,76 @@ pub fn Effects(comptime Msg: type) type {
7695
7767
  return .{ .shared = shared, .generation = generation };
7696
7768
  }
7697
7769
 
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.
7770
+ /// Capture startup truth before publishing the issuing dispatch. The
7771
+ /// handle must come from this open, never a same-key old occupancy.
7772
+ /// Returned failure bytes are borrowed until the next source start.
7773
+ pub fn startChannelSource(self: *Self, key: u64, handle: ?ChannelHandle, name: []const u8, payload: []const u8) EffectChannelSourceResult {
7774
+ std.debug.assert(name.len > 0 and name.len <= max_effect_host_name_bytes and payload.len <= max_channel_source_payload);
7775
+ var request: [max_channel_source_request]u8 = undefined;
7776
+ request[0] = @intCast(name.len);
7777
+ @memcpy(request[1..][0..name.len], name);
7778
+ std.mem.writeInt(u32, request[1 + name.len ..][0..4], @intCast(payload.len), .little);
7779
+ @memcpy(request[5 + name.len ..][0..payload.len], payload);
7780
+ const encoded = request[0 .. 5 + name.len + payload.len];
7781
+ if (self.replay) {
7782
+ if (self.replay_channel_source_len == 0) {
7783
+ self.replay_channel_source_diverged = true;
7784
+ return .{ .key = key, .state = .failed, .bytes = "replay_diverged" };
7785
+ }
7786
+ const entry = &self.replay_channel_sources[0];
7787
+ if (entry.key != key or !std.mem.eql(u8, encoded, entry.request[0..entry.request_len]) or
7788
+ ((entry.state == .skipped) != (handle == null))) self.replay_channel_source_diverged = true;
7789
+ const state = entry.state;
7790
+ const len = entry.failure_len;
7791
+ @memcpy(self.channel_source_reply[0..len], entry.failure[0..len]);
7792
+ self.replay_channel_source_len -= 1;
7793
+ 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]);
7794
+ return .{ .key = key, .state = state, .bytes = self.channel_source_reply[0..len] };
7795
+ }
7796
+ var result: EffectChannelSourceResult = .{ .key = key, .state = .skipped };
7797
+ if (handle) |live| {
7798
+ if (live.live()) {
7799
+ result.state = .started;
7800
+ const outcome = if (self.channel_sources) |binding|
7801
+ binding.start_fn(binding.context, name, payload, live)
7802
+ else if (self.executor == .fake)
7803
+ error.UnsupportedChannelSource
7804
+ else
7805
+ @import("channel_sources.zig").start(name, payload, live);
7806
+ outcome catch |err| {
7807
+ result.state = .failed;
7808
+ const failure = @errorName(err);
7809
+ result.bytes = failure[0..@min(failure.len, self.channel_source_reply.len)];
7810
+ };
7811
+ }
7812
+ }
7813
+ self.journalNote(.{ .kind = .channel_source, .key = key, .code = @intFromEnum(result.state), .payload = encoded, .stderr_tail = result.bytes });
7814
+ return result;
7815
+ }
7816
+
7817
+ pub fn pushReplayChannelSource(self: *Self, record: EffectResultRecord) !void {
7818
+ const canonical: EffectResultRecord = .{ .kind = .channel_source, .key = record.key, .code = record.code, .payload = record.payload, .stderr_tail = record.stderr_tail };
7819
+ if (!self.replay or record.kind != .channel_source or record.code < 0 or record.code > 2 or
7820
+ !std.meta.eql(record, canonical) or record.payload.len < 6 or record.payload.len > max_channel_source_request or
7821
+ record.stderr_tail.len > 255 or (record.code == 2) != (record.stderr_tail.len != 0)) return error.ReplayDamagedRecord;
7822
+ const name_len: usize = record.payload[0];
7823
+ if (name_len == 0 or record.payload.len < 5 + name_len or
7824
+ !std.unicode.utf8ValidateSlice(record.payload[1..][0..name_len]) or
7825
+ std.mem.readInt(u32, record.payload[1 + name_len ..][0..4], .little) != record.payload.len - 5 - name_len or
7826
+ record.payload.len - 5 - name_len > max_channel_source_payload) return error.ReplayDamagedRecord;
7827
+ if (self.replay_channel_source_len == self.replay_channel_sources.len) return error.ReplayChannelSourceDivergence;
7828
+ const entry = &self.replay_channel_sources[self.replay_channel_source_len];
7829
+ entry.key = record.key;
7830
+ entry.state = @enumFromInt(record.code);
7831
+ entry.request_len = record.payload.len;
7832
+ @memcpy(entry.request[0..record.payload.len], record.payload);
7833
+ entry.failure_len = @intCast(record.stderr_tail.len);
7834
+ @memcpy(entry.failure[0..record.stderr_tail.len], record.stderr_tail);
7835
+ self.replay_channel_source_len += 1;
7836
+ }
7837
+
7838
+ /// Resolve the open occupancy's generation-safe posting handle.
7839
+ /// Closing and absent occupancies have no handle.
7703
7840
  pub fn channelHandle(self: *Self, key: u64) ?ChannelHandle {
7704
7841
  for (&self.channel_slots) |*slot| {
7705
7842
  if (slot.state == .open and slot.key == key) {
@@ -8592,7 +8729,7 @@ pub fn Effects(comptime Msg: type) type {
8592
8729
  /// user-visible side effect.
8593
8730
  pub fn showNotification(self: *Self, options: platform.NotificationOptions) void {
8594
8731
  if (self.executor == .fake or self.replay) return;
8595
- validation.validateNotificationOptions(options) catch return;
8732
+ @import("system_admission_policy.zig").notification(self.system_admission_policy, options) catch return;
8596
8733
  const services = self.services orelse return;
8597
8734
  services.showNotification(options) catch {};
8598
8735
  }
@@ -9470,6 +9607,8 @@ pub fn Effects(comptime Msg: type) type {
9470
9607
  slot.on_file = null;
9471
9608
  slot.on_clipboard = null;
9472
9609
  slot.on_host = options.on_result;
9610
+ slot.desktop_waiting = false;
9611
+ slot.replay_window_reply_len = 0;
9473
9612
  slot.on_credentials = credentials_fn;
9474
9613
  slot.cancel_requested.store(false, .release);
9475
9614
  // `cancelled_generation` stays sticky, exactly as in `spawn`.
@@ -9494,7 +9633,10 @@ pub fn Effects(comptime Msg: type) type {
9494
9633
 
9495
9634
  // Fake mode (tests and session replay) parks here: the feed
9496
9635
  // is the only terminal source.
9497
- if (fake) return;
9636
+ if (fake) {
9637
+ slot.desktop_waiting = self.defer_desktop_capabilities and @import("desktop_files.zig").isName(slot.hostName());
9638
+ return;
9639
+ }
9498
9640
  if (store_op) |operation| {
9499
9641
  if (operation == .get or operation == .scan) {
9500
9642
  self.performBoundStoreRequest(slot.hostName(), options.key, slot.fetchPayload());
@@ -9508,6 +9650,10 @@ pub fn Effects(comptime Msg: type) type {
9508
9650
  return;
9509
9651
  }
9510
9652
  if (native_request) {
9653
+ if (self.defer_desktop_capabilities and @import("desktop_files.zig").isName(slot.hostName())) {
9654
+ slot.desktop_waiting = true;
9655
+ return;
9656
+ }
9511
9657
  self.performNativeHostRequest(slot.hostName(), options.key, slot.fetchPayload());
9512
9658
  return;
9513
9659
  }
@@ -9516,7 +9662,7 @@ pub fn Effects(comptime Msg: type) type {
9516
9662
  }
9517
9663
 
9518
9664
  fn isNativeHostRequestName(name: []const u8) bool {
9519
- return std.mem.startsWith(u8, name, "core.store.") or
9665
+ return @import("desktop_files.zig").isName(name) or std.mem.startsWith(u8, name, "core.store.") or
9520
9666
  std.mem.eql(u8, name, "native-sdk.launch-at-login.status") or
9521
9667
  std.mem.eql(u8, name, "native-sdk.launch-at-login.set") or
9522
9668
  std.mem.eql(u8, name, "native-sdk.time.formatLocal");
@@ -9524,19 +9670,154 @@ pub fn Effects(comptime Msg: type) type {
9524
9670
 
9525
9671
  fn isNativeHostSendName(name: []const u8) bool {
9526
9672
  return std.mem.eql(u8, name, "native-sdk.os.openUrl") or
9673
+ std.mem.eql(u8, name, "native-sdk.debug.log") or
9527
9674
  std.mem.eql(u8, name, "native-sdk.os.revealPath");
9528
9675
  }
9529
9676
 
9530
9677
  fn performNativeHostSend(self: *Self, name: []const u8, payload: []const u8) void {
9678
+ if (std.mem.eql(u8, name, "native-sdk.debug.log")) {
9679
+ if (payload.len <= 4096) std.debug.print("{s}", .{payload});
9680
+ return;
9681
+ }
9531
9682
  const binding = self.system_services orelse return;
9532
9683
  if (std.mem.eql(u8, name, "native-sdk.os.openUrl")) {
9533
- binding.open_external_url_fn(binding.context, payload) catch {};
9684
+ binding.open_external_url_fn(binding.context, payload) catch |err| {
9685
+ if (err == error.NavigationDenied) {
9686
+ std.debug.print("native warning: external URL denied by security.navigation.external_links\n", .{});
9687
+ } else {
9688
+ std.debug.print("native warning: external URL open failed: {s}\n", .{@errorName(err)});
9689
+ }
9690
+ };
9534
9691
  } else {
9535
9692
  binding.reveal_path_fn(binding.context, payload) catch {};
9536
9693
  }
9537
9694
  }
9538
9695
 
9696
+ /// Execute a captured batch in issue order after the view transaction.
9697
+ /// Slots own copied payloads; cancellation and replacement invalidate
9698
+ /// captured generations. Calls queued by a nested native event belong
9699
+ /// to the next batch, and fake/replay executors never reach the OS.
9700
+ pub fn flushDesktopCapabilities(self: *Self) void {
9701
+ if (self.executor == .fake) {
9702
+ if (self.replay) self.flushReplayWindowExecutions();
9703
+ return;
9704
+ }
9705
+ if (self.flushing_desktop_capabilities) return;
9706
+ self.flushing_desktop_capabilities = true;
9707
+ defer self.flushing_desktop_capabilities = false;
9708
+ const Pending = struct { index: usize, generation: u32 };
9709
+ var pending: [total_effect_slots]Pending = undefined;
9710
+ var count: usize = 0;
9711
+ const boundary = self.next_generation;
9712
+ for (&self.slots, 0..) |*slot, index| {
9713
+ if (slot.kind != .host or slot.fake or !slot.desktop_waiting or slot.state.load(.acquire) != .running) continue;
9714
+ var at = count;
9715
+ while (at > 0 and boundary -% pending[at - 1].generation < boundary -% slot.generation) : (at -= 1) {
9716
+ pending[at] = pending[at - 1];
9717
+ }
9718
+ pending[at] = .{ .index = index, .generation = slot.generation };
9719
+ count += 1;
9720
+ }
9721
+ for (pending[0..count]) |entry| {
9722
+ const slot = &self.slots[entry.index];
9723
+ if (slot.generation != entry.generation or slot.kind != .host or slot.fake or !slot.desktop_waiting or slot.state.load(.acquire) != .running) continue;
9724
+ slot.desktop_waiting = false;
9725
+ self.performDesktopCapability(entry.index);
9726
+ }
9727
+ }
9728
+
9729
+ fn feedDesktopResult(self: *Self, index: usize, generation: u32, ok: bool, bytes: []const u8) void {
9730
+ const slot = &self.slots[index];
9731
+ if (slot.kind != .host or slot.generation != generation or slot.state.load(.acquire) != .running) return;
9732
+ self.feedHostResult(slot.key, ok, bytes) catch {};
9733
+ }
9734
+
9735
+ fn performDesktopCapability(self: *Self, index: usize) void {
9736
+ const slot = &self.slots[index];
9737
+ const generation = slot.generation;
9738
+ const key = slot.key;
9739
+ const binding = self.system_services orelse return self.feedDesktopResult(index, generation, false, "unsupported");
9740
+ const execute = binding.execute_capability_fn orelse return self.feedDesktopResult(index, generation, false, "unsupported");
9741
+ // A modal native call can reenter the event loop and replace or
9742
+ // cancel this slot. Keep its arguments alive independently and
9743
+ // deliver only to the original occupancy when the call returns.
9744
+ var name_storage: [max_effect_host_name_bytes]u8 = undefined;
9745
+ const name = name_storage[0..slot.url_len];
9746
+ @memcpy(name, slot.hostName());
9747
+ const payload = self.allocator.dupe(u8, slot.fetchPayload()) catch return self.feedDesktopResult(index, generation, false, "unsupported");
9748
+ defer self.allocator.free(payload);
9749
+ const output = self.allocator.alloc(u8, max_effect_host_result_bytes) catch return self.feedDesktopResult(index, generation, false, "unsupported");
9750
+ defer self.allocator.free(output);
9751
+ const result = execute(binding.context, name, payload, output) catch |err| {
9752
+ self.feedDesktopResult(index, generation, false, @errorName(err));
9753
+ return;
9754
+ };
9755
+ if (desktopWindowSuccess(name, payload, result)) {
9756
+ self.journalNote(.{ .kind = .window_execution, .key = key, .code = @intFromBool(std.mem.eql(u8, name, "native-sdk.window.closeResult")), .payload = payload, .stderr_tail = result });
9757
+ }
9758
+ self.feedDesktopResult(index, generation, true, result);
9759
+ }
9760
+
9761
+ fn desktopWindowSuccess(name: []const u8, payload: []const u8, reply: []const u8) bool {
9762
+ if (!std.mem.eql(u8, name, "native-sdk.window.focusResult") and !std.mem.eql(u8, name, "native-sdk.window.closeResult")) return false;
9763
+ const desktop = @import("desktop_files.zig");
9764
+ var request = desktop.request(payload) catch return false;
9765
+ var response = desktop.request(reply) catch return false;
9766
+ if (request.at != response.at or !std.mem.eql(u8, payload[0..request.at], reply[0..response.at])) return false;
9767
+ const label = request.field() catch return false;
9768
+ request.finish() catch return false;
9769
+ const failure = response.field() catch return false;
9770
+ response.finish() catch return false;
9771
+ return failure.len == 0 and label.len > 0 and label.len <= 255 and std.mem.indexOfScalar(u8, label, 0) == null;
9772
+ }
9773
+
9774
+ /// Execution facts can precede their triggering event, like clock
9775
+ /// reads. Copy them until that event's settled view transaction claims
9776
+ /// the exact request. Neither native calls nor application Msgs run.
9777
+ pub fn pushReplayWindowExecution(self: *Self, record: EffectResultRecord) !void {
9778
+ const name = if (record.code == 1) "native-sdk.window.closeResult" else "native-sdk.window.focusResult";
9779
+ const canonical: EffectResultRecord = .{ .kind = .window_execution, .key = record.key, .code = record.code, .payload = record.payload, .stderr_tail = record.stderr_tail };
9780
+ if (!self.replay or record.kind != .window_execution or record.code < 0 or record.code > 1 or
9781
+ !std.meta.eql(record, canonical) or
9782
+ record.payload.len > 293 or record.stderr_tail.len > 38 or
9783
+ !desktopWindowSuccess(name, record.payload, record.stderr_tail)) return error.ReplayDamagedRecord;
9784
+ if (self.replay_window_execution_len == self.replay_window_executions.len) return error.ReplayWindowDivergence;
9785
+ const entry = &self.replay_window_executions[self.replay_window_execution_len];
9786
+ entry.key = record.key;
9787
+ entry.closed = record.code == 1;
9788
+ entry.request_len = @intCast(record.payload.len);
9789
+ @memcpy(entry.request[0..record.payload.len], record.payload);
9790
+ entry.reply_len = @intCast(record.stderr_tail.len);
9791
+ @memcpy(entry.reply[0..record.stderr_tail.len], record.stderr_tail);
9792
+ self.replay_window_execution_len += 1;
9793
+ }
9794
+
9795
+ fn flushReplayWindowExecutions(self: *Self) void {
9796
+ while (self.replay_window_execution_len > 0) {
9797
+ const entry = &self.replay_window_executions[0];
9798
+ const index = self.findActiveSlot(entry.key) orelse break;
9799
+ const slot = &self.slots[index];
9800
+ const name = if (entry.closed) "native-sdk.window.closeResult" else "native-sdk.window.focusResult";
9801
+ if (slot.kind != .host or !slot.fake or (self.defer_desktop_capabilities and !slot.desktop_waiting) or slot.state.load(.acquire) != .running or
9802
+ !std.mem.eql(u8, slot.hostName(), name) or !std.mem.eql(u8, slot.fetchPayload(), entry.request[0..entry.request_len])) break;
9803
+ if (slot.replay_window_reply_len != 0) {
9804
+ self.replay_window_diverged = true;
9805
+ break;
9806
+ }
9807
+ slot.desktop_waiting = false;
9808
+ slot.replay_window_reply_len = entry.reply_len;
9809
+ @memcpy(slot.replay_window_reply[0..entry.reply_len], entry.reply[0..entry.reply_len]);
9810
+ self.restoreDesktopWindowResult(slot, entry.reply[0..entry.reply_len]);
9811
+ self.replay_window_execution_len -= 1;
9812
+ 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]);
9813
+ }
9814
+ }
9815
+
9539
9816
  fn performNativeHostRequest(self: *Self, name: []const u8, key: u64, payload: []const u8) void {
9817
+ if (@import("desktop_files.zig").isName(name)) {
9818
+ self.performDesktopCapability(self.findActiveSlot(key) orelse return);
9819
+ return;
9820
+ }
9540
9821
  if (std.mem.startsWith(u8, name, "core.store.")) {
9541
9822
  self.performBoundStoreRequest(name, key, payload);
9542
9823
  return;
@@ -9572,6 +9853,10 @@ pub fn Effects(comptime Msg: type) type {
9572
9853
  self.feedHostResult(key, true, launchAtLoginStatusName(status)) catch {};
9573
9854
  }
9574
9855
 
9856
+ fn feedUnsupportedNativeRequest(self: *Self, key: u64) void {
9857
+ self.feedHostResult(key, false, "unsupported") catch {};
9858
+ }
9859
+
9575
9860
  fn performBoundStoreRequest(self: *Self, name: []const u8, key: u64, payload: []const u8) void {
9576
9861
  const binding = self.record_store_binding orelse {
9577
9862
  self.feedHostResult(key, false, "rejected") catch {};
@@ -10007,6 +10292,25 @@ pub fn Effects(comptime Msg: type) type {
10007
10292
  } });
10008
10293
  }
10009
10294
 
10295
+ /// Cancel only an image load under this exact identity. A rejected
10296
+ /// image request may share a key with another live effect; that
10297
+ /// incumbent belongs to its original caller and must stay intact.
10298
+ pub fn cancelImage(self: *Self, key: u64) void {
10299
+ const index = self.findActiveSlot(key) orelse self.findFinishedSlot(key) orelse return;
10300
+ if (self.slots[index].kind != .image) return;
10301
+ self.cancel(key);
10302
+ }
10303
+
10304
+ /// Named bridge operations use their own keys, but full-width image
10305
+ /// identities may coincide with them. Preserve the image incumbent
10306
+ /// when a rejected named operation is cancelled before delivery.
10307
+ pub fn cancelNonImage(self: *Self, key: u64) void {
10308
+ if (self.findActiveSlot(key) orelse self.findFinishedSlot(key)) |index| {
10309
+ if (self.slots[index].kind == .image) return;
10310
+ }
10311
+ self.cancel(key);
10312
+ }
10313
+
10010
10314
  /// Cancel a running effect by key. After this returns, no
10011
10315
  /// further `on_line` Msgs for that spawn are dispatched; one
10012
10316
  /// `on_exit` Msg with reason `.cancelled` follows once the
@@ -10132,7 +10436,7 @@ pub fn Effects(comptime Msg: type) type {
10132
10436
  /// platform without a timer service delivers exactly one Msg
10133
10437
  /// with outcome `.rejected` on the next drain.
10134
10438
  pub fn startTimer(self: *Self, options: StartTimerOptions) void {
10135
- if (options.interval_ms == 0) return self.rejectTimer(options);
10439
+ if (options.interval_ms == 0 or options.interval_ms > std.math.maxInt(u64) / std.time.ns_per_ms) return self.rejectTimer(options);
10136
10440
  const fake = self.executor == .fake;
10137
10441
  // Services are bound before init_fx/update ever run; a null
10138
10442
  // here means a host without the platform timer arm.
@@ -10208,11 +10512,7 @@ pub fn Effects(comptime Msg: type) type {
10208
10512
  /// is its own namespace (like timer keys) and identifies the
10209
10513
  /// playback in every event; it consumes no `max_effects` slots.
10210
10514
  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) {
10515
+ if (audioPlayRejected(options)) {
10216
10516
  self.deliverLoopAudio(.{ .key = options.key, .kind = .rejected }, options.on_event);
10217
10517
  return;
10218
10518
  }
@@ -10271,6 +10571,15 @@ pub fn Effects(comptime Msg: type) type {
10271
10571
  if (volume != 1.0) services.audioSetVolume(volume) catch {};
10272
10572
  }
10273
10573
 
10574
+ /// The native source admission boundary; rejected loads retain the
10575
+ /// active player and deliver their own deferred result.
10576
+ pub fn audioPlayRejected(options: PlayAudioOptions) bool {
10577
+ return (options.path.len == 0 and options.url.len == 0) or
10578
+ options.path.len > max_effect_audio_path_bytes or
10579
+ options.url.len > max_effect_audio_path_bytes or
10580
+ options.cache_path.len > max_effect_audio_path_bytes;
10581
+ }
10582
+
10274
10583
  /// Pause the current playback in place. Idle channels no-op; no
10275
10584
  /// event echoes — the caller commanded it, so the caller knows.
10276
10585
  pub fn pauseAudio(self: *Self) void {
@@ -10424,10 +10733,6 @@ pub fn Effects(comptime Msg: type) type {
10424
10733
  /// or has no handler. Loop-thread only; called by
10425
10734
  /// `UiApp.handleEvent` for `.audio` platform events.
10426
10735
  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
10736
  const kind: EffectAudioEventKind = switch (platform_event.kind) {
10432
10737
  .loaded => .loaded,
10433
10738
  .position => .position,
@@ -10445,6 +10750,21 @@ pub fn Effects(comptime Msg: type) type {
10445
10750
  .buffering = platform_event.buffering,
10446
10751
  .bands = platform_event.bands,
10447
10752
  }) orelse return null;
10753
+ if (self.replay) {
10754
+ // Live reports deliver synchronously. Pair the fed result
10755
+ // with this event now, leaving deferred rejections and other
10756
+ // completions in their original drain order.
10757
+ if (self.takePendingAudioMatching(event.key)) |recorded| {
10758
+ if (!std.meta.eql(recorded, event)) {
10759
+ self.replay_audio_diverged = true;
10760
+ return null;
10761
+ }
10762
+ const event_fn = audio_fn orelse return null;
10763
+ return event_fn(recorded);
10764
+ }
10765
+ if (audio_fn != null) self.replay_audio_diverged = true;
10766
+ return null;
10767
+ }
10448
10768
  const event_fn = audio_fn orelse return null;
10449
10769
  self.journalNote(.{
10450
10770
  .kind = .audio,
@@ -10490,6 +10810,36 @@ pub fn Effects(comptime Msg: type) type {
10490
10810
  };
10491
10811
  }
10492
10812
 
10813
+ /// Queue every field of a recorded delivery, including its owner
10814
+ /// key and spectrum transport flags. Platform audio events pair
10815
+ /// these records synchronously; fake executor feeds still drain.
10816
+ pub fn feedAudioRecord(self: *Self, event: EffectAudio) !void {
10817
+ if (!self.audio.active or self.audio.key != event.key) return error.EffectNotFound;
10818
+ self.deliverPending(.{ .audio = .{ .event = event, .audio_fn = null, .resolve = true } });
10819
+ }
10820
+
10821
+ /// Remove only the first fed audio result for this channel. Shift
10822
+ /// entries and their sequence stamps together so unrelated deferred
10823
+ /// completions retain their exact order, including wrapped rings.
10824
+ fn takePendingAudioMatching(self: *Self, key: u64) ?EffectAudio {
10825
+ for (0..self.pending_exit_len) |offset| {
10826
+ const index = (self.pending_exit_head + offset) % max_effect_pending_exits;
10827
+ const entry = self.pending_exits[index];
10828
+ if (entry != .audio or !entry.audio.resolve or entry.audio.event.key != key) continue;
10829
+ var hole = offset;
10830
+ while (hole + 1 < self.pending_exit_len) : (hole += 1) {
10831
+ const to = (self.pending_exit_head + hole) % max_effect_pending_exits;
10832
+ const from = (self.pending_exit_head + hole + 1) % max_effect_pending_exits;
10833
+ self.pending_exits[to] = self.pending_exits[from];
10834
+ self.pending_exit_seqs[to] = self.pending_exit_seqs[from];
10835
+ }
10836
+ self.pending_exit_len -= 1;
10837
+ if (self.pending_exit_len == 0) self.pending_exit_head = 0;
10838
+ return entry.audio.event;
10839
+ }
10840
+ return null;
10841
+ }
10842
+
10493
10843
  /// Fake executor / replay: feed one audio event as the platform
10494
10844
  /// would deliver it. The event resolves against the live channel
10495
10845
  /// at drain time (key and handler from the channel, mirrors
@@ -10499,9 +10849,8 @@ pub fn Effects(comptime Msg: type) type {
10499
10849
  return self.feedAudioEventBuffering(kind, position_ms, duration_ms, playing, false);
10500
10850
  }
10501
10851
 
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.
10852
+ /// `feedAudioEvent` with the stream-stall flag for fake executor
10853
+ /// stream tests; the plain feed keeps local-file tests terse.
10505
10854
  pub fn feedAudioEventBuffering(self: *Self, kind: EffectAudioEventKind, position_ms: u64, duration_ms: u64, playing: bool, buffering: bool) !void {
10506
10855
  if (!self.audio.active) return error.EffectNotFound;
10507
10856
  self.deliverPending(.{ .audio = .{
@@ -12751,6 +13100,8 @@ pub fn Effects(comptime Msg: type) type {
12751
13100
  if (seen == index) {
12752
13101
  return .{
12753
13102
  .key = slot.key,
13103
+ .generation = slot.generation,
13104
+ .timeout_ms = slot.timeout_ms,
12754
13105
  .method = slot.method,
12755
13106
  .url = slot.fetchUrl(),
12756
13107
  .headers = slot.fetchHeaders(),
@@ -12846,6 +13197,16 @@ pub fn Effects(comptime Msg: type) type {
12846
13197
  /// feed, which must deliver exactly the reason the recorded
12847
13198
  /// session delivered (`.signaled`, `.cancelled`, ...).
12848
13199
  pub fn feedExitReason(self: *Self, key: u64, code: i32, reason: EffectExitReason) error{EffectNotFound}!void {
13200
+ return self.feedExitWithMetadata(key, code, reason, .{});
13201
+ }
13202
+
13203
+ /// Preserve the complete journaled terminal, including loss that
13204
+ /// cannot be inferred from an already-truncated output/tail payload.
13205
+ pub fn feedExitWithMetadata(self: *Self, key: u64, code: i32, reason: EffectExitReason, metadata: struct {
13206
+ output_truncated: bool = false,
13207
+ stderr_truncated: bool = false,
13208
+ dropped_lines: ?u32 = null,
13209
+ }) error{EffectNotFound}!void {
12849
13210
  const slot_index = self.findActiveFakeSlot(key, .spawn) orelse return error.EffectNotFound;
12850
13211
  const slot = &self.slots[slot_index];
12851
13212
  var entry: Entry = .{
@@ -12855,12 +13216,16 @@ pub fn Effects(comptime Msg: type) type {
12855
13216
  .key = slot.key,
12856
13217
  .code = code,
12857
13218
  .reason = reason,
12858
- .dropped_lines = slot.dropped_total,
13219
+ .dropped_lines = metadata.dropped_lines orelse slot.dropped_total,
13220
+ .collect_truncated = metadata.output_truncated,
13221
+ .stderr_truncated = metadata.stderr_truncated,
12859
13222
  .exit_fn = slot.on_exit,
12860
13223
  };
12861
13224
  const exit_fn = slot.on_exit;
12862
13225
  if (slot.output_mode == .collect) {
12863
13226
  stampCollectExit(slot, &entry);
13227
+ entry.collect_truncated = entry.collect_truncated or metadata.output_truncated;
13228
+ entry.stderr_truncated = entry.stderr_truncated or metadata.stderr_truncated;
12864
13229
  slot.state.store(.draining, .release);
12865
13230
  if (!self.enqueue(&entry)) {
12866
13231
  self.releaseSpawnSlot(slot);
@@ -12890,6 +13255,8 @@ pub fn Effects(comptime Msg: type) type {
12890
13255
  .code = code,
12891
13256
  .reason = reason,
12892
13257
  .dropped_lines = entry.dropped_lines,
13258
+ .output_truncated = entry.collect_truncated,
13259
+ .stderr_truncated = entry.stderr_truncated,
12893
13260
  }, exit_fn);
12894
13261
  }
12895
13262
  self.wakeHost();
@@ -12998,9 +13365,10 @@ pub fn Effects(comptime Msg: type) type {
12998
13365
  if (seen == index) {
12999
13366
  return .{
13000
13367
  .key = slot.key,
13368
+ .generation = slot.generation,
13001
13369
  .op = slot.file_op,
13002
13370
  .path = slot.filePath(),
13003
- .bytes = if (slot.file_op == .write) slot.fetchPayload() else "",
13371
+ .bytes = if (slot.file_op == .write or slot.file_op == .append) slot.fetchPayload() else "",
13004
13372
  };
13005
13373
  }
13006
13374
  seen += 1;
@@ -13151,6 +13519,7 @@ pub fn Effects(comptime Msg: type) type {
13151
13519
  if (seen == index) {
13152
13520
  return .{
13153
13521
  .key = slot.key,
13522
+ .generation = slot.generation,
13154
13523
  .op = slot.clipboard_op,
13155
13524
  .text = if (slot.clipboard_op == .write) slot.fetchPayload() else "",
13156
13525
  };
@@ -13382,6 +13751,32 @@ pub fn Effects(comptime Msg: type) type {
13382
13751
  return count;
13383
13752
  }
13384
13753
 
13754
+ /// The index-th parked fake database operation, in slot order. Live
13755
+ /// query facts borrow engine-owned storage until the next operation.
13756
+ pub fn pendingDbAt(self: *Self, index: usize) ?struct {
13757
+ key: u64,
13758
+ generation: u64,
13759
+ kind: DbSlotKind,
13760
+ sql: []const u8,
13761
+ params: []const EffectDbValue,
13762
+ tables: []const []const u8,
13763
+ } {
13764
+ var seen: usize = 0;
13765
+ for (&self.db_slots) |*slot| {
13766
+ if (!slot.active or !slot.fake) continue;
13767
+ if (seen == index) return .{
13768
+ .key = slot.key,
13769
+ .generation = slot.generation,
13770
+ .kind = slot.kind,
13771
+ .sql = if (slot.live) |live| live.sql else "",
13772
+ .params = if (slot.live) |live| live.params else &.{},
13773
+ .tables = if (slot.live) |live| live.tables else &.{},
13774
+ };
13775
+ seen += 1;
13776
+ }
13777
+ return null;
13778
+ }
13779
+
13385
13780
  /// Number of parked (still-active) fake host requests.
13386
13781
  pub fn pendingHostCount(self: *Self) usize {
13387
13782
  var count: usize = 0;
@@ -13419,13 +13814,21 @@ pub fn Effects(comptime Msg: type) type {
13419
13814
  /// whole one); if the completion queue is somehow full, the
13420
13815
  /// terminal still lands through the pending ring as an err —
13421
13816
  /// never a silent ok with lost bytes.
13422
- pub fn feedHostResult(self: *Self, key: u64, ok: bool, bytes: []const u8) error{EffectNotFound}!void {
13817
+ pub fn feedHostResult(self: *Self, key: u64, ok: bool, bytes: []const u8) error{ EffectNotFound, ReplayWindowDivergence }!void {
13423
13818
  const slot_index = blk: {
13424
13819
  const index = self.findActiveSlot(key) orelse return error.EffectNotFound;
13425
13820
  if (self.slots[index].kind != .host and self.slots[index].kind != .store and self.slots[index].kind != .credentials) return error.EffectNotFound;
13426
13821
  break :blk index;
13427
13822
  };
13428
13823
  const slot = &self.slots[slot_index];
13824
+ if (self.replay and desktopWindowSuccess(slot.hostName(), slot.fetchPayload(), bytes)) {
13825
+ // Test-owned replies can arrive after the request's settled
13826
+ // view flush. Their execution fact belongs to this completion
13827
+ // boundary; live facts are normally claimed by the flush.
13828
+ self.flushReplayWindowExecutions();
13829
+ 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;
13830
+ } else if (self.replay and slot.replay_window_reply_len != 0) return error.ReplayWindowDivergence;
13831
+ slot.replay_window_reply_len = 0;
13429
13832
  const buffer = slot.fetch_buffer orelse return error.EffectNotFound;
13430
13833
  const capacity = buffer.len - slot.payload_len;
13431
13834
  var delivered_ok = ok;
@@ -13434,6 +13837,12 @@ pub fn Effects(comptime Msg: type) type {
13434
13837
  delivered_ok = false;
13435
13838
  delivered = "host result over budget";
13436
13839
  }
13840
+ if (slot.fake and !self.replay and delivered_ok) {
13841
+ if (desktopWindowSuccess(slot.hostName(), slot.fetchPayload(), delivered)) {
13842
+ 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 });
13843
+ }
13844
+ self.restoreDesktopWindowResult(slot, delivered);
13845
+ }
13437
13846
  @memcpy(buffer[slot.payload_len..][0..delivered.len], delivered);
13438
13847
  slot.body_len = delivered.len;
13439
13848
  var entry: Entry = .{
@@ -13466,6 +13875,23 @@ pub fn Effects(comptime Msg: type) type {
13466
13875
  self.wakeHost();
13467
13876
  }
13468
13877
 
13878
+ fn restoreDesktopWindowResult(self: *Self, slot: *Slot, bytes: []const u8) void {
13879
+ const closed = std.mem.eql(u8, slot.hostName(), "native-sdk.window.closeResult");
13880
+ if (!closed and !std.mem.eql(u8, slot.hostName(), "native-sdk.window.focusResult")) return;
13881
+ const binding = self.system_services orelse return;
13882
+ const restore = binding.replay_window_result_fn orelse return;
13883
+ const desktop = @import("desktop_files.zig");
13884
+ var request = desktop.request(slot.fetchPayload()) catch return;
13885
+ var reply = desktop.request(bytes) catch return;
13886
+ if (request.at != reply.at or !std.mem.eql(u8, request.bytes[0..request.at], bytes[0..reply.at])) return;
13887
+ const label = request.field() catch return;
13888
+ request.finish() catch return;
13889
+ const failure = reply.field() catch return;
13890
+ reply.finish() catch return;
13891
+ if (failure.len != 0 or label.len == 0 or label.len > 255 or std.mem.indexOfScalar(u8, label, 0) != null) return;
13892
+ restore(binding.context, label, closed);
13893
+ }
13894
+
13469
13895
  /// Replay one redacted credential result. A successful get receives a
13470
13896
  /// deterministic same-length placeholder derived from the recorded
13471
13897
  /// digest; no keychain is touched and no live secret is recoverable
@@ -13527,6 +13953,15 @@ pub fn Effects(comptime Msg: type) type {
13527
13953
  return null;
13528
13954
  }
13529
13955
 
13956
+ /// Build a fake timer's platform event without firing it. Harnesses
13957
+ /// that record sessions dispatch this event through Runtime so replay
13958
+ /// can regenerate the timer Msg from the same journaled input.
13959
+ pub fn fakeTimerEvent(self: *Self, key: u64, timestamp_ns: u64) error{EffectNotFound}!platform.TimerEvent {
13960
+ const index = self.findActiveTimerIndex(key) orelse return error.EffectNotFound;
13961
+ if (!self.timer_slots[index].fake) return error.EffectNotFound;
13962
+ return .{ .id = effectTimerPlatformId(index), .timestamp_ns = timestamp_ns };
13963
+ }
13964
+
13530
13965
  /// Fire the fake fx timer with `key` by hand: its `on_fire` Msg
13531
13966
  /// (timestamp 0 — the fake executor has no clock) lands through
13532
13967
  /// the pending ring and drains on the next `.effects_wake`
@@ -14453,6 +14888,8 @@ pub fn Effects(comptime Msg: type) type {
14453
14888
  slot.line_buffer = null;
14454
14889
  }
14455
14890
  if (slot.kind == .credentials) slot.credentials_waiting = false;
14891
+ slot.desktop_waiting = false;
14892
+ slot.replay_window_reply_len = 0;
14456
14893
  slot.state.store(.idle, .release);
14457
14894
  }
14458
14895