@native-sdk/cli 0.5.3 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/build/app.zig +91 -2
  2. package/build.zig +756 -5
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +19 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +416 -9
  9. package/packages/core/sdk/core.ts +706 -5
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +3187 -264
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +42 -4
  17. package/skill-data/ts-core/SKILL.md +13 -3
  18. package/src/app_runner/root.zig +112 -10
  19. package/src/app_runner/ts_core_main.zig +4 -0
  20. package/src/automation/layout_fingerprint.zig +160 -0
  21. package/src/automation/protocol.zig +82 -33
  22. package/src/automation/root.zig +1 -0
  23. package/src/automation/server.zig +1 -1
  24. package/src/automation/snapshot.zig +68 -9
  25. package/src/automation/watcher.zig +1 -1
  26. package/src/embed/host.zig +5 -0
  27. package/src/embed/tests.zig +119 -1
  28. package/src/embed/ui_host.zig +13 -0
  29. package/src/platform/linux/gtk_host.c +639 -16
  30. package/src/platform/linux/gtk_host.h +25 -0
  31. package/src/platform/linux/root.zig +351 -7
  32. package/src/platform/macos/appkit_host.h +152 -8
  33. package/src/platform/macos/appkit_host.m +1816 -100
  34. package/src/platform/macos/cef_host.mm +372 -11
  35. package/src/platform/macos/root.zig +379 -11
  36. package/src/platform/null_platform.zig +696 -9
  37. package/src/platform/null_platform_tests.zig +35 -0
  38. package/src/platform/root.zig +42 -0
  39. package/src/platform/types.zig +524 -18
  40. package/src/platform/windows/root.zig +432 -9
  41. package/src/platform/windows/webview2_host.cpp +482 -45
  42. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  43. package/src/primitives/app_manifest/root.zig +1 -0
  44. package/src/primitives/app_manifest/types.zig +32 -0
  45. package/src/primitives/app_manifest/validation.zig +18 -0
  46. package/src/primitives/canvas/a11y_audit.zig +33 -11
  47. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  48. package/src/primitives/canvas/drawing.zig +25 -0
  49. package/src/primitives/canvas/equality.zig +8 -0
  50. package/src/primitives/canvas/events.zig +103 -16
  51. package/src/primitives/canvas/frame.zig +125 -1
  52. package/src/primitives/canvas/layout_audit.zig +22 -5
  53. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  54. package/src/primitives/canvas/render_tests.zig +13 -10
  55. package/src/primitives/canvas/root.zig +48 -0
  56. package/src/primitives/canvas/terminal_box.zig +471 -0
  57. package/src/primitives/canvas/terminal_grid.zig +978 -0
  58. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  59. package/src/primitives/canvas/test_support.zig +1 -0
  60. package/src/primitives/canvas/tests.zig +2 -0
  61. package/src/primitives/canvas/text_tests.zig +39 -4
  62. package/src/primitives/canvas/tokens.zig +115 -12
  63. package/src/primitives/canvas/ui.zig +535 -12
  64. package/src/primitives/canvas/ui_markup.zig +253 -36
  65. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  66. package/src/primitives/canvas/ui_markup_compiled.zig +195 -9
  67. package/src/primitives/canvas/ui_markup_compiled_tests.zig +188 -8
  68. package/src/primitives/canvas/ui_markup_contract.zig +89 -6
  69. package/src/primitives/canvas/ui_markup_contract_tests.zig +65 -1
  70. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  71. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  72. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  73. package/src/primitives/canvas/ui_markup_tests.zig +178 -9
  74. package/src/primitives/canvas/ui_markup_view.zig +220 -11
  75. package/src/primitives/canvas/ui_markup_view_tests.zig +553 -28
  76. package/src/primitives/canvas/ui_schema.zig +110 -17
  77. package/src/primitives/canvas/ui_schema_tests.zig +18 -10
  78. package/src/primitives/canvas/ui_tests.zig +141 -9
  79. package/src/primitives/canvas/widget_access.zig +28 -2
  80. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  81. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  82. package/src/primitives/canvas/widget_layout.zig +59 -11
  83. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  84. package/src/primitives/canvas/widget_render.zig +272 -18
  85. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  86. package/src/primitives/canvas/widget_routing.zig +59 -7
  87. package/src/primitives/canvas/widget_runtime.zig +23 -0
  88. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  89. package/src/primitives/canvas/widget_semantics.zig +119 -11
  90. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  91. package/src/primitives/canvas/widget_tree.zig +17 -0
  92. package/src/primitives/canvas/widgets.zig +132 -0
  93. package/src/root.zig +23 -0
  94. package/src/runtime/api.zig +76 -5
  95. package/src/runtime/automation_commands.zig +20 -1
  96. package/src/runtime/automation_snapshot.zig +25 -1
  97. package/src/runtime/automation_widget_dispatch.zig +73 -8
  98. package/src/runtime/bridge_payload.zig +8 -0
  99. package/src/runtime/bridge_responses.zig +5 -0
  100. package/src/runtime/builtin_bridge.zig +9 -4
  101. package/src/runtime/canvas_font_tests.zig +439 -2
  102. package/src/runtime/canvas_fonts.zig +61 -6
  103. package/src/runtime/canvas_frame.zig +62 -7
  104. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  105. package/src/runtime/canvas_frame_helpers.zig +190 -1
  106. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  107. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  108. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  109. package/src/runtime/canvas_image_tests.zig +195 -0
  110. package/src/runtime/canvas_images.zig +45 -12
  111. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  112. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  113. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  114. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  115. package/src/runtime/canvas_widget_display.zig +1 -1
  116. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  117. package/src/runtime/canvas_widget_events.zig +240 -24
  118. package/src/runtime/canvas_widget_runtime.zig +213 -29
  119. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  120. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  121. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  122. package/src/runtime/canvas_widget_state.zig +6 -0
  123. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  124. package/src/runtime/core.zig +131 -13
  125. package/src/runtime/effects.zig +8136 -180
  126. package/src/runtime/effects_channel_tests.zig +3519 -0
  127. package/src/runtime/effects_fetch_tests.zig +89 -1
  128. package/src/runtime/effects_file_tests.zig +41 -1
  129. package/src/runtime/effects_image_tests.zig +1304 -0
  130. package/src/runtime/effects_pty_tests.zig +1362 -0
  131. package/src/runtime/effects_tests.zig +167 -9
  132. package/src/runtime/effects_video_tests.zig +3609 -0
  133. package/src/runtime/flow.zig +42 -4
  134. package/src/runtime/gpu_surface_events.zig +473 -13
  135. package/src/runtime/media_surface.zig +116 -11
  136. package/src/runtime/media_surface_tests.zig +61 -0
  137. package/src/runtime/pty.zig +1252 -0
  138. package/src/runtime/pty_windows.zig +1780 -0
  139. package/src/runtime/root.zig +36 -0
  140. package/src/runtime/runtime_event_tests.zig +20 -1
  141. package/src/runtime/session_blobs.zig +689 -0
  142. package/src/runtime/session_journal.zig +432 -62
  143. package/src/runtime/session_record.zig +43 -2
  144. package/src/runtime/session_replay.zig +556 -20
  145. package/src/runtime/session_tests.zig +2087 -1
  146. package/src/runtime/shell_layout.zig +7 -0
  147. package/src/runtime/terminal_session.zig +1569 -0
  148. package/src/runtime/terminal_session_tests.zig +450 -0
  149. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  150. package/src/runtime/terminal_vt_stub.zig +13 -0
  151. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  152. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  153. package/src/runtime/tests.zig +8 -0
  154. package/src/runtime/ts_core_host.zig +1320 -45
  155. package/src/runtime/ts_core_host_tests.zig +1100 -1
  156. package/src/runtime/ts_ui_app.zig +23 -5
  157. package/src/runtime/ui_app.zig +2444 -69
  158. package/src/runtime/ui_app_tests.zig +3171 -744
  159. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  160. package/src/runtime/ui_app_window_tests.zig +736 -0
  161. package/src/runtime/view.zig +190 -2
  162. package/src/runtime/view_widget_scroll.zig +218 -68
  163. package/src/runtime/view_widget_text.zig +11 -2
  164. package/src/runtime/view_widget_tree.zig +111 -3
  165. package/src/runtime/window_command_bridge_tests.zig +117 -0
  166. package/src/runtime/window_storage.zig +77 -2
  167. package/src/runtime/window_view_runtime.zig +34 -2
  168. package/src/runtime/window_views.zig +62 -1
  169. package/src/terminal_session_tests_root.zig +15 -0
  170. package/src/tooling/manifest.zig +75 -0
  171. package/src/tooling/raw_manifest.zig +2 -0
  172. package/src/tooling/templates.zig +244 -8
package/build.zig.zon CHANGED
@@ -3,6 +3,13 @@
3
3
  .fingerprint = 0xc309966142f33087,
4
4
  .version = "0.1.0",
5
5
  .minimum_zig_version = "0.16.0",
6
+ // No dependencies. The terminal emulator (libghostty-vt) is
7
+ // deliberately NOT pinned here: a pin in this file is materialized
8
+ // into every consumer's package directory even when lazy and
9
+ // unused. Apps that want live `<terminal>` sessions pin it in their
10
+ // own build.zig.zon and ask for it with
11
+ // `addAppArtifacts(.{ .terminal_sessions = true })` — see
12
+ // examples/workbench, which also owns that path's test coverage.
6
13
  .dependencies = .{},
7
14
  .paths = .{
8
15
  "README.md",
package/native-sdk.d.ts CHANGED
@@ -25,6 +25,8 @@ export interface NativeSdkWindowInfo {
25
25
  title: string;
26
26
  open: boolean;
27
27
  focused: boolean;
28
+ /** Alive but hidden by `close_policy = "hide"` — still open, not focused, invisible until re-shown. */
29
+ hidden: boolean;
28
30
  x: number;
29
31
  y: number;
30
32
  width: number;
@@ -419,7 +421,23 @@ export type NativeSdkPlatformFeature =
419
421
  | "app_activation_events"
420
422
  | "appActivationEvents"
421
423
  | "gpu_surfaces"
422
- | "gpuSurfaces";
424
+ | "gpuSurfaces"
425
+ | "gpu_surface_scroll_drivers"
426
+ | "gpuSurfaceScrollDrivers"
427
+ | "context_menus"
428
+ | "contextMenus"
429
+ | "view_surface_adoption"
430
+ | "viewSurfaceAdoption"
431
+ | "audio_playback"
432
+ | "audioPlayback"
433
+ | "audio_streaming"
434
+ | "audioStreaming"
435
+ | "audio_spectrum"
436
+ | "audioSpectrum"
437
+ | "window_hide_on_close"
438
+ | "windowHideOnClose"
439
+ | "video_playback"
440
+ | "videoPlayback";
423
441
 
424
442
  export type NativeSdkPlatformFeatureSelector =
425
443
  | { feature: NativeSdkPlatformFeature; name?: never }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,14 +32,14 @@
32
32
  "@typescript/typescript6": "6.0.2"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@native-sdk/cli-darwin-arm64": "0.5.3",
36
- "@native-sdk/cli-darwin-x64": "0.5.3",
37
- "@native-sdk/cli-linux-arm64-gnu": "0.5.3",
38
- "@native-sdk/cli-linux-arm64-musl": "0.5.3",
39
- "@native-sdk/cli-linux-x64-gnu": "0.5.3",
40
- "@native-sdk/cli-linux-x64-musl": "0.5.3",
41
- "@native-sdk/cli-win32-arm64": "0.5.3",
42
- "@native-sdk/cli-win32-x64": "0.5.3"
35
+ "@native-sdk/cli-darwin-arm64": "0.6.0",
36
+ "@native-sdk/cli-darwin-x64": "0.6.0",
37
+ "@native-sdk/cli-linux-arm64-gnu": "0.6.0",
38
+ "@native-sdk/cli-linux-arm64-musl": "0.6.0",
39
+ "@native-sdk/cli-linux-x64-gnu": "0.6.0",
40
+ "@native-sdk/cli-linux-x64-musl": "0.6.0",
41
+ "@native-sdk/cli-win32-arm64": "0.6.0",
42
+ "@native-sdk/cli-win32-x64": "0.6.0"
43
43
  },
44
44
  "repository": {
45
45
  "type": "git",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@native-sdk/core",
9
- "version": "0.5.3",
9
+ "version": "0.6.0",
10
10
  "devDependencies": {
11
11
  "@typescript/old": "npm:typescript@6.0.3",
12
12
  "@typescript/typescript6": "6.0.2"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.5.3",
3
+ "version": "0.6.0",
4
4
  "description": "The TypeScript authoring tier: the app-core subset, its dev-time transpiler to arena-backed Zig, and the SDK module cores import",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1015,7 +1015,7 @@ pub fn Kernel(comptime opts: Options) type {
1015
1015
 
1016
1016
  // -------------------------------------------------------- commands
1017
1017
  //
1018
- // Cmd wire format v2 — the byte encoding of the command value an effectful
1018
+ // Cmd wire format v3 — the byte encoding of the command value an effectful
1019
1019
  // `update` (or a pair-returning `initialModel`) returns alongside the next
1020
1020
  // model (`UpdateResult.cmd` / `InitResult.cmd` in emitted cores). A command
1021
1021
  // value is a flat sequence of op records; the empty slice means "no
@@ -1052,12 +1052,39 @@ pub fn Kernel(comptime opts: Options) type {
1052
1052
  // [path_len u32 LE][path][url_len u32 LE][url]
1053
1053
  // [cache_len u32 LE][cache_path][expected_bytes f64 LE]
1054
1054
  // audio_ctl [op 0x0F][key_len u8][key bytes][verb u8][value f64 LE]
1055
+ // window_show [op 0x10][label_len u8][label bytes]
1056
+ // quit_app [op 0x11]
1057
+ // image_load [op 0x12][id f64 LE][event_tag u8]
1058
+ // [path_len u32 LE][path][url_len u32 LE][url]
1059
+ // [cache_len u32 LE][cache_path][expected_bytes f64 LE]
1060
+ // image_cancel [op 0x13][id f64 LE]
1061
+ // image_unregister [op 0x14][id f64 LE]
1062
+ // channel_open [op 0x15][key f64 LE][event_tag u8]
1063
+ // channel_close [op 0x16][key f64 LE]
1064
+ // video_load [op 0x17][key_len u8][key][event_tag u8]
1065
+ // [surface f64 LE][path_len u32 LE][path]
1066
+ // [url_len u32 LE][url][flags u8]
1067
+ // (flags bit0 = autoplay, bit1 = loop, bit2 = muted)
1068
+ // video_ctl [op 0x18][key_len u8][key][verb u8][value f64 LE]
1069
+ // pty_spawn [op 0x19][key_len u8][key bytes][event_tag u8]
1070
+ // [cols f64 LE][rows f64 LE][term_len u8][term bytes]
1071
+ // then [argc u8] and per argv element:
1072
+ // [arg_len u32 LE][arg bytes]
1073
+ // pty_write [op 0x1A][key_len u8][key bytes][bytes_len u32 LE][bytes]
1074
+ // pty_resize [op 0x1B][key_len u8][key bytes][cols f64 LE][rows f64 LE]
1075
+ // pty_kill [op 0x1C][key_len u8][key bytes]
1055
1076
  //
1056
1077
  // v2 is additive over v1: the 0x01-0x03 records are byte-identical to v1,
1057
1078
  // so a v1 effect log replays under a v2 reader unchanged. The named-op
1058
1079
  // records 0x07-0x0C are additive within v2 the same way, and so are the
1059
1080
  // streaming records 0x0D-0x0F: no existing record's bytes change, new
1060
- // opcodes only.
1081
+ // opcodes only. v3 appends the window-verb records 0x10-0x11 under the
1082
+ // same rule, and the image records 0x12-0x14, channel records
1083
+ // 0x15-0x16, and pty records 0x19-0x1C are additive within v3
1084
+ // the same way: every existing record is byte-identical, new opcodes
1085
+ // only (a host predating an opcode refuses it loudly, naming this
1086
+ // version). The video records 0x17-0x18 join additively under
1087
+ // the same rule.
1061
1088
  //
1062
1089
  // `method` is the closed HTTP verb set in declaration order of `CmdFetchMethod`
1063
1090
  // (GET 0, POST 1, PUT 2, DELETE 3, PATCH 4, HEAD 5). `timeout_ms` 0 means
@@ -1168,6 +1195,134 @@ pub fn Kernel(comptime opts: Options) type {
1168
1195
  // magnitudes, all zeros outside `.spectrum` events).
1169
1196
  // Failure is never silent: an unplayable source is one
1170
1197
  // `.failed` event, a refused command one `.rejected`.
1198
+ // image_load a routed one-shot image load, keyed by the app's own
1199
+ // numeric ImageId (`id`, an f64-carried positive integer
1200
+ // — the SAME model-owned id markup binds via
1201
+ // <image image="{id}"/> / <avatar image="{id}"/>):
1202
+ // resolve the source cascade (local `path` first, then a
1203
+ // verified cache entry at `cache_path`, then `url` —
1204
+ // audio_play's resolution order; `expected_bytes` is the
1205
+ // cache integrity gate, 0 = unknown), decode through the
1206
+ // platform codec, register the pixels under the id, and
1207
+ // dispatch exactly ONE `event_tag` arm — a five-field
1208
+ // record built by name: `id` (a number, the requested
1209
+ // ImageId echoed verbatim so concurrent loads sharing
1210
+ // one arm stay distinguishable; an id the wire cannot
1211
+ // carry exactly echoes 0), `state` (an enum whose
1212
+ // members are exactly the fifteen image outcome names,
1213
+ // matched by member NAME), width and height (numbers,
1214
+ // the decoded dimensions on "loaded"), and status
1215
+ // (number, the HTTP status for url loads that
1216
+ // performed an exchange; 0 when none occurred —
1217
+ // local paths, cache hits — so a cached "loaded"
1218
+ // is distinguishable from a network one). One load
1219
+ // per id at a time: a duplicate live id dispatches
1220
+ // "rejected" (the spawn discipline — a load in flight
1221
+ // is never replaced implicitly).
1222
+ // image_cancel end the in-flight load under `id`, if any, LOUDLY:
1223
+ // the load's one terminal arrives as its own event arm
1224
+ // with state "cancelled" (ending an in-flight load is
1225
+ // an observable event, spawn's cancel discipline), and
1226
+ // the id is free for a fresh load once that terminal
1227
+ // lands. Aimed at an id with no live load — or one the
1228
+ // wire cannot carry exactly — it is a no-op, the same
1229
+ // idle no-op audio_ctl keeps: whatever it aimed at is
1230
+ // already gone. Image loads are keyed by their numeric
1231
+ // id, so the string-keyed `cancel` record never
1232
+ // touches them.
1233
+ // image_unregister
1234
+ // free the registry slot under `id`: the pixels are
1235
+ // released, views referencing the id draw their
1236
+ // fallback on the next frame, and the slot is open
1237
+ // for another load. Registration's own discipline in
1238
+ // reverse — synchronous registry surgery, NOT an
1239
+ // effect: no Msg follows, and an id with no
1240
+ // registration (or one the wire cannot carry
1241
+ // exactly) is a no-op, image_cancel's idle rule. It
1242
+ // frees only the CURRENT registration: a load in
1243
+ // flight under the id is untouched and its terminal
1244
+ // still registers — cancel the load first to keep
1245
+ // the slot free.
1246
+ // channel_open open an EXTERNAL-SOURCE CHANNEL, keyed by the app's
1247
+ // own numeric key (`key`, an f64-carried positive
1248
+ // integer below 2^53 — the image records' id
1249
+ // convention): the host stages a long-lived,
1250
+ // thread-safe posting seam its NATIVE side feeds
1251
+ // (embedders and platform-services extensions post
1252
+ // bytes from their own threads; transpiled cores are
1253
+ // single-threaded and never post — they open, close,
1254
+ // and receive). Every channel event then dispatches
1255
+ // the `event_tag` arm — a five-field record built by
1256
+ // name: `key` (a number, the channel key echoed so
1257
+ // concurrent channels sharing one arm stay
1258
+ // distinguishable; a key the wire cannot carry exactly
1259
+ // echoes 0), `state` (an enum whose members are
1260
+ // exactly data/closed/rejected, matched by member
1261
+ // NAME), `bytes` (the post's payload; empty outside
1262
+ // "data" events), and `droppedPending`/`droppedTotal`
1263
+ // (numbers — the honest back-pressure counters: posts
1264
+ // refused since the previous event, and over the
1265
+ // channel's whole life). The entry is non-retiring
1266
+ // the spawn way: "data" events flow across dispatches
1267
+ // until the one "closed" terminal (channel_close) —
1268
+ // or a "rejected" terminal for an open the host
1269
+ // refused (duplicate live key, full table, occupied
1270
+ // engine key) — retires it. One channel per key at a
1271
+ // time, never replaced implicitly.
1272
+ // channel_close close the open channel under `key`, if any:
1273
+ // staged posts flush, exactly one "closed" event
1274
+ // (final drop totals aboard) dispatches the entry's
1275
+ // own event arm, and the key frees. A key naming no
1276
+ // open channel — or one the wire cannot carry exactly
1277
+ // — is a no-op, audio_ctl's idle rule. Channels are
1278
+ // keyed by their numeric key, so the string-keyed
1279
+ // `cancel` record never touches them — this is their
1280
+ // close, the way audio_ctl stop is audio's.
1281
+ // pty_spawn open a PSEUDO-TERMINAL SESSION — a spawn with a
1282
+ // different transport: run `argv` (the spawn record's
1283
+ // argv encoding and budgets) on a fresh pty whose
1284
+ // initial grid is `cols` x `rows` and whose TERM is
1285
+ // `term` (empty = the engine's default TERM — the
1286
+ // fetch-timeout convention: the wire never bakes the
1287
+ // default in). Non-retiring the spawn way: every
1288
+ // session event dispatches the `event_tag` arm — a
1289
+ // six-field record built by name: `state` (an enum
1290
+ // whose members are exactly output/exit, matched by
1291
+ // member NAME), `bytes` (a coalesced batch of child
1292
+ // output; empty outside "output" events), `code` (a
1293
+ // number, the child's exit code; -1 for every
1294
+ // non-exited end), `reason` (an enum whose members
1295
+ // are exactly the five spawn exit reasons —
1296
+ // exited/signaled/cancelled/rejected/spawn_failed —
1297
+ // matched by member NAME), `signal` (a number, the
1298
+ // fatal signal after a signaled end, else 0), and
1299
+ // `droppedWrites` (a number: pty_write payloads
1300
+ // refused over the session's life — never silence).
1301
+ // "output" events flow across dispatches until the
1302
+ // exactly-one "exit" terminal retires the entry (a
1303
+ // refused spawn — duplicate live key, full table,
1304
+ // bad grid — is one "exit" with reason "rejected";
1305
+ // a transport that could not start is one with
1306
+ // "spawn_failed"). One session per key at a time,
1307
+ // never replaced implicitly: kill it first, the
1308
+ // spawn discipline.
1309
+ // pty_write write bytes toward the session's child — keystrokes
1310
+ // and pastes, fire-and-forget: a key naming no open
1311
+ // session is a no-op (the exit was already on its
1312
+ // way), and refused payloads count into the exit's
1313
+ // `droppedWrites`, never silence.
1314
+ // pty_resize push a new grid to the session so the child
1315
+ // receives SIGWINCH — fire-and-forget like
1316
+ // pty_write; a key naming no open session is a
1317
+ // no-op.
1318
+ // pty_kill terminate the session's child. LOUD, the spawn
1319
+ // cancel discipline: the session's one "exit"
1320
+ // terminal arrives through its own event arm with
1321
+ // reason "cancelled" and the key frees once it
1322
+ // lands. A key naming no open session is a no-op.
1323
+ // Sessions are their own family's to end — the
1324
+ // string-keyed `cancel` record never touches them,
1325
+ // the way audio_ctl stop is audio's close.
1171
1326
  // audio_ctl drive the open stream's playback in place, by verb
1172
1327
  // (`CmdAudioVerb` declaration order): pause 0, resume
1173
1328
  // 1, stop 2, seek 3 (`value` = position ms), volume 4
@@ -1178,6 +1333,51 @@ pub fn Kernel(comptime opts: Options) type {
1178
1333
  // no open stream is a no-op (the playback it aimed at
1179
1334
  // is already gone). `stop` closes the stream: no
1180
1335
  // events for that key after it.
1336
+ // video_load open (or replace — one player is the whole surface)
1337
+ // the keyed video EVENT STREAM: claim the media-surface
1338
+ // texture channel `surface` names (the SAME model-owned
1339
+ // id a video widget binds — decoded frames flow
1340
+ // platform-side into it, never through this channel),
1341
+ // resolve the source cascade (local `path` first, then
1342
+ // `url`; empty fields = absent) and start playback per
1343
+ // `flags` (bit0 = autoplay, bit1 = loop, bit2 = muted).
1344
+ // Every playback event — loaded, position ticks,
1345
+ // completed, failed, rejected — then dispatches the
1346
+ // `event_tag` arm until `video_ctl` stop (or a
1347
+ // replacing video_load) closes the stream. The arm is
1348
+ // a seven-field record built by name: `state` (an enum
1349
+ // whose members are exactly loaded/position/completed/
1350
+ // failed/rejected, matched by member NAME so
1351
+ // declaration order is the app's), positionMs and
1352
+ // durationMs (numbers), playing and buffering
1353
+ // (booleans), and width and height (numbers: the
1354
+ // stream's decoded pixel dimensions on "loaded", 0
1355
+ // elsewhere). Failure is never silent: an unplayable
1356
+ // source is one `.failed` event, a refused command one
1357
+ // `.rejected`.
1358
+ // video_ctl drive the open stream's playback in place, by verb
1359
+ // (`CmdVideoVerb` declaration order): play 0, pause 1,
1360
+ // stop 2, seek 3 (`value` = position ms), volume 4
1361
+ // (`value` clamped 0..1), muted 5 and loop 6 (`value`
1362
+ // 0 = off, non-zero = on). `value` is 0 when the verb
1363
+ // takes none. Control verbs are fire-and-forget —
1364
+ // their consequences arrive on the keyed event stream
1365
+ // — and a verb whose key names no open stream is a
1366
+ // no-op. `stop` closes the stream: no events for that
1367
+ // key after it.
1368
+ // window_show fire-and-forget window verb, LABEL-addressed (the
1369
+ // declared window label, the same address the Zig
1370
+ // tier's `fx.showWindow` takes): un-hide + activate
1371
+ // the window — the counterpart to a
1372
+ // `close_policy = "hide"` hide and the tray "Open"
1373
+ // consequence; also restores a minimized window. No
1374
+ // result Msg; the window's own frame event carries
1375
+ // the state. An unknown label is a no-op.
1376
+ // quit_app fire-and-forget graceful terminate: the host quits
1377
+ // through the SAME shutdown path a last-window close
1378
+ // takes (app_shutdown emits, the stop hook runs
1379
+ // exactly once, a recording session seals its
1380
+ // journal). No payload, no result Msg.
1181
1381
  //
1182
1382
  // Key discipline is ONE rule across request, the named engine ops
1183
1383
  // (read_file/write_file/fetch/clip_read), and delay: issuing an
@@ -1188,15 +1388,16 @@ pub fn Kernel(comptime opts: Options) type {
1188
1388
  // the duplicate (err arm "rejected"): a running subprocess is never
1189
1389
  // killed implicitly — cancel it first. audio_play also replaces on
1190
1390
  // key reuse, per the engine underneath: one player is the whole
1191
- // surface.
1391
+ // surface — and video_load keeps the same rule on its own single
1392
+ // player.
1192
1393
  //
1193
1394
  // Sub vs streams, the design line: `Sub` descriptors are DECLARATIVE
1194
1395
  // recurring effects derived from the model after every commit (the
1195
- // host reconciles them; the app never opens or closes one). spawn and
1196
- // audio_play are Cmd-INITIATED STREAMS: imperative opens with a keyed
1197
- // lifecycle the app drives (cancel / audio_ctl stop), delivering many
1198
- // results until their terminal (spawn) or close (audio) retires the
1199
- // key.
1396
+ // host reconciles them; the app never opens or closes one). spawn,
1397
+ // audio_play, and video_load are Cmd-INITIATED STREAMS: imperative
1398
+ // opens with a keyed lifecycle the app drives (cancel / audio_ctl
1399
+ // stop / video_ctl stop), delivering many results until their
1400
+ // terminal (spawn) or close (audio, video) retires the key.
1200
1401
  //
1201
1402
  // Host record payload encoding (the `Cmd.host`/`Cmd.request` record form,
1202
1403
  // produced identically by the SDK under node and by emitted Zig): fields
@@ -1209,7 +1410,7 @@ pub fn Kernel(comptime opts: Options) type {
1209
1410
  // copies) them after the model commit and BEFORE frameReset — the same
1210
1411
  // boundary the committed model crosses.
1211
1412
 
1212
- pub const cmd_format_version: u32 = 2;
1413
+ pub const cmd_format_version: u32 = 3;
1213
1414
 
1214
1415
  /// An encoded command value: op records per the layout above.
1215
1416
  pub const Cmd = []const u8;
@@ -1230,6 +1431,19 @@ pub fn Kernel(comptime opts: Options) type {
1230
1431
  spawn = 0x0D,
1231
1432
  audio_play = 0x0E,
1232
1433
  audio_ctl = 0x0F,
1434
+ window_show = 0x10,
1435
+ quit_app = 0x11,
1436
+ image_load = 0x12,
1437
+ image_cancel = 0x13,
1438
+ image_unregister = 0x14,
1439
+ channel_open = 0x15,
1440
+ channel_close = 0x16,
1441
+ video_load = 0x17,
1442
+ video_ctl = 0x18,
1443
+ pty_spawn = 0x19,
1444
+ pty_write = 0x1A,
1445
+ pty_resize = 0x1B,
1446
+ pty_kill = 0x1C,
1233
1447
  };
1234
1448
 
1235
1449
  /// The spawn record's "no line routing" sentinel: a `line_tag` of
@@ -1252,6 +1466,17 @@ pub fn Kernel(comptime opts: Options) type {
1252
1466
  volume = 4,
1253
1467
  };
1254
1468
 
1469
+ /// The video_ctl verb set, wire value = declaration order.
1470
+ pub const CmdVideoVerb = enum(u8) {
1471
+ play = 0,
1472
+ pause = 1,
1473
+ stop = 2,
1474
+ seek = 3,
1475
+ volume = 4,
1476
+ muted = 5,
1477
+ loop = 6,
1478
+ };
1479
+
1255
1480
  /// The closed HTTP verb set of the fetch record, wire value =
1256
1481
  /// declaration order.
1257
1482
  pub const CmdFetchMethod = enum(u8) {
@@ -1511,6 +1736,188 @@ pub fn Kernel(comptime opts: Options) type {
1511
1736
  return out;
1512
1737
  }
1513
1738
 
1739
+ pub fn cmdWindowShow(label: []const u8) Cmd {
1740
+ // The emitter's byte gate on the literal label is the
1741
+ // build-time teaching; this is the loud runtime backstop.
1742
+ // A std.debug.assert compiles out of ReleaseFast, where the
1743
+ // @intCast below would then truncate the length byte and
1744
+ // corrupt the wire record silently — panic in every build
1745
+ // mode instead.
1746
+ if (label.len > 255) @panic("Cmd.showWindow label over 255 bytes");
1747
+ const out = frameAlloc(u8, 2 + label.len);
1748
+ out[0] = @intFromEnum(CmdOp.window_show);
1749
+ out[1] = @intCast(label.len);
1750
+ @memcpy(out[2..][0..label.len], label);
1751
+ return out;
1752
+ }
1753
+
1754
+ pub fn cmdQuitApp() Cmd {
1755
+ const out = frameAlloc(u8, 1);
1756
+ out[0] = @intFromEnum(CmdOp.quit_app);
1757
+ return out;
1758
+ }
1759
+
1760
+ pub fn cmdImageLoad(
1761
+ id: f64,
1762
+ event_tag: u8,
1763
+ path: []const u8,
1764
+ url: []const u8,
1765
+ cache_path: []const u8,
1766
+ expected_bytes: f64,
1767
+ ) Cmd {
1768
+ std.debug.assert(path.len <= std.math.maxInt(u32));
1769
+ std.debug.assert(url.len <= std.math.maxInt(u32));
1770
+ std.debug.assert(cache_path.len <= std.math.maxInt(u32));
1771
+ const out = frameAlloc(u8, 1 + 8 + 1 + 4 + path.len + 4 + url.len + 4 + cache_path.len + 8);
1772
+ out[0] = @intFromEnum(CmdOp.image_load);
1773
+ std.mem.writeInt(u64, out[1..][0..8], @bitCast(id), .little);
1774
+ out[9] = event_tag;
1775
+ var off: usize = 10;
1776
+ off = writeLongBytes(out, off, path);
1777
+ off = writeLongBytes(out, off, url);
1778
+ off = writeLongBytes(out, off, cache_path);
1779
+ std.mem.writeInt(u64, out[off..][0..8], @bitCast(expected_bytes), .little);
1780
+ return out;
1781
+ }
1782
+
1783
+ pub fn cmdImageCancel(id: f64) Cmd {
1784
+ const out = frameAlloc(u8, 1 + 8);
1785
+ out[0] = @intFromEnum(CmdOp.image_cancel);
1786
+ std.mem.writeInt(u64, out[1..][0..8], @bitCast(id), .little);
1787
+ return out;
1788
+ }
1789
+
1790
+ pub fn cmdImageUnregister(id: f64) Cmd {
1791
+ const out = frameAlloc(u8, 1 + 8);
1792
+ out[0] = @intFromEnum(CmdOp.image_unregister);
1793
+ std.mem.writeInt(u64, out[1..][0..8], @bitCast(id), .little);
1794
+ return out;
1795
+ }
1796
+
1797
+ pub fn cmdChannelOpen(key: f64, event_tag: u8) Cmd {
1798
+ const out = frameAlloc(u8, 1 + 8 + 1);
1799
+ out[0] = @intFromEnum(CmdOp.channel_open);
1800
+ std.mem.writeInt(u64, out[1..][0..8], @bitCast(key), .little);
1801
+ out[9] = event_tag;
1802
+ return out;
1803
+ }
1804
+
1805
+ pub fn cmdChannelClose(key: f64) Cmd {
1806
+ const out = frameAlloc(u8, 1 + 8);
1807
+ out[0] = @intFromEnum(CmdOp.channel_close);
1808
+ std.mem.writeInt(u64, out[1..][0..8], @bitCast(key), .little);
1809
+ return out;
1810
+ }
1811
+
1812
+ pub fn cmdVideoLoad(
1813
+ key: []const u8,
1814
+ event_tag: u8,
1815
+ surface: f64,
1816
+ path: []const u8,
1817
+ url: []const u8,
1818
+ flags: u8,
1819
+ ) Cmd {
1820
+ // The emitter's byte gate on the literal key is the
1821
+ // build-time teaching; this is the loud runtime backstop.
1822
+ // A std.debug.assert compiles out of ReleaseFast, where the
1823
+ // @intCast below would then truncate the length byte and
1824
+ // corrupt the wire record silently — panic in every build
1825
+ // mode instead.
1826
+ if (key.len > 255) @panic("Cmd.videoLoad key over 255 bytes");
1827
+ std.debug.assert(path.len <= std.math.maxInt(u32));
1828
+ std.debug.assert(url.len <= std.math.maxInt(u32));
1829
+ const out = frameAlloc(u8, 2 + key.len + 1 + 8 + 4 + path.len + 4 + url.len + 1);
1830
+ out[0] = @intFromEnum(CmdOp.video_load);
1831
+ out[1] = @intCast(key.len);
1832
+ @memcpy(out[2..][0..key.len], key);
1833
+ var off: usize = 2 + key.len;
1834
+ out[off] = event_tag;
1835
+ std.mem.writeInt(u64, out[off + 1 ..][0..8], @bitCast(surface), .little);
1836
+ off += 9;
1837
+ off = writeLongBytes(out, off, path);
1838
+ off = writeLongBytes(out, off, url);
1839
+ out[off] = flags;
1840
+ return out;
1841
+ }
1842
+
1843
+ pub fn cmdVideoCtl(key: []const u8, verb: CmdVideoVerb, value: f64) Cmd {
1844
+ // The same loud backstop as cmdVideoLoad: the length byte
1845
+ // must never truncate silently in ReleaseFast.
1846
+ if (key.len > 255) @panic("Cmd.video verb key over 255 bytes");
1847
+ const out = frameAlloc(u8, 2 + key.len + 1 + 8);
1848
+ out[0] = @intFromEnum(CmdOp.video_ctl);
1849
+ out[1] = @intCast(key.len);
1850
+ @memcpy(out[2..][0..key.len], key);
1851
+ out[2 + key.len] = @intFromEnum(verb);
1852
+ std.mem.writeInt(u64, out[2 + key.len + 1 ..][0..8], @bitCast(value), .little);
1853
+ return out;
1854
+ }
1855
+
1856
+ pub fn cmdPtySpawn(
1857
+ key: []const u8,
1858
+ event_tag: u8,
1859
+ cols: f64,
1860
+ rows: f64,
1861
+ term: []const u8,
1862
+ argv: []const []const u8,
1863
+ ) Cmd {
1864
+ std.debug.assert(key.len <= 255);
1865
+ std.debug.assert(term.len <= 255);
1866
+ std.debug.assert(argv.len >= 1 and argv.len <= 255);
1867
+ var argv_bytes: usize = 0;
1868
+ for (argv) |arg| {
1869
+ std.debug.assert(arg.len <= std.math.maxInt(u32));
1870
+ argv_bytes += 4 + arg.len;
1871
+ }
1872
+ const out = frameAlloc(u8, 2 + key.len + 1 + 8 + 8 + 1 + term.len + 1 + argv_bytes);
1873
+ out[0] = @intFromEnum(CmdOp.pty_spawn);
1874
+ out[1] = @intCast(key.len);
1875
+ @memcpy(out[2..][0..key.len], key);
1876
+ var off: usize = 2 + key.len;
1877
+ out[off] = event_tag;
1878
+ std.mem.writeInt(u64, out[off + 1 ..][0..8], @bitCast(cols), .little);
1879
+ std.mem.writeInt(u64, out[off + 9 ..][0..8], @bitCast(rows), .little);
1880
+ off += 17;
1881
+ out[off] = @intCast(term.len);
1882
+ @memcpy(out[off + 1 ..][0..term.len], term);
1883
+ off += 1 + term.len;
1884
+ out[off] = @intCast(argv.len);
1885
+ off += 1;
1886
+ for (argv) |arg| off = writeLongBytes(out, off, arg);
1887
+ return out;
1888
+ }
1889
+
1890
+ pub fn cmdPtyWrite(key: []const u8, bytes: []const u8) Cmd {
1891
+ std.debug.assert(key.len <= 255);
1892
+ std.debug.assert(bytes.len <= std.math.maxInt(u32));
1893
+ const out = frameAlloc(u8, 2 + key.len + 4 + bytes.len);
1894
+ out[0] = @intFromEnum(CmdOp.pty_write);
1895
+ out[1] = @intCast(key.len);
1896
+ @memcpy(out[2..][0..key.len], key);
1897
+ _ = writeLongBytes(out, 2 + key.len, bytes);
1898
+ return out;
1899
+ }
1900
+
1901
+ pub fn cmdPtyResize(key: []const u8, cols: f64, rows: f64) Cmd {
1902
+ std.debug.assert(key.len <= 255);
1903
+ const out = frameAlloc(u8, 2 + key.len + 8 + 8);
1904
+ out[0] = @intFromEnum(CmdOp.pty_resize);
1905
+ out[1] = @intCast(key.len);
1906
+ @memcpy(out[2..][0..key.len], key);
1907
+ std.mem.writeInt(u64, out[2 + key.len ..][0..8], @bitCast(cols), .little);
1908
+ std.mem.writeInt(u64, out[2 + key.len + 8 ..][0..8], @bitCast(rows), .little);
1909
+ return out;
1910
+ }
1911
+
1912
+ pub fn cmdPtyKill(key: []const u8) Cmd {
1913
+ std.debug.assert(key.len <= 255);
1914
+ const out = frameAlloc(u8, 2 + key.len);
1915
+ out[0] = @intFromEnum(CmdOp.pty_kill);
1916
+ out[1] = @intCast(key.len);
1917
+ @memcpy(out[2..][0..key.len], key);
1918
+ return out;
1919
+ }
1920
+
1514
1921
  pub fn cmdBatch(cmds: []const Cmd) Cmd {
1515
1922
  var total: usize = 0;
1516
1923
  for (cmds) |c| total += c.len;