@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
@@ -0,0 +1,95 @@
1
+ import assert from "node:assert/strict";
2
+ import { test } from "node:test";
3
+ import { entryBegin, entryStep, entryPolicy, formatDiagnostics, readFailure } from "./entry_coordination.ts";
4
+ import type { EntryAction, EntryObservation } from "./entry_coordination.ts";
5
+ import { planInvocation, textBytes } from "./invocation.ts";
6
+ import path from "node:path";
7
+ import { invoke } from "./invocation_fixture.ts";
8
+ import type { InvocationCase } from "./invocation_cases.ts";
9
+ import { baseContract as coreContract } from "./core_cases.ts";
10
+ import { baseContract as serviceContract } from "./service_cases.ts";
11
+ const b = textBytes;
12
+ const core = planInvocation(["corewire", "--sidecar", "input", "--facade", "facade", "--profile", "profile"].map(b));
13
+ const service = planInvocation(["corewire", "--services-sidecar", "input", "--service-client", "client"].map(b));
14
+ const observation = (): EntryObservation => ({ plan: core, ok: true, message: [], exit_code: 0, paths: 3, diagnostics: [] });
15
+ function trace(plan = core, observe: (a: EntryAction) => Partial<EntryObservation> = () => ({})) {
16
+ let state = entryBegin(), observed = observation(); const actions: EntryAction[] = [];
17
+ for (let i=0; i<100; i++) {
18
+ const result = entryStep(state, observed);state = result.state;actions.push(result.action);
19
+ if (result.action.kind === "done") return { state, actions };
20
+ observed = { ...observation(), plan, ...observe(result.action) };
21
+ }
22
+ throw new Error("entry coordinator failed to finish");
23
+ }
24
+ test("complete core invocation preserves alias observations before read and warnings before output", () => {
25
+ const {state, actions} = trace(core,a => a.kind === "project" ? { diagnostics:b("warning\n") } : {});
26
+ assert.equal(state.exit_code,0);
27
+ assert.deepEqual(actions.map(a=>a.kind),["plan","canonical_input","alias_paths","canonical_output","canonical_output","canonical_output","identity_input","identity_pair","identity_pair","identity_input","identity_pair","identity_input","aliases","read_core","decode_core","relative_entry","project","diagnostic","flush","outputs","done"]);
28
+ assert.deepEqual(actions.filter(a=>a.kind==="identity_pair").map(a=>[a.cursor,a.prior]),[[0,1],[0,2],[1,2]]);
29
+ assert.deepEqual(actions.find(a=>a.kind==="diagnostic")?.message,b("warning\n"));
30
+ });
31
+ test("service mode bypasses core aliases and entry computation, flushing on complete success",()=>{
32
+ assert.deepEqual(trace(service).actions.map(a=>a.kind),["plan","read_service","decode_service","outputs","flush","done"]);
33
+ assert.deepEqual(trace(service,a=>a.kind==="outputs"?{exit_code:1}:{}).actions.map(a=>a.kind),["plan","read_service","decode_service","outputs","done"]);
34
+ });
35
+ test("argument refusal precedes every path capability",()=>{
36
+ const bad=planInvocation(["corewire","--bad"].map(b)); const t=trace(bad);
37
+ assert.equal(t.state.exit_code,2);assert.deepEqual(t.actions.map(a=>a.kind),["plan","diagnostic","flush","done"]);
38
+ assert.deepEqual(t.actions[1].message,bad.error);
39
+ });
40
+ for(const failure of ["aliases","read_core","decode_core","project"]) test(`${failure} refusal prevents later capabilities and preserves exit and diagnostic selection`,()=>{
41
+ const t=trace(core,a=>a.kind===failure?{ok:false,message:failure==="decode_core"?[]:b("explicit"),diagnostics:b("fields"),exit_code:2}:{});
42
+ const names=t.actions.map(a=>a.kind);assert.equal(names.includes("outputs"),false);
43
+ assert.equal(t.state.exit_code,failure==="aliases"||failure==="project"?2:1);
44
+ assert.deepEqual(t.actions.at(-3)?.message,b(failure==="decode_core"?"fields":"explicit"));
45
+ assert.deepEqual(names.slice(-3),["diagnostic","flush","done"]);
46
+ });
47
+ test("projection field diagnostics are used only in the absence of explicit error",()=>{
48
+ const t=trace(core,a=>a.kind==="project"?{message:[],exit_code:1,diagnostics:b("fields")}:{});
49
+ assert.deepEqual(t.actions.at(-3)?.message,b("fields"));
50
+ });
51
+ test("facade-only and no-facade invocation retain independent entry selection",()=>{
52
+ const facade=planInvocation(["corewire","--sidecar","input","--facade","facade"].map(b));assert.ok(trace(facade).actions.some(a=>a.kind==="basename_entry"));
53
+ const check=planInvocation(["corewire","--sidecar","input","--check"].map(b));assert.ok(!trace(check).actions.some(a=>a.kind.endsWith("_entry")));
54
+ });
55
+ test("diagnostic formatting preserves ordered raw bytes, empty fields and exact punctuation",()=>{
56
+ assert.deepEqual(formatDiagnostics([255,0],[{path:[],message:[128,10],severity:"error"},{path:[65,0],message:[255],severity:"warning"}]),[255,0,...b(": error: "),128,10,10,255,0,...b(": warning: "),65,0,58,32,255,10]);
57
+ assert.deepEqual(readFailure([255,0],[128]),[...b("corewire: cannot read "),255,0,58,32,128,10]);
58
+ });
59
+ test("entry ABI retains raw malformed bytes and normalizes only relative Windows separators",()=>{
60
+ const run=(v:object)=>JSON.parse(entryPolicy(JSON.stringify({operation:"entry",payload:JSON.stringify({bytes:[97,92,98],relative:true,windows:true,absolute:false,valid_utf8:true,facade:[255],directory:[128],...v})})));
61
+ assert.deepEqual(run({}),{text:"a/b",bytes:[97,47,98],utf8:true,unrelated:false,facade_path:[255],profile_directory:[128]});
62
+ assert.equal(run({relative:false}).text,"a\\b");
63
+ assert.deepEqual(run({bytes:[255,0],valid_utf8:false}).bytes,[255,0]);assert.equal(run({bytes:[],valid_utf8:true}).unrelated,true);
64
+ assert.equal(run({bytes:b("\uFEFFé😀.ts")}).text,"\uFEFFé😀.ts");
65
+ });
66
+ for (const kind of ["read_service", "decode_service"]) test(`${kind} refusal terminates before every service output`, () => {
67
+ const t = trace(service, a => a.kind === kind ? { ok: false, message: b("read"), diagnostics: b("decode") } : {});
68
+ assert.equal(t.state.exit_code, 1);
69
+ assert.equal(t.actions.some(a => a.kind === "outputs"), false);
70
+ assert.deepEqual(t.actions.at(-3)?.message, b(kind === "read_service" ? "read" : "decode"));
71
+ });
72
+
73
+ if (process.argv[2] && process.argv[3]) {
74
+ const candidate = path.resolve(process.argv[2]), reference = path.resolve(process.argv[3]);
75
+ const core = JSON.stringify(coreContract(), (key, value) => (key === "origin" || key === "member") && value === null ? undefined : value);
76
+ const services = JSON.stringify(serviceContract());
77
+ const cases: InvocationCase[] = [];
78
+ const add = (name: string, args: string[], fields: Partial<InvocationCase> = {}) => cases.push({ name, args, core, services, directories: ["nested"], ...fields });
79
+ for (const name of ["\uFEFFfacade.ts", "é😀.ts", "quote\".ts", "line\n.ts"]) {
80
+ for (const profile of [false, true]) add("raw entry " + JSON.stringify(name) + (profile ? " with profile" : " basename"),
81
+ ["--sidecar", "input.json", "--facade", name, ...(profile ? ["--profile", "profile"] : [])]);
82
+ }
83
+ for (const input of ["{", "null", "{}", core.replace('"wire_version":10', '"wire_version":0')])
84
+ add("core decode " + input.slice(0, 30), ["--sidecar", "input.json", "--out", "mirror"], { core: input });
85
+ const warnings = core.slice(0, -1) + ',"future_entry_field":true}';
86
+ add("warnings before successful check", ["--sidecar", "input.json", "--check"], { core: warnings });
87
+ add("explicit projection refusal supersedes additive warnings", ["--sidecar", "input.json", "--check", "--optimization", "invalid"], { core: warnings });
88
+ add("core read failure", ["--sidecar", "missing", "--check"]);
89
+ add("service read failure", ["--services-sidecar", "missing", "--service-client", "client"]);
90
+ for (const input of ["{", "null", "{}", services.replace('"format":3', '"format":0'), services.replace('"deterministic":false', '"deterministic":true')])
91
+ add("service decode " + input.slice(0, 30), ["--services-sidecar", "services.json", "--service-client", "client"], { services: input });
92
+ for (const item of cases) test("complete entry native reference: " + item.name, () => {
93
+ assert.deepEqual(invoke(candidate, item), invoke(reference, item));
94
+ });
95
+ }
@@ -0,0 +1,127 @@
1
+ // Complete build-host invocation coordination. Native executes only returned
2
+ // capabilities and owns raw input, decoded records and compiled result bytes.
3
+ import { diagnostic } from "./invocation.ts";
4
+ import type { InvocationPlan } from "./invocation.ts";
5
+
6
+ export interface EntryState {
7
+ phase: string; mode: string; cursor: number; prior: number; paths: number;
8
+ exit_code: number; facade: number | null; profile: number | null;
9
+ }
10
+ export interface EntryObservation {
11
+ plan: InvocationPlan | null; ok: boolean; message: number[]; exit_code: number;
12
+ paths: number; diagnostics: number[];
13
+ }
14
+ export interface EntryAction { kind: string; cursor: number; prior: number; message: number[] }
15
+ export interface EntryStep { state: EntryState; action: EntryAction }
16
+ export function entryBegin(): EntryState {
17
+ return { phase: "plan", mode: "core", cursor: 0, prior: 0, paths: 0, exit_code: 0, facade: null, profile: null };
18
+ }
19
+ function action(state: EntryState, kind: string, message: number[] = []): EntryStep {
20
+ return { state, action: { kind, cursor: state.cursor, prior: state.prior, message } };
21
+ }
22
+ export function entryStep(state: EntryState, observed: EntryObservation): EntryStep {
23
+ while (true) {
24
+ switch (state.phase) {
25
+ case "plan": state.phase = "planned"; return action(state, "plan");
26
+ case "planned": {
27
+ const plan = observed.plan;
28
+ if (plan === null) throw new Error("missing corewire invocation plan");
29
+ state.mode = plan.mode; state.exit_code = plan.exit_code;
30
+ if (plan.exit_code !== 0) { state.phase = "terminal_flush"; return action(state, "diagnostic", plan.error); }
31
+ for (const output of plan.outputs) {
32
+ if (output.kind === "facade") state.facade = output.path_index;
33
+ if (output.kind === "profile") state.profile = output.path_index;
34
+ }
35
+ state.phase = plan.mode === "service" ? "read" : "canonical_input"; continue;
36
+ }
37
+ case "canonical_input": state.phase = "alias_paths"; return action(state, "canonical_input");
38
+ case "alias_paths": state.phase = "canonical_outputs"; return action(state, "alias_paths");
39
+ case "canonical_outputs":
40
+ state.paths = observed.paths; state.cursor = 0; state.phase = "canonical_next"; continue;
41
+ case "canonical_next":
42
+ if (state.cursor === state.paths) { state.cursor = 0; state.phase = "identity_next"; continue; }
43
+ state.phase = "canonical_advance"; return action(state, "canonical_output");
44
+ case "canonical_advance": state.cursor++; state.phase = "canonical_next"; continue;
45
+ case "identity_next":
46
+ if (state.cursor === state.paths) { state.phase = "aliases"; continue; }
47
+ state.prior = state.cursor + 1; state.phase = "identity_pair"; return action(state, "identity_input");
48
+ case "identity_pair":
49
+ if (state.prior === state.paths) { state.cursor++; state.phase = "identity_next"; continue; }
50
+ state.phase = "identity_advance"; return action(state, "identity_pair");
51
+ case "identity_advance": state.prior++; state.phase = "identity_pair"; continue;
52
+ case "aliases": state.phase = "alias_result"; return action(state, "aliases");
53
+ case "alias_result":
54
+ if (observed.message.length !== 0) { state.exit_code = 2; state.phase = "terminal_flush"; return action(state, "diagnostic", observed.message); }
55
+ state.phase = "read"; continue;
56
+ case "read": state.phase = "read_result"; return action(state, state.mode === "service" ? "read_service" : "read_core");
57
+ case "read_result":
58
+ if (!observed.ok) { state.exit_code = 1; state.phase = "terminal_flush"; return action(state, "diagnostic", observed.message); }
59
+ state.phase = "decoded"; return action(state, state.mode === "service" ? "decode_service" : "decode_core");
60
+ case "decoded":
61
+ if (!observed.ok) { state.exit_code = 1; state.phase = "terminal_flush"; return action(state, "diagnostic", observed.diagnostics); }
62
+ if (state.mode === "service") { state.phase = "output"; continue; }
63
+ state.phase = "project";
64
+ if (state.facade !== null) return action(state, state.profile !== null ? "relative_entry" : "basename_entry");
65
+ continue;
66
+ case "project": state.phase = "projected"; return action(state, "project");
67
+ case "projected":
68
+ state.exit_code = observed.exit_code;
69
+ state.phase = observed.exit_code !== 0 ? "terminal_flush" : "output_flush";
70
+ return action(state, "diagnostic", observed.exit_code !== 0 && observed.message.length !== 0 ? observed.message : observed.diagnostics);
71
+ case "output_flush": state.phase = "output"; return action(state, "flush");
72
+ case "output": state.phase = "output_result"; return action(state, "outputs");
73
+ case "output_result":
74
+ state.exit_code = observed.exit_code;
75
+ state.phase = state.mode === "service" && observed.exit_code === 0 ? "terminal_flush" : "done"; continue;
76
+ case "terminal_flush": state.phase = "done"; return action(state, "flush");
77
+ case "done": return action(state, "done");
78
+ default: throw new Error("invalid corewire invocation phase");
79
+ }
80
+ }
81
+ }
82
+ export interface EntryDiagnostic { path: number[]; message: number[]; severity: string }
83
+ export function formatDiagnostics(label: number[], entries: EntryDiagnostic[]): number[] {
84
+ const out: number[] = [];
85
+ for (const item of entries) {
86
+ const line = diagnostic("", label, item.severity === "error" ? ": error: " : ": warning: ");
87
+ if (item.path.length !== 0) { for (const b of item.path) line.push(b); line.push(58, 32); }
88
+ for (const b of item.message) line.push(b);
89
+ line.push(10);
90
+ for (const b of line) out.push(b);
91
+ }
92
+ return out;
93
+ }
94
+ export function readFailure(path: number[], error: number[]): number[] {
95
+ const out = diagnostic("corewire: cannot read ", path, ": ");
96
+ for (const b of error) out.push(b);
97
+ out.push(10); return out;
98
+ }
99
+ export function entryPolicy(input: string): string {
100
+ const value = JSON.parse(input) as { operation: string; payload: string };
101
+ switch (value.operation) {
102
+ case "begin": return JSON.stringify(entryBegin());
103
+ case "step": {
104
+ const v = JSON.parse(value.payload) as { state: EntryState; observation: EntryObservation };
105
+ return JSON.stringify(entryStep(v.state, v.observation));
106
+ }
107
+ case "diagnostics": {
108
+ const v = JSON.parse(value.payload) as { label: number[]; entries: EntryDiagnostic[] };
109
+ return JSON.stringify(formatDiagnostics(v.label, v.entries));
110
+ }
111
+ case "entry": {
112
+ const v = JSON.parse(value.payload) as { bytes: number[]; relative: boolean; windows: boolean; absolute: boolean; valid_utf8: boolean; facade: number[]; directory: number[] };
113
+ const bytes = v.bytes.map(b => v.relative && v.windows && b === 92 ? 47 : b);
114
+ return JSON.stringify({ text: v.valid_utf8 ? new TextDecoder("utf-8", { ignoreBOM: true }).decode(new Uint8Array(bytes)) : "", bytes, utf8: v.valid_utf8,
115
+ unrelated: v.relative && (bytes.length === 0 || v.absolute), facade_path: v.facade, profile_directory: v.directory });
116
+ }
117
+ case "read_failure": {
118
+ const v = JSON.parse(value.payload) as { path: number[]; error: number[] };
119
+ return JSON.stringify(readFailure(v.path, v.error));
120
+ }
121
+ case "service_failure": {
122
+ const v = JSON.parse(value.payload) as { error: number[] };
123
+ return JSON.stringify(diagnostic("corewire: services contract is not valid schema-2 JSON: ", v.error, "\n"));
124
+ }
125
+ default: throw new Error("unknown corewire entry operation");
126
+ }
127
+ }
@@ -0,0 +1,190 @@
1
+ //! Explicit capabilities for TypeScript-owned corewire entry coordination.
2
+ const std = @import("std");
3
+ const invocation = @import("invocation.zig");
4
+ const sidecar = @import("sidecar.zig");
5
+ const service = @import("service_contract.zig");
6
+ const filesystem = @import("filesystem_coordination.zig");
7
+ const PanicSink = *const fn (?*anyopaque, [*]const u8, usize, u64) callconv(.c) void;
8
+ extern fn nsc_profile_set_panic_sink(PanicSink, ?*anyopaque) void;
9
+ extern fn nsc_profile_init() void;
10
+ extern fn nsc_profile_collect() void;
11
+ extern fn nsc_profile_entry_policy([*]const u8, usize, *[*]const u8, *usize) void;
12
+ fn panicSink(_: ?*anyopaque, message: [*]const u8, len: usize, _: u64) callconv(.c) void {
13
+ std.debug.print("corewire: entry coordination trapped: {s}\n", .{message[0..len]});
14
+ std.process.exit(1);
15
+ }
16
+ fn call(comptime T: type, arena: std.mem.Allocator, operation: []const u8, facts: anytype) !T {
17
+ const input = try std.json.Stringify.valueAlloc(arena, .{ .operation = operation, .payload = try std.json.Stringify.valueAlloc(arena, facts, .{}) }, .{});
18
+ nsc_profile_set_panic_sink(panicSink, null);
19
+ nsc_profile_init();
20
+ defer nsc_profile_collect();
21
+ var ptr: [*]const u8 = undefined;
22
+ var len: usize = 0;
23
+ nsc_profile_entry_policy(input.ptr, input.len, &ptr, &len);
24
+ return std.json.parseFromSliceLeaky(T, arena, ptr[0..len], .{ .allocate = .alloc_always }) catch |err| switch (err) {
25
+ error.OutOfMemory => return error.OutOfMemory,
26
+ else => @panic("corewire: malformed compiled entry response"),
27
+ };
28
+ }
29
+ fn raw(arena: std.mem.Allocator, bytes: []const u8) !std.json.Value {
30
+ var values: std.json.Array = .init(arena);
31
+ for (bytes) |byte| try values.append(.{ .integer = byte });
32
+ return .{ .array = values };
33
+ }
34
+ pub fn diagnostics(arena: std.mem.Allocator, label: []const u8, entries: []const sidecar.Diagnostic) ![]const u8 {
35
+ var values: std.json.Array = .init(arena);
36
+ for (entries) |entry| {
37
+ var value: std.json.ObjectMap = .{};
38
+ try value.put(arena, "path", try raw(arena, entry.path));
39
+ try value.put(arena, "message", try raw(arena, entry.message));
40
+ try value.put(arena, "severity", .{ .string = @tagName(entry.severity) });
41
+ try values.append(.{ .object = value });
42
+ }
43
+ return call([]const u8, arena, "diagnostics", .{ .label = try raw(arena, label), .entries = std.json.Value{ .array = values } });
44
+ }
45
+ const State = struct { phase: []const u8, mode: []const u8, cursor: usize, prior: usize, paths: usize, exit_code: u8, facade: ?usize, profile: ?usize };
46
+ const Observation = struct { plan: std.json.Value = .null, ok: bool = true, message: std.json.Value, exit_code: u8 = 0, paths: usize = 0, diagnostics: std.json.Value };
47
+ const Action = struct { kind: enum { plan, canonical_input, alias_paths, canonical_output, identity_input, identity_pair, aliases, read_core, read_service, decode_core, decode_service, relative_entry, basename_entry, project, diagnostic, flush, outputs, done }, cursor: usize, prior: usize, message: []const u8 };
48
+ fn planFacts(arena: std.mem.Allocator, plan: invocation.Plan) !std.json.Value {
49
+ var value = try std.json.parseFromSliceLeaky(std.json.Value, arena, try std.json.Stringify.valueAlloc(arena, plan, .{}), .{ .allocate = .alloc_always });
50
+ try value.object.put(arena, "error", try raw(arena, plan.@"error"));
51
+ return value;
52
+ }
53
+ pub fn run(init: std.process.Init, args: []const []const u8, stderr: *std.Io.Writer) !u8 {
54
+ const arena = init.arena.allocator();
55
+ var state = try call(State, arena, "begin", .{});
56
+ var observed = Observation{ .message = try raw(arena, ""), .diagnostics = try raw(arena, "") };
57
+ var plan: invocation.Plan = undefined;
58
+ var input: []const u8 = undefined;
59
+ var canonical_input: []const u8 = undefined;
60
+ var paths: []const []const u8 = undefined;
61
+ var canonical: [][]const u8 = undefined;
62
+ var identities: [][]bool = undefined;
63
+ var source: []const u8 = undefined;
64
+ var diags: sidecar.Diagnostics = .{ .arena = arena };
65
+ var parsed: sidecar.Sidecar = undefined;
66
+ var contract: ?service.Contract = null;
67
+ var entry: invocation.Entry = .{};
68
+ var result: ?invocation.CoreResult = null;
69
+ while (true) {
70
+ const step = try call(struct { state: State, action: Action }, arena, "step", .{ .state = state, .observation = observed });
71
+ state = step.state;
72
+ const action = step.action;
73
+ observed = .{ .message = try raw(arena, ""), .diagnostics = try raw(arena, "") };
74
+ switch (action.kind) {
75
+ .plan => {
76
+ plan = try invocation.plan(arena, args);
77
+ observed.plan = try planFacts(arena, plan);
78
+ },
79
+ .canonical_input => {
80
+ input = args[plan.input.?];
81
+ canonical_input = try filesystem.canonicalSpelling(init.io, arena, input);
82
+ },
83
+ .alias_paths => {
84
+ paths = try filesystem.aliasPaths(arena, plan, args);
85
+ canonical = try arena.alloc([]const u8, paths.len);
86
+ identities = try arena.alloc([]bool, paths.len);
87
+ for (identities) |*row| {
88
+ row.* = try arena.alloc(bool, paths.len + 1);
89
+ @memset(row.*, false);
90
+ }
91
+ observed.paths = paths.len;
92
+ },
93
+ .canonical_output => canonical[action.cursor] = try filesystem.canonicalSpelling(init.io, arena, paths[action.cursor]),
94
+ .identity_input => identities[action.cursor][0] = try filesystem.sameExistingFile(init.io, arena, canonical[action.cursor], canonical_input),
95
+ .identity_pair => identities[action.cursor][action.prior + 1] = try filesystem.sameExistingFile(init.io, arena, canonical[action.cursor], canonical[action.prior]),
96
+ .aliases => observed.message = try raw(arena, try invocation.aliases(arena, canonical_input, canonical, identities)),
97
+ .read_core, .read_service => {
98
+ input = args[plan.input.?];
99
+ const limit = if (action.kind == .read_core) sidecar.max_sidecar_bytes else service.max_bytes;
100
+ source = std.Io.Dir.cwd().readFileAlloc(init.io, input, arena, .limited(limit)) catch |err| blk: {
101
+ observed.ok = false;
102
+ const message = try call([]const u8, arena, "read_failure", .{ .path = try raw(arena, input), .@"error" = try raw(arena, @errorName(err)) });
103
+ observed.message = try raw(arena, message);
104
+ break :blk "";
105
+ };
106
+ },
107
+ .decode_core => {
108
+ parsed = sidecar.read(arena, source, &diags) catch |err| switch (err) {
109
+ error.OutOfMemory => return err,
110
+ error.Refused => blk: {
111
+ observed.ok = false;
112
+ observed.diagnostics = try raw(arena, try diagnostics(arena, input, diags.list.items));
113
+ break :blk undefined;
114
+ },
115
+ };
116
+ },
117
+ .decode_service => {
118
+ const decoded = try service.decode(arena, source);
119
+ contract = decoded.contract;
120
+ observed.ok = contract != null;
121
+ observed.diagnostics = try raw(arena, if (decoded.intake_error.len != 0)
122
+ try call([]const u8, arena, "service_failure", .{ .@"error" = try raw(arena, decoded.intake_error) })
123
+ else
124
+ decoded.diagnostics);
125
+ },
126
+ .relative_entry => {
127
+ const facade_path = args[state.facade.?];
128
+ const profile_dir = std.fs.path.dirname(args[state.profile.?]) orelse ".";
129
+ var buffer: [std.fs.max_path_bytes]u8 = undefined;
130
+ const len = std.Io.Dir.cwd().realPath(init.io, &buffer) catch 0;
131
+ const cwd = if (len == 0) "." else buffer[0..len];
132
+ const related = try std.fs.path.relative(arena, cwd, init.environ_map, profile_dir, facade_path);
133
+ entry = try entryFacts(arena, related, true, facade_path, profile_dir);
134
+ },
135
+ .basename_entry => entry = try entryFacts(arena, std.fs.path.basename(args[state.facade.?]), false, "", ""),
136
+ .project => {
137
+ result = try invocation.core(arena, parsed, plan, args, entry, source);
138
+ for (result.?.diagnostics) |item| diags.flag(item.path, "{s}", .{item.message});
139
+ observed.exit_code = result.?.exit_code;
140
+ observed.message = try raw(arena, result.?.@"error");
141
+ if (result.?.exit_code == 0 or result.?.@"error".len == 0)
142
+ observed.diagnostics = try raw(arena, try diagnostics(arena, input, diags.list.items));
143
+ },
144
+ .diagnostic => try stderr.writeAll(action.message),
145
+ .flush => try stderr.flush(),
146
+ .outputs => observed.exit_code = try filesystem.execute(init, stderr, plan, args, result, contract),
147
+ .done => return state.exit_code,
148
+ }
149
+ }
150
+ }
151
+ fn entryFacts(arena: std.mem.Allocator, bytes: []const u8, relative: bool, facade: []const u8, directory: []const u8) !invocation.Entry {
152
+ const result = try call(struct { text: []const u8, bytes: []const u8, utf8: bool, unrelated: bool, facade_path: []const u8, profile_directory: []const u8 }, arena, "entry", .{
153
+ .bytes = try raw(arena, bytes),
154
+ .relative = relative,
155
+ .windows = std.fs.path.sep == std.fs.path.sep_windows,
156
+ .absolute = std.fs.path.isAbsolute(bytes),
157
+ .valid_utf8 = std.unicode.utf8ValidateSlice(bytes),
158
+ .facade = try raw(arena, facade),
159
+ .directory = try raw(arena, directory),
160
+ });
161
+ return .{ .text = result.text, .bytes = result.bytes, .utf8 = result.utf8, .unrelated = result.unrelated, .facade_path = result.facade_path, .profile_directory = result.profile_directory };
162
+ }
163
+
164
+ test "entry state, raw diagnostics and path facts survive alternating collection" {
165
+ var arena_state = std.heap.ArenaAllocator.init(std.testing.allocator);
166
+ defer arena_state.deinit();
167
+ const arena = arena_state.allocator();
168
+ const state = try call(State, arena, "begin", .{});
169
+ const observed = Observation{ .message = try raw(arena, ""), .diagnostics = try raw(arena, "") };
170
+ const step = try call(struct { state: State, action: Action }, arena, "step", .{ .state = state, .observation = observed });
171
+ const diagnostic = try diagnostics(arena, "input\xff", &.{.{ .path = "field", .message = "message\x80", .severity = .@"error" }});
172
+ const path = try entryFacts(arena, "\xef\xbb\xbffacade.ts", true, "facade\xff", "dir\x80");
173
+ const malformed = try entryFacts(arena, "facade\xff.ts", false, "", "");
174
+ for (0..8) |_| {
175
+ _ = try invocation.plan(arena, &.{ "corewire", "--bad" });
176
+ _ = try call([]const u8, arena, "service_failure", .{ .@"error" = try raw(arena, "UnexpectedEndOfInput") });
177
+ _ = try entryFacts(arena, "other.ts", true, "other", ".");
178
+ try std.testing.expectEqualStrings("planned", step.state.phase);
179
+ try std.testing.expectEqualStrings("core", state.mode);
180
+ try std.testing.expectEqual(@as(@TypeOf(step.action.kind), .plan), step.action.kind);
181
+ try std.testing.expectEqualStrings("input\xff: error: field: message\x80\n", diagnostic);
182
+ try std.testing.expectEqualStrings("\xef\xbb\xbffacade.ts", path.text);
183
+ try std.testing.expectEqualStrings(path.text, path.bytes);
184
+ try std.testing.expectEqualStrings("facade\xff", path.facade_path);
185
+ try std.testing.expectEqualStrings("dir\x80", path.profile_directory);
186
+ try std.testing.expectEqualStrings("facade\xff.ts", malformed.bytes);
187
+ try std.testing.expectEqualStrings("", malformed.text);
188
+ try std.testing.expect(!malformed.utf8);
189
+ }
190
+ }
@@ -0,0 +1,85 @@
1
+ // Exact generated code text shared with the preserved projection fixtures.
2
+ export const header = "// Generated by corewire from this app's core.contract.json — the\n// compiled-core entry module. It imports the author's core module\n// (staged beside this file with its SDK imports resolved locally),\n// owns the committed model in module state, and exports the\n// profile-declared dispatch surface. Inbound payloads decode\n// through the generated wire codec below; returned Cmd/Sub data\n// encodes through the same codec's v3 wires — byte-identical to\n// the transpiler lane's output. The same sidecar generates the\n// host's Zig mirror (core_shim.zig), so the two sides carry one\n// set of types, wire tags, field orders, and byte encodings by\n// construction. Do not edit; regenerate from the sidecar.\n//\n// Contract identity: entry {s}, compiler {s}, build_id\n// {x:0>16}.\n";
3
+ export const reexportPrelude = "\n// The contract type designations the sidecar section names — the\n// author's exported declarations re-exported verbatim. Private\n// reachable declarations have structural twins below instead: their\n// authored modules expose no name this facade can import.\n";
4
+ export const privateTypes = "\n// Private contract-table declarations, reconstructed structurally\n// because their authored modules expose no importable designation.\n";
5
+ export const channels = "\n// The exported-const channel conventions must be DECLARED here (the\n// sidecar emitter reads the entry module's own declarations;\n// re-exports do not join its tables).\n";
6
+ export const unbound = "\n// The unbound-list declaration, carried by the generator from the\n// author's own markings in the core module: message arms only the\n// host fires, and model fields and helpers only update logic reads.\nexport const viewUnbound = [\n";
7
+ export const helperPrelude = "\n// The model helpers must be DECLARED here too, in declaration order\n// — the compiled contract's model_helpers table and helper_call's\n// index space both derive from it. Classed helper returns prove at\n// this boundary: bind the helper's value, range-guard it (an\n// ordered comparison excludes NaN), and state wholeness with\n// Math.trunc at the return.\n";
8
+ export const helperOptionalInteger = "\nexport function {s}(model: {s}): {s} {{\n const nscfValue = nscfH_{s}(model);\n if (nscfValue === null) return null;\n if (nscfValue >= {s} && nscfValue <= {s}) return Math.trunc(nscfValue);\n nscfTrap(\"a helper return is NaN or outside its attested exact-integer range — the integer slot has no honest value for it\");\n}}\n";
9
+ export const helperInteger = "\nexport function {s}(model: {s}): number {{\n const nscfValue = nscfH_{s}(model);\n if (nscfValue >= {s} && nscfValue <= {s}) return Math.trunc(nscfValue);\n nscfTrap(\"a helper return is NaN or outside its attested exact-integer range — the integer slot has no honest value for it\");\n}}\n";
10
+ export const helperSequence = "\nexport function {s}(model: {s}): {s} {{\n return nscfH_{s}(model) as {s};\n}}\n";
11
+ export const helperValue = "\nexport function {s}(model: {s}): {s} {{\n return nscfH_{s}(model);\n}}\n";
12
+ export const entries = "\n// The designated shape-flag exports: the profile names init and\n// coreUpdate, and their return shapes restate the contract's\n// init_returns_cmd/update_returns_cmd flags.\n";
13
+ export const initMixed = "\nexport function init(): [{s}, Uint8Array] {{\n const out = nscfInitialModel();\n if (Array.isArray(out)) return [out[0], nscfCmdBytes(out[1])];\n return [out, new Uint8Array(0)];\n}}\n";
14
+ export const initCommand = "\nexport function init(): [{s}, Uint8Array] {{\n const pair = nscfInitialModel();\n return [pair[0], nscfCmdBytes(pair[1])];\n}}\n";
15
+ export const initModel = "\nexport function init(): {s} {{\n return nscfInitialModel();\n}}\n";
16
+ export const messageTags = "\n// Declaration-order wire tags (the contract sidecar is the tag\n// authority; a skewed table cannot survive the paired battery's\n// byte comparison or the mirror's boot fence).\nconst nscfArmNames = [\n";
17
+ export const unknownTag = "\nfunction nscfTagOf(kind: string): number {\n for (let i = 0; i < nscfArmNames.length; i++) {\n if (nscfArmNames[i] === kind) return i;\n }\n nscfTrap(\"a command routes the unknown arm \" + kind + \" — the author module and this generated module disagree\");\n}\n";
18
+ export const updateMixed = "\nexport function coreUpdate(model: {s}, msg: {s}): [{s}, Uint8Array] {{\n const out = nscfUpdate(model, msg);\n if (Array.isArray(out)) return [out[0], nscfCmdBytes(out[1])];\n return [out, new Uint8Array(0)];\n}}\n";
19
+ export const updateCommand = "\nexport function coreUpdate(model: {s}, msg: {s}): [{s}, Uint8Array] {{\n const pair = nscfUpdate(model, msg);\n return [pair[0], nscfCmdBytes(pair[1])];\n}}\n";
20
+ export const updateModel = "\nexport function coreUpdate(model: {s}, msg: {s}): {s} {{\n return nscfUpdate(model, msg);\n}}\n";
21
+ export const subscriptions = "\nexport function coreSubscriptions(model: {s}): Uint8Array {{\n return nscfSubBytes(nscfSubscriptions(model));\n}}\n";
22
+ export const dispatchPrelude = "\n// ------------------------------------------------ the dispatch surface\n// One committed model in module state; every dispatch entry runs one\n// update+commit and returns the cycle's command bytes.\n\n";
23
+ export const commitCommand = "\nfunction nscfCommit(out: [{s}, Uint8Array]): Uint8Array {{\n nscfCommitted = out[0];\n return out[1];\n}}\n";
24
+ export const commitModel = "\nfunction nscfCommit(out: {s}): Uint8Array {{\n nscfCommitted = out;\n return new Uint8Array(0);\n}}\n";
25
+ export const bootstrap = "\nfunction nscfUnknownTag(entry: string, tag: number): never {\n nscfTrap(\"tag \" + tag + \" does not name a \" + entry + \" message arm of this core — the host and this core disagree about the contract\");\n}\n";
26
+ export const bootCommand = "\nexport function boot_cmd(): Uint8Array {\n return nscfBootPair[1];\n}\n";
27
+ export const bootEmpty = "\nexport function boot_cmd(): Uint8Array {\n // init_returns_cmd is false for this contract: no boot command.\n return new Uint8Array(0);\n}\n";
28
+ export const dispatchInteger = " // This integer-classed arm proves in place: its attestation\n // selects the signed or unsigned lower bound, the ordered\n // comparisons exclude NaN, and Math.trunc states wholeness.\n if (tag === nscfTag_{s}) {{\n if (value >= {s} && value <= {s}) {{\n const whole = Math.trunc(value);\n return nscfCommit(coreUpdate(nscfCommitted, {s}));\n }}\n nscfTrap(\"a numeric dispatch value is NaN or outside its attested exact-integer range — the integer slot has no honest value for it\");\n }}\n";
29
+ export const dispatchNumberBytesInteger = " if (tag === nscfTag_{s}) {{\n // The number field is i64-classed: range-guard the raw f64 (an\n // ordered comparison excludes NaN) and state wholeness with\n // Math.trunc at the write.\n if (value >= {s} && value <= {s}) {{\n return nscfCommit(coreUpdate(nscfCommitted, {{ kind: \"{s}\", {s}: Math.trunc(value), {s}: payload }}));\n }}\n nscfTrap(\"a numeric dispatch value is NaN or outside its attested exact-integer range — the integer slot has no honest value for it\");\n }}\n";
30
+ export const dispatchEnumGuard = " if (tag === nscfTag_{s}) {{\n if (member >= nscfMembers{s}.length) nscfMember(\"{s}\", member);\n {s}\n }}\n";
31
+ export const scrollDispatch = "\nexport function dispatch_scroll_state(\n tag: number,\n offsetX: number,\n offsetY: number,\n velocityX: number,\n velocityY: number,\n viewportExtentX: number,\n viewportExtentY: number,\n contentExtentX: number,\n contentExtentY: number,\n): Uint8Array {\n";
32
+ export const scrollDispatchGuard = " if (tag === nscfTag_{s}) {{\n if ({s}) return nscfCommit(coreUpdate(nscfCommitted, {s}));\n nscfTrap(\"a scroll dispatch value is NaN or outside its attested exact-integer range — the integer slot has no honest value for it\");\n }}\n";
33
+ export const messageEnvelope = "\n// --------------------------------------------- the ABI channel entries\n// Each answers the channel bytes envelope: [produced u8][tag u8]\n// [payload in the arm's canonical value encoding]. Byte 0 is 0\n// (nothing produced; the envelope is exactly two bytes) or 1.\n\nfunction nscfPackMsg(produced: {s} | null): Uint8Array {{\n if (produced === null) return new Uint8Array(2);\n const sink = nscfNewSink();\n nscfMsgPayload(sink, produced);\n const payload = nscfFinish(sink);\n const out = new Uint8Array(2 + payload.length);\n out[0] = 1;\n out[1] = nscfTagOf(produced.kind);\n for (let i = 0; i < payload.length; i++) out[2 + i] = payload[i]!;\n return out;\n}}\n";
34
+ export const commandBytesEntry = "\nexport function abi_command_msg(name: Uint8Array): Uint8Array {\n return nscfPackMsg(nscfChanCommandMsg(name));\n}\n";
35
+ export const commandEntry = "\nexport function abi_command_msg(name: Uint8Array): Uint8Array {\n return nscfPackMsg(nscfChanCommandMsg(nscfAsciiString(name)));\n}\n";
36
+ export const frameEntry = "\nexport function abi_frame_msg(width: number, height: number, timestampMs: number, intervalMs: number): Uint8Array {\n return nscfPackMsg(nscfChanFrameMsg(nscfCommitted, {\n width: width,\n height: height,\n timestampMs: timestampMs,\n intervalMs: intervalMs,\n }));\n}\n";
37
+ export const keyEntry = "\nexport function abi_key_msg(\n key: Uint8Array,\n shift: number,\n control: number,\n alt: number,\n superMod: number,\n): Uint8Array {\n return nscfPackMsg(nscfChanKeyMsg({\n key: nscfAsciiString(key),\n shift: shift !== 0,\n control: control !== 0,\n alt: alt !== 0,\n super: superMod !== 0,\n }));\n}\n";
38
+ export const pinchEntry = "\n// The pinch phase table the channel's u32 member index reads back\n// through (the SDK's declared PinchPhase members, in order).\nconst nscfPinchPhases: PinchPhase[] = [\"begin\", \"change\", \"end\"];\n\nexport function abi_pinch_msg(\n windowId: number,\n label: Uint8Array,\n phase: number,\n scale: number,\n x: number,\n y: number,\n): Uint8Array {\n if (phase >= nscfPinchPhases.length) nscfMember(\"PinchPhase\", phase);\n return nscfPackMsg(nscfChanPinchMsg({\n windowId: windowId,\n label: nscfAsciiString(label),\n phase: nscfPinchPhases[phase]!,\n scale: scale,\n x: x,\n y: y,\n }));\n}\n";
39
+ export const dropEntry = "\nexport function abi_drop_msg(event: Uint8Array): Uint8Array {\n let at = 0;\n const windowId = nscfReadF64(event, at);\n at += 8;\n const viewLabelLen = nscfReadU32(event, at);\n at += 4;\n const viewLabel = nscfReadBytesBody(event, at, viewLabelLen);\n at += viewLabelLen;\n const pointPresent = nscfReadBool(event, at);\n at += 1;\n let point: FileDropPoint | null = null;\n if (pointPresent) {\n const x = nscfReadF64(event, at);\n at += 8;\n const y = nscfReadF64(event, at);\n at += 8;\n point = { x: x, y: y };\n }\n const pathCount = nscfReadU32(event, at);\n at += 4;\n const paths: Uint8Array[] = [];\n for (let i = 0; i < pathCount; i++) {\n const pathLen = nscfReadU32(event, at);\n at += 4;\n paths.push(nscfReadBytesBody(event, at, pathLen));\n at += pathLen;\n }\n nscfAssertConsumed(event, at);\n return nscfPackMsg(nscfChanDropMsg({\n windowId: windowId,\n viewLabel: nscfAsciiString(viewLabel),\n point: point,\n paths: paths,\n }));\n}\n";
40
+ export const subscriptionsAfterCycle = "\nexport function abi_subscriptions(): Uint8Array {\n return coreSubscriptions(nscfCommitted);\n}\n";
41
+ export const emptySubscriptions = "\nexport function abi_subscriptions(): Uint8Array {\n // has_subscriptions is false for this contract: always empty.\n return new Uint8Array(0);\n}\n";
42
+ export const snapshot = "\n// The positional committed-model encoding used only by the\n// core/shim mirror ABI. Keep this stable with shim_rt.decodeSnapshot;\n// durable persistence has its own tagged export below.\nexport function model_snapshot(): Uint8Array {{\n const sink = nscfNewSink();\n nscfWrite{s}(sink, nscfCommitted);\n return nscfFinish(sink);\n}}\n";
43
+ export const persistPrelude = "\n// The canonical committed-model encoding (snapshot format {d}): the\n// root record is a u32 field count followed by tagged fields\n// [u32 declaration-index][u32 payload-length][payload]. Each payload\n// uses the command dialect's little-endian canonical value encoding.\nfunction nscfSnapshot{s}(value: {s}): Uint8Array {{\n const sink = nscfNewSink();\n nscfWU32(sink, {d});\n";
44
+ export const persistEnd = "\n return nscfFinish(sink);\n}}\n\nexport function persist_snapshot(): Uint8Array {{\n return nscfSnapshot{s}(nscfCommitted);\n}}\n";
45
+ export const restorePrelude = "\nfunction nscfSnapshotPayloads(snapshot: Uint8Array): Uint8Array {\n let nscfAt = 0;\n const sink = nscfNewSink();";
46
+ export const restoreFieldsEnd = " nscfAssertConsumed(snapshot, nscfAt);\n return nscfFinish(sink);\n}\n\n// Replace the committed root from the same canonical encoding\n// persist_snapshot emits. The ABI result is intentionally empty:\n// restore is a boot mutation owned by the host, not an app Cmd.\n";
47
+ export const restoreFinish = "export function restore_model(snapshot: Uint8Array): Uint8Array {{\n nscfCommitted = nscfDecodeSnapshot{s}(nscfSnapshotPayloads(snapshot));\n return new Uint8Array(0);\n}}\n";
48
+ export const migration = "\n// Pure schema migration. A one-byte status prefix keeps an\n// empty Model snapshot distinguishable from failure.\nexport function migrate_model(snapshot: Uint8Array, fromVersion: number): Uint8Array {{\n try {{\n const migrated = nscfMigrate(snapshot, fromVersion);\n const body = nscfSnapshot{s}(migrated);\n const out = new Uint8Array(body.length + 1);\n out[0] = 1;\n for (let i = 0; i < body.length; i++) out[i + 1] = body[i]!;\n return out;\n }} catch {{\n return new Uint8Array(1);\n }}\n}}\n";
49
+ export const noMigration = "\n// This core declares no migration hook.\nexport function migrate_model(snapshot: Uint8Array, fromVersion: number): Uint8Array {\n return new Uint8Array(1);\n}\n";
50
+ export const helperEmpty = "\n// This core declares no model helpers; the entry stays for the ABI's\n// fixed export set.\nexport function helper_call(helper: number, args: Uint8Array): Uint8Array {\n nscfAssertConsumed(args, 0);\n nscfTrap(\"helper index \" + helper + \" does not name an exported model helper of this core — the host and this core disagree about the contract\");\n}\n";
51
+ export const helperCallPrelude = "\n// ------------------------------------------------------- model helpers\n// Indexed by the contract's model_helpers order; results ride the\n// canonical value encoding of each helper's declared return type.\nexport function helper_call(helper: number, args: Uint8Array): Uint8Array {\n nscfAssertConsumed(args, 0);\n";
52
+ export const generatedTablesPrelude = "\n// ----------------------------------- generated tables and codecs\n// Enum member tables (u32 member indices read back through them),\n// canonical record/union writers, and standalone union decoders.\n";
53
+ export const memberTrap = "\nfunction nscfMember(enumName: string, member: number): never {\n nscfTrap(\"member index \" + member + \" does not name a \" + enumName + \" member — the host and this core disagree about the contract\");\n}\n";
54
+ export const enumIndex = "\nfunction nscfIndex{s}(value: {s}): number {{\n for (let i = 0; i < nscfMembers{s}.length; i++) {{\n if (nscfMembers{s}[i] === value) return i;\n }}\n nscfTrap(\"an enum slot carries an undeclared member — the author module and this generated module disagree\");\n}}\n";
55
+ export const unionDecoderPrelude = "\nfunction nscfDecode{s}(bytes: Uint8Array): {s} {{\n if (bytes.length === 0) {{\n nscfTrap(\"a dispatched union payload carries no arm byte — the host and this core disagree about the contract\");\n }}\n const arm = bytes[0]!;\n";
56
+ export const codecPrelude = "\n// -------------------------------------------------- the wire codec\n// The canonical value encoding (little-endian, headerless,\n// schema-driven) plus the v3 command/subscription wire format the\n// host consumes — byte-identical to what the transpiler lane emits,\n// proven by the paired e2e batteries.\n";
57
+ export const trap = "\nfunction nscfTrap(teaching: string): never {\n throw new Error(teaching);\n}\n";
58
+ export const readU8 = "\nfunction nscfReadU8(bytes: Uint8Array, at: number): number {\n if (at >= bytes.length) {\n nscfTrap(\"a dispatch payload ended mid-value — the host and this core disagree about a type's layout\");\n }\n return bytes[at]!;\n}\n";
59
+ export const readU32 = "\nfunction nscfReadU32(bytes: Uint8Array, at: number): number {\n if (at + 4 > bytes.length) {\n nscfTrap(\"a dispatch payload ended mid-value — the host and this core disagree about a type's layout\");\n }\n return bytes[at]! + bytes[at + 1]! * 256 + bytes[at + 2]! * 65536 + bytes[at + 3]! * 16777216;\n}\n";
60
+ export const readF64 = "\nfunction nscfReadF64(bytes: Uint8Array, at: number): number {\n if (at + 8 > bytes.length) {\n nscfTrap(\"a dispatch payload ended mid-value — the host and this core disagree about a type's layout\");\n }\n const data = new Uint8Array(8);\n const buf = new DataView(data.buffer);\n for (let i = 0; i < 8; i++) {\n data[i] = bytes[at + i]!;\n }\n return buf.getFloat64(0, true);\n}\n";
61
+ export const readI64 = "\nfunction nscfReadI64(bytes: Uint8Array, at: number): number {\n const lo = nscfReadU32(bytes, at);\n const hi = nscfReadU32(bytes, at + 4);\n const hiSigned = hi >= 2147483648 ? hi - 4294967296 : hi;\n const value = hiSigned * 4294967296 + lo;\n if (value > 9007199254740991 || value < -9007199254740991) {\n nscfTrap(\"an integer payload is at or past 2^53 — the f64 number model has no honest value for it\");\n }\n return value;\n}\n";
62
+ export const readI64Saturating = "\n// An i64 payload saturated into the f64-exact window: values at or\n// past +-2^53 clamp to +-(2^53 - 1). Selection offsets ride this\n// reader because the host's select-all synthesizes the maxInt \"to\n// the end\" sentinel, which every consumer snaps to the text's\n// length.\nfunction nscfReadI64Saturating(bytes: Uint8Array, at: number): number {\n const lo = nscfReadU32(bytes, at);\n const hi = nscfReadU32(bytes, at + 4);\n const hiSigned = hi >= 2147483648 ? hi - 4294967296 : hi;\n const value = hiSigned * 4294967296 + lo;\n if (value > 9007199254740991) return 9007199254740991;\n if (value < -9007199254740991) return -9007199254740991;\n return value;\n}\n";
63
+ export const readU64Saturating = "\n// A u64 payload saturated into the nonnegative f64-exact window.\n// Selection offsets use this twin when their sidecar slot is\n// unsigned: maxInt(usize) is all-one bits, not signed -1.\nfunction nscfReadU64Saturating(bytes: Uint8Array, at: number): number {\n const lo = nscfReadU32(bytes, at);\n const hi = nscfReadU32(bytes, at + 4);\n if (hi > 2097151) return 9007199254740991;\n return hi * 4294967296 + lo;\n}\n";
64
+ export const readBool = "\nfunction nscfReadBool(bytes: Uint8Array, at: number): boolean {\n if (at >= bytes.length) {\n nscfTrap(\"a dispatch payload ended mid-value — the host and this core disagree about a type's layout\");\n }\n const raw = bytes[at]!;\n if (raw > 1) {\n nscfTrap(\"a dispatch payload carries a boolean discriminant past 1 — the host and this core disagree about a type's layout\");\n }\n return raw === 1;\n}\n";
65
+ export const readBytesBody = "\nfunction nscfReadBytesBody(bytes: Uint8Array, at: number, len: number): Uint8Array {\n if (at + len > bytes.length) {\n nscfTrap(\"a dispatch payload ended mid-value — the host and this core disagree about a type's layout\");\n }\n const out = new Uint8Array(len);\n for (let i = 0; i < len; i++) {\n out[i] = bytes[at + i]!;\n }\n return out;\n}\n";
66
+ export const assertConsumed = "\nfunction nscfAssertConsumed(bytes: Uint8Array, at: number): void {\n if (at !== bytes.length) {\n nscfTrap(\"a dispatch payload carries bytes past the decoded value — the host and this core disagree about a type's layout\");\n }\n}\n";
67
+ export const truncTowardZero = "\n// An i64-classed slot narrows core-side by truncation toward zero\n// (producers guarantee integer-classed values are exact below 2^53).\nfunction nscfTruncTowardZero(value: number): number {\n return value < 0 ? -Math.floor(-value) : Math.floor(value);\n}\n";
68
+ export const sink = "\n// A sink is a plain byte accumulator; nscfFinish snapshots it.\ntype nscfSink = number[];\n\nfunction nscfNewSink(): nscfSink {\n return [];\n}\n\nfunction nscfFinish(sink: nscfSink): Uint8Array {\n const out = new Uint8Array(sink.length);\n for (let i = 0; i < sink.length; i++) {\n out[i] = sink[i]!;\n }\n return out;\n}\n";
69
+ export const writeU8 = "\nfunction nscfWU8(sink: nscfSink, value: number): void {\n sink.push(value);\n}\n";
70
+ export const writeU32 = "\nfunction nscfWU32(sink: nscfSink, value: number): void {\n sink.push(value % 256);\n sink.push(Math.floor(value / 256) % 256);\n sink.push(Math.floor(value / 65536) % 256);\n sink.push(Math.floor(value / 16777216) % 256);\n}\n";
71
+ export const writeF64 = "\nfunction nscfWF64(sink: nscfSink, value: number): void {\n const data = new Uint8Array(8);\n const buf = new DataView(data.buffer);\n buf.setFloat64(0, value, true);\n for (let i = 0; i < 8; i++) {\n sink.push(data[i]!);\n }\n}\n";
72
+ export const writeI64 = "\n// Two's-complement i64, exact for every integer within +-(2^53 - 1).\nfunction nscfWI64(sink: nscfSink, value: number): void {\n if (value > 9007199254740991 || value < -9007199254740991 || value !== nscfTruncTowardZero(value)) {\n nscfTrap(\"an integer slot carries a non-integer or out-of-range value — the i64 encoding has no honest bytes for it\");\n }\n const hi = Math.floor(value / 4294967296);\n const lo = value - hi * 4294967296;\n const hiWire = hi < 0 ? hi + 4294967296 : hi;\n nscfWU32(sink, lo);\n nscfWU32(sink, hiWire);\n}\n";
73
+ export const writeU64 = "\n// The unsigned twin for u64-attested slots: 8-byte unsigned LE,\n// refusing negatives (a negative value has no honest unsigned\n// bytes).\nfunction nscfWU64(sink: nscfSink, value: number): void {\n if (value > 9007199254740991 || value < 0 || value !== nscfTruncTowardZero(value)) {\n nscfTrap(\"an unsigned integer slot carries a non-integer, negative, or out-of-range value — the u64 encoding has no honest bytes for it\");\n }\n const hi = Math.floor(value / 4294967296);\n const lo = value - hi * 4294967296;\n nscfWU32(sink, lo);\n nscfWU32(sink, hi);\n}\n";
74
+ export const writeBool = "\nfunction nscfWBool(sink: nscfSink, value: boolean): void {\n sink.push(value ? 1 : 0);\n}\n";
75
+ export const writeBytes = "\n// A u32-length-prefixed bytes value (the canonical bytes encoding,\n// and the wire format's long-bytes field).\nfunction nscfWBytes(sink: nscfSink, bytes: Uint8Array): void {\n nscfWU32(sink, bytes.length);\n for (const byte of bytes) sink.push(byte);\n}\n";
76
+ export const shortText = "\nfunction nscfTextBytes(text: string): Uint8Array {\n const out = new Uint8Array(text.length);\n for (let i = 0; i < text.length; i++) {\n out[i] = text.charCodeAt(i);\n }\n return out;\n}\n\n// A u8-length-prefixed short text field (names, keys, labels).\nfunction nscfWShortText(sink: nscfSink, text: string): void {\n const bytes = nscfTextBytes(text);\n if (bytes.length > 255) {\n nscfTrap(\"a command name or key is over 255 bytes — the wire's short-text fields cannot carry it\");\n }\n sink.push(bytes.length);\n for (const byte of bytes) sink.push(byte);\n}\n\nfunction nscfWShortBytes(sink: nscfSink, bytes: Uint8Array): void {\n if (bytes.length > 255) nscfTrap(\"a command key exceeds the 255-byte wire limit\");\n sink.push(bytes.length);\n for (const byte of bytes) sink.push(byte);\n}\n";
77
+ export const utf8Text = "\n// Store keys are ordinary UTF-8 text, not the ASCII-only\n// short names used by command routing. This mirrors the SDK's\n// utf8Bytes intrinsic, including U+FFFD for lone surrogates.\nfunction nscfUtf8TextBytes(text: string): Uint8Array {\n let byteLength = 0;\n for (let i = 0; i < text.length; i++) {\n const code = text.charCodeAt(i);\n if (code <= 0x7f) byteLength += 1;\n else if (code <= 0x7ff) byteLength += 2;\n else if (code >= 0xd800 && code <= 0xdbff && i + 1 < text.length) {\n const next = text.charCodeAt(i + 1);\n if (next >= 0xdc00 && next <= 0xdfff) {\n byteLength += 4;\n i += 1;\n } else byteLength += 3;\n } else byteLength += 3;\n }\n const out = new Uint8Array(byteLength);\n let at = 0;\n for (let i = 0; i < text.length; i++) {\n let code = text.charCodeAt(i);\n if (code >= 0xd800 && code <= 0xdbff && i + 1 < text.length) {\n const next = text.charCodeAt(i + 1);\n if (next >= 0xdc00 && next <= 0xdfff) {\n code = 0x10000 + ((code - 0xd800) << 10) + (next - 0xdc00);\n i += 1;\n } else code = 0xfffd;\n } else if (code >= 0xd800 && code <= 0xdfff) code = 0xfffd;\n if (code <= 0x7f) {\n out[at] = code;\n at += 1;\n } else if (code <= 0x7ff) {\n out[at] = 0xc0 | (code >> 6);\n out[at + 1] = 0x80 | (code & 0x3f);\n at += 2;\n } else if (code <= 0xffff) {\n out[at] = 0xe0 | (code >> 12);\n out[at + 1] = 0x80 | ((code >> 6) & 0x3f);\n out[at + 2] = 0x80 | (code & 0x3f);\n at += 3;\n } else {\n out[at] = 0xf0 | (code >> 18);\n out[at + 1] = 0x80 | ((code >> 12) & 0x3f);\n out[at + 2] = 0x80 | ((code >> 6) & 0x3f);\n out[at + 3] = 0x80 | (code & 0x3f);\n at += 4;\n }\n }\n return out;\n}\n";
78
+ export const asciiString = "\nfunction nscfAsciiString(bytes: Uint8Array): string {\n let out = \"\";\n for (let i = 0; i < bytes.length; i++) out = out + String.fromCharCode(bytes[i]!);\n return out;\n}\n";
79
+ export const enumIndexCodec = "\nfunction nscfMemberIndex(members: string[], value: string, what: string): number {\n for (let i = 0; i < members.length; i++) {\n if (members[i] === value) return i;\n }\n nscfTrap(\"a command carries an unknown \" + what + \" member — the SDK and this generated module disagree\");\n}\n";
80
+ export const commandEncoderPrefix = "\n// ---------------------------------------------------- the cmd wire\n// Encoder for the inert Cmd data the author's update returns —\n// byte-for-byte the layouts the host's command decoder expects\n// (cmd_format_version 10). nscfTagOf maps a Msg arm name onto its\n// declaration-order wire tag.\n\nconst nscfFetchMethods = [\"GET\", \"POST\", \"PUT\", \"DELETE\", \"PATCH\", \"HEAD\"];\nconst nscfAudioVerbs = [\"pause\", \"resume\", \"stop\", \"seek\", \"volume\"];\nconst nscfAudioCaptureSources = [\"microphone\", \"system\"];\nconst nscfVideoVerbs = [\"play\", \"pause\", \"stop\", \"seek\", \"volume\", \"muted\", \"loop\", \"restart\"];\n\n// Preserve the store err route for dynamic invalid limits. Writing a\n// fractional or out-of-u32 number directly into the byte sink would\n// truncate/wrap it into a different, potentially valid request. 257\n// is the host's stable over-bound sentinel (the public maximum is 256).\nfunction nscfStoreScanLimit(value: number): number {{\n return Number.isInteger(value) && value >= 0 && value <= 256 ? value : 257;\n}}\n\nfunction nscfWDbValue(sink: nscfSink, value: unknown): void {{\n if (value === null) {{\n nscfWU8(sink, 0);\n }} else if (typeof value === \"number\") {{\n nscfWU8(sink, 1);\n nscfWF64(sink, value);\n }} else if (typeof value === \"string\") {{\n nscfWU8(sink, 2);\n nscfWBytes(sink, nscfUtf8TextBytes(value));\n }} else if (typeof value === \"boolean\") {{\n nscfWU8(sink, 4);\n nscfWU8(sink, value ? 1 : 0);\n }} else if (value instanceof Uint8Array) {{\n nscfWU8(sink, 3);\n nscfWBytes(sink, value);\n }} else {{\n nscfWU8(sink, 2);\n const bytes = (value as nscfDbText).bytes;\n nscfWU32(sink, bytes.length);\n for (let i = 0; i < bytes.length; i++) sink.push(bytes[i]!);\n }}\n}}\n\nfunction nscfEncodeCmd(sink: nscfSink, cmd: nscfCmd<{s}>): void {{\n";
81
+ export const commandEncoderBody = " switch (cmd.op) {\n case \"none\":\n return;\n case \"persist\":\n nscfWU8(sink, 0x01);\n return;\n case \"wall_time\":\n nscfWU8(sink, 0x39); nscfWU8(sink, nscfTagOf(cmd.msgKind)); return;\n case \"cancel_key\":\n nscfWU8(sink, 0x06); nscfWShortBytes(sink, cmd.key); return;\n case \"read_file_result_key\":\n nscfWU8(sink, cmd.replace ? 0x37 : 0x3e); nscfWShortBytes(sink, cmd.key); nscfWU8(sink, nscfTagOf(cmd.resultKind)); nscfWBytes(sink, cmd.path); return;\n case \"write_file_result_key\":\n nscfWU8(sink, cmd.replace ? 0x38 : 0x3f); nscfWShortBytes(sink, cmd.key); nscfWU8(sink, nscfTagOf(cmd.resultKind)); nscfWBytes(sink, cmd.path); nscfWBytes(sink, cmd.bytes); return;\n case \"read_file_result\":\n nscfWU8(sink, cmd.replace ? 0x37 : 0x3e); nscfWShortText(sink, cmd.key); nscfWU8(sink, nscfTagOf(cmd.resultKind)); nscfWBytes(sink, cmd.path); return;\n case \"write_file_result\":\n nscfWU8(sink, cmd.replace ? 0x38 : 0x3f); nscfWShortText(sink, cmd.key); nscfWU8(sink, nscfTagOf(cmd.resultKind)); nscfWBytes(sink, cmd.path); nscfWBytes(sink, cmd.bytes); return;\n case \"timer_result_exact\":\n nscfWU8(sink, 0x40); nscfWShortText(sink, cmd.key); nscfWU8(sink, cmd.mode === \"repeating\" ? 1 : 0); nscfWBytes(sink, cmd.afterMs); nscfWU8(sink, nscfTagOf(cmd.msgKind)); return;\n case \"timer_result\":\n nscfWU8(sink, 0x3a); nscfWShortText(sink, cmd.key); nscfWU8(sink, cmd.mode === \"repeating\" ? 1 : 0); nscfWF64(sink, cmd.afterMs); nscfWU8(sink, nscfTagOf(cmd.msgKind)); return;\n case \"now\":\n nscfWU8(sink, 0x02);\n nscfWU8(sink, nscfTagOf(cmd.msgKind));\n return;\n case \"host\": {\n nscfWU8(sink, 0x03);\n nscfWShortText(sink, cmd.name);\n if (cmd.args.length > 255) {\n nscfTrap(\"a host command carries over 255 scalar args — the wire's arg block cannot carry it\");\n }\n nscfWU8(sink, cmd.args.length);\n for (let i = 0; i < cmd.args.length; i++) {\n nscfWF64(sink, cmd.args[i]!);\n }\n return;\n }\n case \"host_bytes\":\n nscfWU8(sink, 0x04);\n nscfWShortText(sink, cmd.name);\n nscfWBytes(sink, cmd.payload);\n return;\n case \"request\":\n nscfWU8(sink, 0x05);\n nscfWShortText(sink, cmd.name);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWU8(sink, cmd.typedService ? 1 : 0);\n nscfWBytes(sink, cmd.payload);\n return;\n case \"service_stream_request\":\n nscfWU8(sink, 0x28);\n nscfWF64(sink, cmd.channelKey);\n nscfWU8(sink, nscfTagOf(cmd.eventKind));\n nscfWU8(sink, cmd.maxPending);\n nscfWShortText(sink, cmd.name);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWBytes(sink, cmd.payload);\n return;\n case \"cancel\":\n nscfWU8(sink, 0x06);\n nscfWShortText(sink, cmd.key);\n return;\n case \"read_file\":\n nscfWU8(sink, 0x07);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWBytes(sink, cmd.path);\n return;\n case \"write_file\":\n nscfWU8(sink, 0x08);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWBytes(sink, cmd.path);\n nscfWBytes(sink, cmd.bytes);\n return;\n case \"append_file\":\n nscfWU8(sink, 0x2b);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWBytes(sink, cmd.path);\n nscfWBytes(sink, cmd.bytes);\n return;\n case \"stat_file\":\n nscfWU8(sink, 0x2c);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWBytes(sink, cmd.path);\n return;\n case \"delete_file\":\n nscfWU8(sink, 0x32);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWBytes(sink, cmd.path);\n return;\n case \"read_file_stream\":\n nscfWU8(sink, 0x2d);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.chunkKind));\n nscfWU8(sink, nscfTagOf(cmd.doneKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWBytes(sink, cmd.path);\n return;\n case \"write_file_stream\":\n nscfWU8(sink, 0x2e);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWBytes(sink, cmd.path);\n return;\n case \"write_file_chunk\":\n nscfWU8(sink, 0x2f);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWBytes(sink, cmd.bytes);\n return;\n case \"write_file_close\":\n nscfWU8(sink, 0x30);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n return;\n case \"fetch\": {\n nscfWU8(sink, 0x09);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWU8(sink, nscfMemberIndex(nscfFetchMethods, cmd.method, \"fetch method\"));\n nscfWU32(sink, cmd.timeoutMs);\n nscfWBytes(sink, cmd.url);\n if (cmd.headers.length > 255) {\n nscfTrap(\"a fetch carries over 255 headers — the wire's header block cannot carry it\");\n }\n nscfWU8(sink, cmd.headers.length);\n for (let i = 0; i < cmd.headers.length; i++) {\n const header = cmd.headers[i]!;\n nscfWShortText(sink, header.name);\n const value = header.value;\n nscfWBytes(sink, typeof value === \"string\" ? nscfTextBytes(value) : value);\n }\n nscfWBytes(sink, cmd.body);\n return;\n }\n case \"clip_write\":\n nscfWU8(sink, 0x0a);\n nscfWBytes(sink, cmd.bytes);\n return;\n case \"clip_write_result\":\n nscfWU8(sink, 0x34);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.resultKind));\n nscfWBytes(sink, cmd.bytes);\n return;\n case \"video_snapshot\":\n nscfWU8(sink, 0x35);\n nscfWU8(sink, nscfTagOf(cmd.snapshotKind));\n return;\n case \"clip_read\":\n nscfWU8(sink, 0x0b);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n return;\n case \"delay\":\n nscfWU8(sink, 0x0c);\n nscfWShortText(sink, cmd.key);\n nscfWF64(sink, cmd.afterMs);\n nscfWU8(sink, nscfTagOf(cmd.msgKind));\n return;\n case \"cancel_exact\":\n nscfWU8(sink, 0x47); nscfWBytes(sink, cmd.key); return;\n case \"spawn_events_exact\":\n if (cmd.argv.length > 255) nscfTrap(\"an exact spawn carries over 255 argv entries\");\n nscfWU8(sink, 0x46); nscfWBytes(sink, cmd.key);\n nscfWU8(sink, cmd.lineKind === \"\" ? 255 : nscfTagOf(cmd.lineKind));\n nscfWU8(sink, nscfTagOf(cmd.exitKind)); nscfWU8(sink, cmd.collect ? 1 : 0);\n nscfWU8(sink, cmd.argv.length);\n for (let i = 0; i < cmd.argv.length; i++) nscfWBytes(sink, cmd.argv[i]!);\n nscfWBytes(sink, cmd.stdin); return;\n case \"spawn_events\": {\n nscfWU8(sink, 0x33);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, cmd.lineKind === \"\" ? 0xff : nscfTagOf(cmd.lineKind));\n nscfWU8(sink, nscfTagOf(cmd.exitKind));\n nscfWU8(sink, cmd.collect ? 1 : 0);\n if (cmd.argv.length === 0 || cmd.argv.length > 255) nscfTrap(\"invalid spawn argv count\");\n nscfWU8(sink, cmd.argv.length);\n for (let i = 0; i < cmd.argv.length; i++) nscfWBytes(sink, cmd.argv[i]!);\n nscfWBytes(sink, cmd.stdin);\n return;\n }\n case \"spawn\": {\n nscfWU8(sink, 0x0d);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, cmd.lineKind === \"\" ? 0xff : nscfTagOf(cmd.lineKind));\n nscfWU8(sink, nscfTagOf(cmd.exitKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWU8(sink, cmd.collect ? 1 : 0);\n if (cmd.argv.length === 0 || cmd.argv.length > 255) {\n nscfTrap(\"a spawn carries no argv or over 255 argv entries — the wire's argv block cannot carry it\");\n }\n nscfWU8(sink, cmd.argv.length);\n for (let i = 0; i < cmd.argv.length; i++) {\n nscfWBytes(sink, cmd.argv[i]!);\n }\n nscfWBytes(sink, cmd.stdin);\n return;\n }\n case \"audio_play\":\n nscfWU8(sink, 0x0e);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.eventKind));\n nscfWBytes(sink, cmd.path);\n nscfWBytes(sink, cmd.url);\n nscfWBytes(sink, cmd.cachePath);\n nscfWF64(sink, cmd.expectedBytes);\n return;\n case \"audio_play_exact\":\n nscfWU8(sink, 0x42);\n nscfWBytes(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.eventKind));\n nscfWBytes(sink, cmd.path);\n nscfWBytes(sink, cmd.url);\n nscfWBytes(sink, cmd.cachePath);\n nscfWBytes(sink, cmd.cacheDir);\n nscfWF64(sink, cmd.expectedBytes);\n return;\n case \"audio_transport\": {\n const transport = cmd.transport;\n nscfWU8(sink, 0x43);\n nscfWU8(sink, nscfMemberIndex(nscfAudioVerbs, transport.kind === \"play\" ? \"resume\" : transport.kind, \"audio transport verb\"));\n if (transport.kind === \"seek\") nscfWBytes(sink, transport.positionMs);\n if (transport.kind === \"volume\") nscfWF64(sink, transport.value);\n return;\n }\n case \"audio_ctl\":\n nscfWU8(sink, 0x0f);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfMemberIndex(nscfAudioVerbs, cmd.verb, \"audio verb\"));\n nscfWF64(sink, cmd.value);\n return;\n case \"window_show\":\n nscfWU8(sink, 0x10);\n nscfWShortText(sink, cmd.label);\n return;\n case \"window_hide\":\n nscfWU8(sink, 0x21);\n nscfWShortText(sink, cmd.label);\n return;\n case \"window_close\":\n case \"window_minimize\":\n nscfWU8(sink, cmd.op === \"window_close\" ? 0x44 : 0x45);\n nscfWShortBytes(sink, nscfUtf8TextBytes(cmd.label));\n return;\n case \"dock_presence\":\n nscfWU8(sink, 0x22);\n nscfWU8(sink, cmd.visible ? 1 : 0);\n return;\n case \"store_set\":\n nscfWU8(sink, 0x23);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWU32(sink, 0);\n nscfWBytes(sink, nscfUtf8TextBytes(cmd.storeKey));\n nscfWBytes(sink, cmd.bytes);\n return;\n case \"store_get\":\n case \"store_delete\":\n nscfWU8(sink, cmd.op === \"store_get\" ? 0x24 : 0x25);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWU32(sink, 0);\n nscfWBytes(sink, nscfUtf8TextBytes(cmd.storeKey));\n return;\n case \"store_scan\":\n nscfWU8(sink, 0x26);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWU32(sink, 0);\n nscfWBytes(sink, nscfUtf8TextBytes(cmd.prefix));\n nscfWU32(sink, nscfStoreScanLimit(cmd.limit));\n nscfWBytes(sink, typeof cmd.after === \"string\" ? nscfUtf8TextBytes(cmd.after) : cmd.after);\n return;\n case \"store_set_many\":\n nscfWU8(sink, 0x27);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWU32(sink, 0);\n nscfWU32(sink, cmd.entries.length);\n for (let i = 0; i < cmd.entries.length; i++) {\n nscfWBytes(sink, nscfUtf8TextBytes(cmd.entries[i]![0]));\n nscfWBytes(sink, cmd.entries[i]![1]);\n }\n return;\n case \"db_query\":\n nscfWU8(sink, 0x29);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.pageKind));\n nscfWU8(sink, nscfTagOf(cmd.doneKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWBytes(sink, nscfUtf8TextBytes(cmd.sql));\n nscfWU32(sink, cmd.params.length);\n for (let i = 0; i < cmd.params.length; i++) nscfWDbValue(sink, cmd.params[i]!);\n return;\n case \"db_exec\":\n nscfWU8(sink, 0x2a);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWU32(sink, cmd.statements.length);\n for (let i = 0; i < cmd.statements.length; i++) {\n const statement = cmd.statements[i]!;\n nscfWBytes(sink, nscfUtf8TextBytes(statement[0]));\n nscfWU32(sink, statement[1].length);\n for (let j = 0; j < statement[1].length; j++) nscfWDbValue(sink, statement[1][j]!);\n }\n return;\n case \"quit_app\":\n nscfWU8(sink, 0x11);\n return;\n case \"image_load_words\":\n case \"image_cancel_words\":\n case \"image_unregister_words\": {\n const id = cmd.identity;\n if (!Number.isInteger(id.imageLower) || !Number.isInteger(id.imageUpper) || id.imageLower < 0 || id.imageLower > 4294967295 || id.imageUpper < 0 || id.imageUpper > 4294967295) nscfTrap(\"image identity words must be unsigned 32-bit integers\");\n nscfWU8(sink, cmd.op === \"image_load_words\" ? 0x3b : cmd.op === \"image_cancel_words\" ? 0x3c : 0x3d);\n nscfWU32(sink, id.imageLower); nscfWU32(sink, id.imageUpper);\n if (cmd.op === \"image_load_words\") {\n nscfWU8(sink, nscfTagOf(cmd.eventKind)); nscfWBytes(sink, cmd.path); nscfWBytes(sink, cmd.url); nscfWBytes(sink, cmd.cachePath); nscfWF64(sink, cmd.expectedBytes);\n }\n return;\n }\n case \"image_load\":\n nscfWU8(sink, 0x12);\n nscfWF64(sink, cmd.id);\n nscfWU8(sink, nscfTagOf(cmd.eventKind));\n nscfWBytes(sink, cmd.path);\n nscfWBytes(sink, cmd.url);\n nscfWBytes(sink, cmd.cachePath);\n nscfWF64(sink, cmd.expectedBytes);\n return;\n case \"image_cancel\":\n nscfWU8(sink, 0x13);\n nscfWF64(sink, cmd.id);\n return;\n case \"image_unregister\":\n nscfWU8(sink, 0x14);\n nscfWF64(sink, cmd.id);\n return;\n case \"channel_open\":\n nscfWU8(sink, 0x15);\n nscfWF64(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.eventKind));\n nscfWU8(sink, cmd.maxPending);\n return;\n case \"channel_open_source\": {\n const sourceBytes = nscfUtf8TextBytes(cmd.source);\n if (sourceBytes.length === 0 || sourceBytes.length > 255 || cmd.payload.length > 4096) nscfTrap(\"invalid channel source arguments\");\n nscfWU8(sink, 0x41); nscfWF64(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.eventKind)); nscfWU8(sink, nscfTagOf(cmd.startedKind)); nscfWU8(sink, cmd.maxPending);\n nscfWShortText(sink, cmd.source); nscfWBytes(sink, cmd.payload); return;\n }\n case \"channel_close\":\n nscfWU8(sink, 0x16);\n nscfWF64(sink, cmd.key);\n return;\n case \"video_load\": {\n nscfWU8(sink, 0x17);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.eventKind));\n nscfWF64(sink, cmd.surface);\n nscfWBytes(sink, cmd.path);\n nscfWBytes(sink, cmd.url);\n // Wire flags: bit0 = autoplay, bit1 = loop, bit2 = muted.\n let flags = 0;\n if (cmd.autoplay) flags = flags + 1;\n if (cmd.loop) flags = flags + 2;\n if (cmd.muted) flags = flags + 4;\n nscfWU8(sink, flags);\n return;\n }\n case \"video_ctl\":\n nscfWU8(sink, 0x18);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfMemberIndex(nscfVideoVerbs, cmd.verb, \"video verb\"));\n nscfWF64(sink, cmd.value);\n return;\n case \"pty_spawn\": {\n nscfWU8(sink, 0x19);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.eventKind));\n nscfWF64(sink, cmd.cols);\n nscfWF64(sink, cmd.rows);\n nscfWShortText(sink, cmd.term);\n if (cmd.argv.length === 0 || cmd.argv.length > 255) {\n nscfTrap(\"a pty spawn carries no argv or over 255 argv entries — the wire's argv block cannot carry it\");\n }\n nscfWU8(sink, cmd.argv.length);\n for (let i = 0; i < cmd.argv.length; i++) {\n nscfWBytes(sink, cmd.argv[i]!);\n }\n return;\n }\n case \"pty_write\":\n nscfWU8(sink, 0x1a);\n nscfWShortText(sink, cmd.key);\n nscfWBytes(sink, cmd.bytes);\n return;\n case \"pty_resize\":\n nscfWU8(sink, 0x1b);\n nscfWShortText(sink, cmd.key);\n nscfWF64(sink, cmd.cols);\n nscfWF64(sink, cmd.rows);\n return;\n case \"pty_kill\":\n nscfWU8(sink, 0x1c);\n nscfWShortText(sink, cmd.key);\n return;\n case \"show_notification\":\n if (cmd.id.length === 0 && cmd.actionLabel.length === 0 && cmd.actionCommand.length === 0) {\n nscfWU8(sink, 0x1d);\n nscfWBytes(sink, cmd.title);\n nscfWBytes(sink, cmd.subtitle);\n nscfWBytes(sink, cmd.body);\n } else {\n nscfWU8(sink, 0x31);\n nscfWBytes(sink, cmd.id);\n nscfWBytes(sink, cmd.title);\n nscfWBytes(sink, cmd.subtitle);\n nscfWBytes(sink, cmd.body);\n nscfWBytes(sink, cmd.actionLabel);\n nscfWBytes(sink, cmd.actionCommand);\n }\n return;\n case \"audio_capture_start\":\n nscfWU8(sink, 0x1e);\n nscfWF64(sink, cmd.key);\n nscfWU8(sink, nscfMemberIndex(nscfAudioCaptureSources, cmd.source, \"audio capture source\"));\n nscfWU32(sink, cmd.sampleRate);\n nscfWU8(sink, cmd.channels);\n nscfWU8(sink, nscfTagOf(cmd.eventKind));\n return;\n case \"audio_capture_stop\":\n nscfWU8(sink, 0x1f);\n nscfWF64(sink, cmd.key);\n return;\n case \"fetch_stream\": {\n nscfWU8(sink, 0x20);\n nscfWShortText(sink, cmd.key);\n nscfWU8(sink, nscfTagOf(cmd.lineKind));\n nscfWU8(sink, nscfTagOf(cmd.okKind));\n nscfWU8(sink, nscfTagOf(cmd.errKind));\n nscfWU8(sink, nscfMemberIndex(nscfFetchMethods, cmd.method, \"fetch method\"));\n nscfWU32(sink, cmd.timeoutMs);\n nscfWU32(sink, cmd.maxLineBytes);\n nscfWBytes(sink, cmd.url);\n if (cmd.headers.length > 255) {\n nscfTrap(\"a fetch carries over 255 headers — the wire's header block cannot carry it\");\n }\n nscfWU8(sink, cmd.headers.length);\n for (let i = 0; i < cmd.headers.length; i++) {\n const header = cmd.headers[i]!;\n nscfWShortText(sink, header.name);\n const value = header.value;\n nscfWBytes(sink, typeof value === \"string\" ? nscfTextBytes(value) : value);\n }\n nscfWBytes(sink, cmd.body);\n return;\n }\n case \"batch\":\n for (let i = 0; i < cmd.cmds.length; i++) {\n nscfEncodeCmd(sink, cmd.cmds[i]!);\n }\n return;\n }\n}\n";
82
+ export const commandEncoderSuffix = "\nfunction nscfCmdBytes(cmd: nscfCmd<{s}>): Uint8Array {{\n const sink = nscfNewSink();\n nscfEncodeCmd(sink, cmd);\n return nscfFinish(sink);\n}}\n";
83
+ export const subscriptionEncoder = "\n// The v3 subscription wire: repeating timers and build-time\n// checked live relational queries.\nfunction nscfWSubDbValue(sink: nscfSink, value: unknown): void {{\n if (value === null) {{\n nscfWU8(sink, 0);\n }} else if (typeof value === \"number\") {{\n nscfWU8(sink, 1);\n nscfWF64(sink, value);\n }} else if (typeof value === \"string\") {{\n nscfWU8(sink, 2);\n nscfWBytes(sink, nscfUtf8TextBytes(value));\n }} else if (typeof value === \"boolean\") {{\n nscfWU8(sink, 4);\n nscfWU8(sink, value ? 1 : 0);\n }} else if (value instanceof Uint8Array) {{\n nscfWU8(sink, 3);\n nscfWBytes(sink, value);\n }} else {{\n nscfWU8(sink, 2);\n const bytes = (value as nscfDbText).bytes;\n nscfWU32(sink, bytes.length);\n for (let i = 0; i < bytes.length; i++) sink.push(bytes[i]!);\n }}\n}}\n\nfunction nscfEncodeSub(sink: nscfSink, sub: nscfSub<{s}>): void {{\n switch (sub.op) {{\n case \"none\":\n return;\n case \"timer\":\n nscfWU8(sink, 0x01);\n nscfWShortText(sink, sub.key);\n nscfWF64(sink, sub.everyMs);\n nscfWU8(sink, nscfTagOf(sub.msgKind));\n return;\n case \"global_shortcut\":\n nscfWU8(sink, 0x03);\n nscfWShortText(sink, sub.id);\n nscfWBytes(sink, sub.key);\n nscfWU8(sink, sub.modifiers);\n nscfWU8(sink, nscfTagOf(sub.msgKind));\n return;\n case \"db_live\":\n nscfWU8(sink, 0x02);\n nscfWShortText(sink, sub.key);\n nscfWU8(sink, nscfTagOf(sub.pageKind));\n nscfWU8(sink, nscfTagOf(sub.doneKind));\n nscfWU8(sink, nscfTagOf(sub.errKind));\n nscfWBytes(sink, nscfUtf8TextBytes(sub.sql));\n nscfWU32(sink, sub.params.length);\n for (let i = 0; i < sub.params.length; i++) nscfWSubDbValue(sink, sub.params[i]!);\n nscfWU32(sink, sub.tables.length);\n for (let i = 0; i < sub.tables.length; i++) nscfWShortText(sink, sub.tables[i]!);\n return;\n case \"batch\":\n for (let i = 0; i < sub.subs.length; i++) {{\n nscfEncodeSub(sink, sub.subs[i]!);\n }}\n return;\n }}\n}}\n\nfunction nscfSubBytes(sub: nscfSub<{s}>): Uint8Array {{\n const sink = nscfNewSink();\n nscfEncodeSub(sink, sub);\n return nscfFinish(sink);\n}}\n";
84
+
85
+ export const frameEntryNs = "\nexport function abi_frame_msg_ns(width: number, height: number, timestampMs: number, intervalMs: number, timestampNs: Uint8Array, intervalNs: Uint8Array): Uint8Array {\n const frame = { width, height, timestampMs, intervalMs, timestampNs, intervalNs };\n return nscfPackMsg(nscfChanFrameMsg(nscfCommitted, frame));\n}\n// Legacy hosts retain the four-number entry. Exact clocks are unavailable\n// through that entry; the matching generated host uses frame_msg_ns.\nexport function abi_frame_msg(width: number, height: number, timestampMs: number, intervalMs: number): Uint8Array {\n return abi_frame_msg_ns(width, height, timestampMs, intervalMs, new Uint8Array(0), new Uint8Array(0));\n}\n";