@native-sdk/cli 0.5.2 → 0.5.4

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 (123) hide show
  1. package/build/app.zig +41 -1
  2. package/build.zig +264 -3
  3. package/native-sdk.d.ts +17 -1
  4. package/package.json +9 -9
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/rt/rt.zig +138 -3
  8. package/packages/core/sdk/core.ts +225 -3
  9. package/packages/core/sdk/events.ts +39 -2
  10. package/packages/core/src/checker.ts +1 -1
  11. package/packages/core/src/emitter.ts +2625 -262
  12. package/packages/core/src/infer.ts +53 -7
  13. package/skill-data/automation/SKILL.md +7 -4
  14. package/skill-data/core/references/app-model-runtime.md +3 -0
  15. package/skill-data/native-ui/SKILL.md +4 -2
  16. package/skill-data/ts-core/SKILL.md +9 -1
  17. package/src/app_runner/root.zig +106 -1
  18. package/src/app_runner/ts_core_main.zig +4 -0
  19. package/src/automation/protocol.zig +20 -1
  20. package/src/embed/host.zig +27 -0
  21. package/src/embed/tests.zig +187 -0
  22. package/src/embed/ui_host.zig +4 -0
  23. package/src/platform/linux/gtk_host.c +112 -3
  24. package/src/platform/linux/root.zig +71 -0
  25. package/src/platform/macos/appkit_host.h +59 -2
  26. package/src/platform/macos/appkit_host.m +663 -34
  27. package/src/platform/macos/cef_host.mm +262 -10
  28. package/src/platform/macos/root.zig +126 -4
  29. package/src/platform/null_platform.zig +298 -5
  30. package/src/platform/null_platform_tests.zig +39 -0
  31. package/src/platform/root.zig +36 -0
  32. package/src/platform/types.zig +247 -8
  33. package/src/platform/windows/root.zig +134 -0
  34. package/src/platform/windows/webview2_host.cpp +152 -40
  35. package/src/primitives/app_manifest/comptime_scene.zig +5 -0
  36. package/src/primitives/app_manifest/root.zig +1 -0
  37. package/src/primitives/app_manifest/types.zig +32 -0
  38. package/src/primitives/canvas/chart.zig +7 -7
  39. package/src/primitives/canvas/chart_tests.zig +66 -0
  40. package/src/primitives/canvas/commands.zig +48 -0
  41. package/src/primitives/canvas/events.zig +161 -0
  42. package/src/primitives/canvas/font_ttf.zig +155 -8
  43. package/src/primitives/canvas/font_ttf_tests.zig +686 -0
  44. package/src/primitives/canvas/reference.zig +67 -8
  45. package/src/primitives/canvas/render_fingerprints.zig +8 -0
  46. package/src/primitives/canvas/root.zig +25 -0
  47. package/src/primitives/canvas/tests.zig +1 -0
  48. package/src/primitives/canvas/ui.zig +46 -9
  49. package/src/primitives/canvas/ui_markup.zig +82 -34
  50. package/src/primitives/canvas/ui_markup_binary.zig +4 -1
  51. package/src/primitives/canvas/ui_markup_binary_tests.zig +25 -0
  52. package/src/primitives/canvas/ui_markup_compiled.zig +63 -11
  53. package/src/primitives/canvas/ui_markup_compiled_tests.zig +88 -0
  54. package/src/primitives/canvas/ui_markup_contract.zig +10 -1
  55. package/src/primitives/canvas/ui_markup_contract_tests.zig +50 -0
  56. package/src/primitives/canvas/ui_markup_huge_document_tests.zig +154 -0
  57. package/src/primitives/canvas/ui_markup_tests.zig +55 -9
  58. package/src/primitives/canvas/ui_markup_view.zig +81 -14
  59. package/src/primitives/canvas/ui_markup_view_tests.zig +219 -7
  60. package/src/primitives/canvas/ui_schema.zig +29 -0
  61. package/src/primitives/canvas/ui_schema_tests.zig +11 -11
  62. package/src/primitives/canvas/ui_tests.zig +31 -0
  63. package/src/primitives/canvas/vector.zig +258 -141
  64. package/src/primitives/canvas/widget_access.zig +1 -1
  65. package/src/primitives/canvas/widget_builtin_tests.zig +129 -0
  66. package/src/primitives/canvas/widget_layout.zig +9 -4
  67. package/src/primitives/canvas/widget_render.zig +78 -40
  68. package/src/primitives/canvas/widget_render_controls.zig +15 -4
  69. package/src/primitives/canvas/widget_semantics.zig +6 -1
  70. package/src/primitives/canvas/widget_semantics_tests.zig +168 -0
  71. package/src/primitives/canvas/widget_text_input.zig +118 -10
  72. package/src/primitives/canvas/widgets.zig +16 -0
  73. package/src/root.zig +12 -0
  74. package/src/runtime/api.zig +15 -0
  75. package/src/runtime/automation_commands.zig +33 -0
  76. package/src/runtime/automation_widget_dispatch.zig +64 -0
  77. package/src/runtime/bridge_payload.zig +7 -0
  78. package/src/runtime/bridge_responses.zig +5 -0
  79. package/src/runtime/builtin_bridge.zig +9 -4
  80. package/src/runtime/canvas_font_tests.zig +711 -5
  81. package/src/runtime/canvas_fonts.zig +120 -25
  82. package/src/runtime/canvas_frame_helpers.zig +15 -0
  83. package/src/runtime/canvas_image_tests.zig +221 -0
  84. package/src/runtime/canvas_images.zig +78 -19
  85. package/src/runtime/canvas_limits.zig +44 -8
  86. package/src/runtime/canvas_widget_clipboard_tests.zig +123 -0
  87. package/src/runtime/canvas_widget_context_menu_tests.zig +55 -0
  88. package/src/runtime/canvas_widget_events.zig +24 -4
  89. package/src/runtime/canvas_widget_runtime.zig +24 -7
  90. package/src/runtime/canvas_widget_state.zig +6 -1
  91. package/src/runtime/canvas_widget_text_tests.zig +277 -0
  92. package/src/runtime/core.zig +148 -9
  93. package/src/runtime/effects.zig +1664 -43
  94. package/src/runtime/effects_fetch_tests.zig +89 -1
  95. package/src/runtime/effects_file_tests.zig +41 -1
  96. package/src/runtime/effects_image_tests.zig +1304 -0
  97. package/src/runtime/effects_tests.zig +153 -0
  98. package/src/runtime/flow.zig +44 -0
  99. package/src/runtime/gpu_surface_events.zig +7 -0
  100. package/src/runtime/media_surface.zig +726 -0
  101. package/src/runtime/media_surface_tests.zig +1476 -0
  102. package/src/runtime/root.zig +20 -0
  103. package/src/runtime/session_blobs.zig +689 -0
  104. package/src/runtime/session_journal.zig +111 -20
  105. package/src/runtime/session_record.zig +27 -2
  106. package/src/runtime/session_replay.zig +168 -16
  107. package/src/runtime/session_tests.zig +2118 -4
  108. package/src/runtime/shell_layout.zig +7 -0
  109. package/src/runtime/testdata/fonts/NotoSansSC-Receipt.ttf +0 -0
  110. package/src/runtime/testdata/fonts/OFL.txt +93 -0
  111. package/src/runtime/tests.zig +3 -0
  112. package/src/runtime/ts_core_host.zig +439 -4
  113. package/src/runtime/ts_core_host_tests.zig +41 -0
  114. package/src/runtime/ts_ui_app.zig +63 -0
  115. package/src/runtime/ui_app.zig +169 -6
  116. package/src/runtime/ui_app_tests.zig +334 -0
  117. package/src/runtime/ui_app_window_tests.zig +468 -0
  118. package/src/runtime/window_command_bridge_tests.zig +117 -0
  119. package/src/runtime/window_storage.zig +32 -0
  120. package/src/runtime/window_views.zig +61 -1
  121. package/src/tooling/manifest.zig +75 -0
  122. package/src/tooling/raw_manifest.zig +2 -0
  123. package/src/tooling/templates.zig +219 -1
@@ -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,23 @@ 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]
1055
1062
  //
1056
1063
  // v2 is additive over v1: the 0x01-0x03 records are byte-identical to v1,
1057
1064
  // so a v1 effect log replays under a v2 reader unchanged. The named-op
1058
1065
  // records 0x07-0x0C are additive within v2 the same way, and so are the
1059
1066
  // streaming records 0x0D-0x0F: no existing record's bytes change, new
1060
- // opcodes only.
1067
+ // opcodes only. v3 appends the window-verb records 0x10-0x11 under the
1068
+ // same rule, and the image records 0x12-0x14 are additive within v3
1069
+ // the same way: every existing record is byte-identical, new opcodes
1070
+ // only (a host predating an opcode refuses it loudly, naming this
1071
+ // version).
1061
1072
  //
1062
1073
  // `method` is the closed HTTP verb set in declaration order of `CmdFetchMethod`
1063
1074
  // (GET 0, POST 1, PUT 2, DELETE 3, PATCH 4, HEAD 5). `timeout_ms` 0 means
@@ -1168,6 +1179,54 @@ pub fn Kernel(comptime opts: Options) type {
1168
1179
  // magnitudes, all zeros outside `.spectrum` events).
1169
1180
  // Failure is never silent: an unplayable source is one
1170
1181
  // `.failed` event, a refused command one `.rejected`.
1182
+ // image_load a routed one-shot image load, keyed by the app's own
1183
+ // numeric ImageId (`id`, an f64-carried positive integer
1184
+ // — the SAME model-owned id markup binds via
1185
+ // <image image="{id}"/> / <avatar image="{id}"/>):
1186
+ // resolve the source cascade (local `path` first, then a
1187
+ // verified cache entry at `cache_path`, then `url` —
1188
+ // audio_play's resolution order; `expected_bytes` is the
1189
+ // cache integrity gate, 0 = unknown), decode through the
1190
+ // platform codec, register the pixels under the id, and
1191
+ // dispatch exactly ONE `event_tag` arm — a five-field
1192
+ // record built by name: `id` (a number, the requested
1193
+ // ImageId echoed verbatim so concurrent loads sharing
1194
+ // one arm stay distinguishable; an id the wire cannot
1195
+ // carry exactly echoes 0), `state` (an enum whose
1196
+ // members are exactly the fifteen image outcome names,
1197
+ // matched by member NAME), width and height (numbers,
1198
+ // the decoded dimensions on "loaded"), and status
1199
+ // (number, the HTTP status for url loads that
1200
+ // performed an exchange; 0 when none occurred —
1201
+ // local paths, cache hits — so a cached "loaded"
1202
+ // is distinguishable from a network one). One load
1203
+ // per id at a time: a duplicate live id dispatches
1204
+ // "rejected" (the spawn discipline — a load in flight
1205
+ // is never replaced implicitly).
1206
+ // image_cancel end the in-flight load under `id`, if any, LOUDLY:
1207
+ // the load's one terminal arrives as its own event arm
1208
+ // with state "cancelled" (ending an in-flight load is
1209
+ // an observable event, spawn's cancel discipline), and
1210
+ // the id is free for a fresh load once that terminal
1211
+ // lands. Aimed at an id with no live load — or one the
1212
+ // wire cannot carry exactly — it is a no-op, the same
1213
+ // idle no-op audio_ctl keeps: whatever it aimed at is
1214
+ // already gone. Image loads are keyed by their numeric
1215
+ // id, so the string-keyed `cancel` record never
1216
+ // touches them.
1217
+ // image_unregister
1218
+ // free the registry slot under `id`: the pixels are
1219
+ // released, views referencing the id draw their
1220
+ // fallback on the next frame, and the slot is open
1221
+ // for another load. Registration's own discipline in
1222
+ // reverse — synchronous registry surgery, NOT an
1223
+ // effect: no Msg follows, and an id with no
1224
+ // registration (or one the wire cannot carry
1225
+ // exactly) is a no-op, image_cancel's idle rule. It
1226
+ // frees only the CURRENT registration: a load in
1227
+ // flight under the id is untouched and its terminal
1228
+ // still registers — cancel the load first to keep
1229
+ // the slot free.
1171
1230
  // audio_ctl drive the open stream's playback in place, by verb
1172
1231
  // (`CmdAudioVerb` declaration order): pause 0, resume
1173
1232
  // 1, stop 2, seek 3 (`value` = position ms), volume 4
@@ -1178,6 +1237,19 @@ pub fn Kernel(comptime opts: Options) type {
1178
1237
  // no open stream is a no-op (the playback it aimed at
1179
1238
  // is already gone). `stop` closes the stream: no
1180
1239
  // events for that key after it.
1240
+ // window_show fire-and-forget window verb, LABEL-addressed (the
1241
+ // declared window label, the same address the Zig
1242
+ // tier's `fx.showWindow` takes): un-hide + activate
1243
+ // the window — the counterpart to a
1244
+ // `close_policy = "hide"` hide and the tray "Open"
1245
+ // consequence; also restores a minimized window. No
1246
+ // result Msg; the window's own frame event carries
1247
+ // the state. An unknown label is a no-op.
1248
+ // quit_app fire-and-forget graceful terminate: the host quits
1249
+ // through the SAME shutdown path a last-window close
1250
+ // takes (app_shutdown emits, the stop hook runs
1251
+ // exactly once, a recording session seals its
1252
+ // journal). No payload, no result Msg.
1181
1253
  //
1182
1254
  // Key discipline is ONE rule across request, the named engine ops
1183
1255
  // (read_file/write_file/fetch/clip_read), and delay: issuing an
@@ -1209,7 +1281,7 @@ pub fn Kernel(comptime opts: Options) type {
1209
1281
  // copies) them after the model commit and BEFORE frameReset — the same
1210
1282
  // boundary the committed model crosses.
1211
1283
 
1212
- pub const cmd_format_version: u32 = 2;
1284
+ pub const cmd_format_version: u32 = 3;
1213
1285
 
1214
1286
  /// An encoded command value: op records per the layout above.
1215
1287
  pub const Cmd = []const u8;
@@ -1230,6 +1302,11 @@ pub fn Kernel(comptime opts: Options) type {
1230
1302
  spawn = 0x0D,
1231
1303
  audio_play = 0x0E,
1232
1304
  audio_ctl = 0x0F,
1305
+ window_show = 0x10,
1306
+ quit_app = 0x11,
1307
+ image_load = 0x12,
1308
+ image_cancel = 0x13,
1309
+ image_unregister = 0x14,
1233
1310
  };
1234
1311
 
1235
1312
  /// The spawn record's "no line routing" sentinel: a `line_tag` of
@@ -1511,6 +1588,64 @@ pub fn Kernel(comptime opts: Options) type {
1511
1588
  return out;
1512
1589
  }
1513
1590
 
1591
+ pub fn cmdWindowShow(label: []const u8) Cmd {
1592
+ // The emitter's byte gate on the literal label is the
1593
+ // build-time teaching; this is the loud runtime backstop.
1594
+ // A std.debug.assert compiles out of ReleaseFast, where the
1595
+ // @intCast below would then truncate the length byte and
1596
+ // corrupt the wire record silently — panic in every build
1597
+ // mode instead.
1598
+ if (label.len > 255) @panic("Cmd.showWindow label over 255 bytes");
1599
+ const out = frameAlloc(u8, 2 + label.len);
1600
+ out[0] = @intFromEnum(CmdOp.window_show);
1601
+ out[1] = @intCast(label.len);
1602
+ @memcpy(out[2..][0..label.len], label);
1603
+ return out;
1604
+ }
1605
+
1606
+ pub fn cmdQuitApp() Cmd {
1607
+ const out = frameAlloc(u8, 1);
1608
+ out[0] = @intFromEnum(CmdOp.quit_app);
1609
+ return out;
1610
+ }
1611
+
1612
+ pub fn cmdImageLoad(
1613
+ id: f64,
1614
+ event_tag: u8,
1615
+ path: []const u8,
1616
+ url: []const u8,
1617
+ cache_path: []const u8,
1618
+ expected_bytes: f64,
1619
+ ) Cmd {
1620
+ std.debug.assert(path.len <= std.math.maxInt(u32));
1621
+ std.debug.assert(url.len <= std.math.maxInt(u32));
1622
+ std.debug.assert(cache_path.len <= std.math.maxInt(u32));
1623
+ const out = frameAlloc(u8, 1 + 8 + 1 + 4 + path.len + 4 + url.len + 4 + cache_path.len + 8);
1624
+ out[0] = @intFromEnum(CmdOp.image_load);
1625
+ std.mem.writeInt(u64, out[1..][0..8], @bitCast(id), .little);
1626
+ out[9] = event_tag;
1627
+ var off: usize = 10;
1628
+ off = writeLongBytes(out, off, path);
1629
+ off = writeLongBytes(out, off, url);
1630
+ off = writeLongBytes(out, off, cache_path);
1631
+ std.mem.writeInt(u64, out[off..][0..8], @bitCast(expected_bytes), .little);
1632
+ return out;
1633
+ }
1634
+
1635
+ pub fn cmdImageCancel(id: f64) Cmd {
1636
+ const out = frameAlloc(u8, 1 + 8);
1637
+ out[0] = @intFromEnum(CmdOp.image_cancel);
1638
+ std.mem.writeInt(u64, out[1..][0..8], @bitCast(id), .little);
1639
+ return out;
1640
+ }
1641
+
1642
+ pub fn cmdImageUnregister(id: f64) Cmd {
1643
+ const out = frameAlloc(u8, 1 + 8);
1644
+ out[0] = @intFromEnum(CmdOp.image_unregister);
1645
+ std.mem.writeInt(u64, out[1..][0..8], @bitCast(id), .little);
1646
+ return out;
1647
+ }
1648
+
1514
1649
  pub fn cmdBatch(cmds: []const Cmd) Cmd {
1515
1650
  var total: usize = 0;
1516
1651
  for (cmds) |c| total += c.len;
@@ -10,7 +10,7 @@
10
10
  // return path (NS1017) — they never live in the Model, in a Msg, in a local,
11
11
  // or in a helper.
12
12
  //
13
- // The v2 command set:
13
+ // The v3 command set:
14
14
  //
15
15
  // Cmd.none no effects (what a bare `return model` means)
16
16
  // Cmd.persist() ask the host to persist the committed model
@@ -103,6 +103,50 @@
103
103
  // forget control verbs whose consequences arrive
104
104
  // on the event stream; aimed at a key with no
105
105
  // open stream they no-op.
106
+ // Cmd.imageLoad(id, { path?, url?, cachePath?, expectedBytes? }, { event })
107
+ // load an image at runtime by its model-owned
108
+ // numeric ImageId (the id markup binds:
109
+ // <image image="{id}"/>, avatar likewise): the
110
+ // host resolves the source cascade (local path
111
+ // first, then a verified cache entry, then the
112
+ // network), decodes through the platform codec,
113
+ // registers the pixels under the id, and
114
+ // dispatches exactly ONE `event` arm (the
115
+ // five-field record below, the requested id
116
+ // echoed) — state "loaded" with the decoded
117
+ // width/height, or one failure class. One load
118
+ // per id at a time: a duplicate live id
119
+ // dispatches state "rejected".
120
+ // Cmd.imageCancel(id) end the in-flight load under the id, if any
121
+ // — loud, the spawn discipline: the load's
122
+ // event arm delivers state "cancelled" and the
123
+ // id frees for a fresh load once it lands. An
124
+ // id with no live load no-ops.
125
+ // Cmd.imageUnregister(id) free the registry slot under the id: the
126
+ // pixels are released, views referencing the
127
+ // id draw their fallback, and the slot is
128
+ // open for another load. Synchronous registry
129
+ // surgery like registration itself — not an
130
+ // effect, no Msg follows; an id with no
131
+ // registration no-ops. A load IN FLIGHT under
132
+ // the id is untouched: its terminal still
133
+ // registers — cancel the load first to keep
134
+ // the slot free.
135
+ //
136
+ // The window verbs (fire-and-forget, no result Msg — the window's own
137
+ // frame event carries the state):
138
+ //
139
+ // Cmd.showWindow(label) un-hide + activate the window with the
140
+ // declared label — the counterpart to a
141
+ // `close_policy = "hide"` hide and the tray
142
+ // "Open" consequence; also restores a
143
+ // minimized window. An unknown label is a
144
+ // no-op.
145
+ // Cmd.quitApp() graceful terminate, the tray "Quit"
146
+ // consequence: the host quits through the
147
+ // SAME shutdown path a last-window close
148
+ // takes, so the stop hook runs exactly once
149
+ // and a recording session seals its journal.
106
150
  //
107
151
  // The keyed-effect discipline is ONE rule: a keyed effect REPLACES its live
108
152
  // predecessor (the superseded effect's result is dropped — no message), and
@@ -248,12 +292,87 @@ export type AudioEventArm = {
248
292
  };
249
293
 
250
294
  /// The Msg arms an audio event stream may target: arms whose payload is
251
- /// exactly the six AudioEventArm fields.
295
+ /// exactly the six AudioEventArm fields. The `state` check runs BOTH
296
+ /// directions: the `&` constraint holds the arm's states to AudioState,
297
+ /// and the tuple-wrapped reverse check holds AudioState to the arm's
298
+ /// states — a narrower union would silently drop event states the host
299
+ /// emits, so it is refused here, not discovered at runtime.
252
300
  export type AudioEventKind<M extends Msgish> = M extends Msgish
253
301
  ? [Exclude<keyof M, "kind">] extends [keyof AudioEventArm]
254
302
  ? [keyof AudioEventArm] extends [Exclude<keyof M, "kind">]
255
303
  ? M extends Msgish & AudioEventArm
256
- ? M["kind"]
304
+ ? [AudioState] extends [M["state"]]
305
+ ? M["kind"]
306
+ : never
307
+ : never
308
+ : never
309
+ : never
310
+ : never;
311
+
312
+ /// The image load result states, mirroring the engine's outcome vocabulary:
313
+ /// "loaded" means the pixels are registered under the requested id (width and
314
+ /// height carry what the codec decoded); every other state is the failure
315
+ /// class — "rejected" (a refused command: invalid id, no source, a duplicate
316
+ /// live id), "not_found" (missing local file, no url), "io_failed" (a local
317
+ /// read failure), "connect_failed"/"tls_failed"/"protocol_failed"/"timed_out"
318
+ /// (the fetch taxonomy), "http_status" (a non-2xx answer; `status` carries
319
+ /// it), "cancelled", "too_large" (source or decoded pixels over budget),
320
+ /// "unsupported" (no platform codec), "decode_failed", "registry_full", and
321
+ /// "alloc_failed" (the host refused the memory the registration needed —
322
+ /// resource exhaustion, not corrupt bytes: the same source may load once
323
+ /// memory frees).
324
+ export type ImageState =
325
+ | "loaded"
326
+ | "rejected"
327
+ | "not_found"
328
+ | "io_failed"
329
+ | "connect_failed"
330
+ | "tls_failed"
331
+ | "protocol_failed"
332
+ | "timed_out"
333
+ | "http_status"
334
+ | "cancelled"
335
+ | "too_large"
336
+ | "unsupported"
337
+ | "decode_failed"
338
+ | "registry_full"
339
+ | "alloc_failed";
340
+
341
+ /// The payload shape of an image result arm — five fields, matched by NAME
342
+ /// (the AudioEventArm convention). `id` is the requested ImageId echoed
343
+ /// verbatim, so two concurrent loads sharing one event arm stay
344
+ /// distinguishable in `update` (an id the wire cannot carry exactly — 0,
345
+ /// negatives, fractions, 2^53 and past — echoes 0, the no-image sentinel:
346
+ /// there is no honest integer to echo); `state` must be a named
347
+ /// string-literal-union alias carrying exactly the fifteen ImageState
348
+ /// members (any declaration order — the host matches members by name);
349
+ /// `width`/`height` are the decoded pixel dimensions ("loaded" only, 0
350
+ /// otherwise); `status` is the HTTP status for url loads that performed an
351
+ /// exchange, 0 when none occurred (local paths, cache hits) — 0 is signal,
352
+ /// not a missing value: a cache hit is a real "loaded" with no exchange
353
+ /// behind it, so apps can distinguish a network load from a cached one.
354
+ export type ImageEventArm = {
355
+ readonly id: number;
356
+ readonly state: ImageState;
357
+ readonly width: number;
358
+ readonly height: number;
359
+ readonly status: number;
360
+ };
361
+
362
+ /// The Msg arms an image load result may target: arms whose payload is
363
+ /// exactly the five ImageEventArm fields. The `state` check runs BOTH
364
+ /// directions (the AudioEventKind convention): the `&` constraint holds
365
+ /// the arm's states to ImageState, and the tuple-wrapped reverse check
366
+ /// holds ImageState to the arm's states — a narrower union would
367
+ /// silently drop result states the host emits, so it is refused here,
368
+ /// not discovered at runtime.
369
+ export type ImageEventKind<M extends Msgish> = M extends Msgish
370
+ ? [Exclude<keyof M, "kind">] extends [keyof ImageEventArm]
371
+ ? [keyof ImageEventArm] extends [Exclude<keyof M, "kind">]
372
+ ? M extends Msgish & ImageEventArm
373
+ ? [ImageState] extends [M["state"]]
374
+ ? M["kind"]
375
+ : never
257
376
  : never
258
377
  : never
259
378
  : never
@@ -335,6 +454,26 @@ export interface AudioRoute<M extends Msgish> {
335
454
  readonly event: AudioEventKind<M>;
336
455
  }
337
456
 
457
+ /// A `Cmd.imageLoad` source: the audio cascade's shape exactly. The local
458
+ /// `path` is tried first; a missing file falls through to `url` (fetched
459
+ /// whole, installed at `cachePath` when given and verified against
460
+ /// `expectedBytes` — 0/omitted means unknown size, existence alone qualifies
461
+ /// a cache entry; omit `cachePath` and the host derives the conventional
462
+ /// content-addressed path when a caches directory is configured). At least
463
+ /// one of path/url must be present.
464
+ export interface ImageSource {
465
+ readonly path?: Uint8Array;
466
+ readonly url?: Uint8Array;
467
+ readonly cachePath?: Uint8Array;
468
+ readonly expectedBytes?: number;
469
+ }
470
+
471
+ /// `Cmd.imageLoad` routing: the ONE terminal result dispatches the `event`
472
+ /// arm (the five-field ImageEventArm record, matched by field name).
473
+ export interface ImageRoute<M extends Msgish> {
474
+ readonly event: ImageEventKind<M>;
475
+ }
476
+
338
477
  /// The closed HTTP verb set of `Cmd.fetch` (wire value = declaration order).
339
478
  export type FetchMethod = "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD";
340
479
 
@@ -431,6 +570,19 @@ export type Cmd<M extends Msgish> =
431
570
  /// Seek position (ms) / volume (0..1); 0 for the value-less verbs.
432
571
  readonly value: number;
433
572
  }
573
+ | { readonly op: "window_show"; readonly label: string }
574
+ | { readonly op: "quit_app" }
575
+ | {
576
+ readonly op: "image_load";
577
+ readonly id: number;
578
+ readonly eventKind: string;
579
+ readonly path: Uint8Array;
580
+ readonly url: Uint8Array;
581
+ readonly cachePath: Uint8Array;
582
+ readonly expectedBytes: number;
583
+ }
584
+ | { readonly op: "image_cancel"; readonly id: number }
585
+ | { readonly op: "image_unregister"; readonly id: number }
434
586
  | { readonly op: "batch"; readonly cmds: readonly Cmd<M>[] };
435
587
 
436
588
  /// The wire encoding of a host record payload, byte-identical to what the
@@ -659,6 +811,76 @@ export const Cmd = {
659
811
  return { op: "audio_ctl", key, verb: "volume", value: volume };
660
812
  },
661
813
 
814
+ /// Show the window with the declared `label`: un-hide + activate — the
815
+ /// counterpart to a `close_policy = "hide"` hide and the tray "Open"
816
+ /// consequence; also restores a minimized window. Fire-and-forget: no
817
+ /// result Msg (the window's own frame event carries the state), and an
818
+ /// unknown label is a no-op. The label is a string literal — window
819
+ /// labels are declarations.
820
+ showWindow(label: string): Cmd<never> {
821
+ return { op: "window_show", label };
822
+ },
823
+
824
+ /// Quit the app for real — the graceful terminate, and the tray "Quit"
825
+ /// consequence. The host quits through the SAME shutdown path a
826
+ /// last-window close takes, so the stop hook runs exactly once and a
827
+ /// recording session seals its journal. Fire-and-forget.
828
+ quitApp(): Cmd<never> {
829
+ return { op: "quit_app" };
830
+ },
831
+
832
+ /// Load an image at runtime under the model-owned numeric ImageId your
833
+ /// markup binds (`<image image="{id}"/>`, `<avatar image="{id}"/>`):
834
+ /// resolve the source cascade (local path first, then a verified cache
835
+ /// entry, then the network), decode through the platform codec, register
836
+ /// the pixels under `id`, and dispatch exactly ONE `event` arm — state
837
+ /// "loaded" with the decoded width/height, or one failure class, always
838
+ /// echoing the requested id so concurrent loads sharing the arm stay
839
+ /// distinguishable. Failure is never silent, and views referencing the
840
+ /// id repaint on the next
841
+ /// frame. One load per id at a time: a duplicate live id dispatches state
842
+ /// "rejected" (finish or re-key instead — ids are model data). Ids are
843
+ /// positive integers below 2^53 outside the reserved bit-63 namespace;
844
+ /// 0 is the no-image sentinel and dispatches "rejected".
845
+ imageLoad<M extends Msgish>(id: number, source: ImageSource, route: ImageRoute<M>): Cmd<M> {
846
+ return {
847
+ op: "image_load",
848
+ id,
849
+ eventKind: route.event,
850
+ path: source.path ?? new Uint8Array(0),
851
+ url: source.url ?? new Uint8Array(0),
852
+ cachePath: source.cachePath ?? new Uint8Array(0),
853
+ expectedBytes: source.expectedBytes ?? 0,
854
+ };
855
+ },
856
+
857
+ /// End the in-flight image load under `id`, if any — LOUDLY: the load's
858
+ /// one terminal arrives as its own `event` arm with state "cancelled"
859
+ /// (ending an in-flight load is an observable event, the spawn cancel
860
+ /// discipline), and the id is free for a fresh load once that terminal
861
+ /// lands. Aimed at an id with no live load it no-ops (the load it aimed
862
+ /// at already delivered its terminal). Image loads are keyed by their
863
+ /// numeric id, so the string-keyed `Cmd.cancel` never touches them —
864
+ /// this is their cancel, the way `Cmd.audioStop` is audio's.
865
+ imageCancel(id: number): Cmd<never> {
866
+ return { op: "image_cancel", id };
867
+ },
868
+
869
+ /// Free the registry slot under `id`: the pixels are released, views
870
+ /// referencing the id draw their fallback (avatar initials) on the next
871
+ /// frame, and the slot — one of the registry's 16 — is open for another
872
+ /// load (the gallery eviction move: unregister the evictee, load the
873
+ /// newcomer under a fresh id). Like registration itself this is
874
+ /// synchronous registry surgery, not an effect: no Msg follows, and an
875
+ /// id with no registration no-ops (whatever it aimed at is already
876
+ /// gone, `Cmd.imageCancel`'s idle rule). It frees only the CURRENT
877
+ /// registration — a load IN FLIGHT under the id is untouched and its
878
+ /// terminal still registers the pixels; to keep the slot free, end the
879
+ /// load with `Cmd.imageCancel(id)` first.
880
+ imageUnregister(id: number): Cmd<never> {
881
+ return { op: "image_unregister", id };
882
+ },
883
+
662
884
  /// Several commands from one dispatch, performed in order.
663
885
  batch<M extends Msgish>(cmds: readonly Cmd<M>[]): Cmd<M> {
664
886
  return { op: "batch", cmds };
@@ -26,8 +26,9 @@
26
26
  // - `TextInputEvent`, `ScrollState`: Msg-arm PAYLOAD fields —
27
27
  // `{ kind: "draft_edit"; edit: TextInputEvent }`,
28
28
  // `{ kind: "scrolled"; scroll: ScrollState }`.
29
- // - `FrameEvent`, `KeyEvent`: the wiring channels' parameter records —
30
- // `frameMsg(model, frame: FrameEvent)`, `keyMsg(key: KeyEvent)`.
29
+ // - `FrameEvent`, `KeyEvent`, `PinchEvent`: the wiring channels'
30
+ // parameter records — `frameMsg(model, frame: FrameEvent)`,
31
+ // `keyMsg(key: KeyEvent)`, `pinchMsg(pinch: PinchEvent)`.
31
32
  // - `ColorScheme`, `ChromeInsets`, `ChromeButtons`, `AudioState`: field
32
33
  // types INSIDE the arm records the `appearanceMsg`/`chromeMsg`/audio
33
34
  // routes name (the arms themselves stay inline unions of `kind` plus
@@ -72,6 +73,42 @@ export interface KeyEvent {
72
73
  readonly super: boolean;
73
74
  }
74
75
 
76
+ /// The pinch phase vocabulary — a NAMED begin/change/end alias (the host
77
+ /// matches enum members by name, so this is the `phase` field's type in
78
+ /// `pinchMsg`'s parameter record). A host-cancelled gesture folds into
79
+ /// "end": pinch delivers incremental deltas the app applies as they
80
+ /// arrive, so there is no transient state to roll back. A terminal host
81
+ /// event that still measured a nonzero delta delivers it as a final
82
+ /// "change" before the "end", so the cumulative product always matches
83
+ /// what the OS reported.
84
+ export type PinchPhase = "begin" | "change" | "end";
85
+
86
+ /// The pinch channel's record (`pinchMsg(pinch)`): the trackpad pinch
87
+ /// gesture, phase-explicit. `windowId`/`label` name the source window and
88
+ /// gpu-surface view — `x`/`y` are view-local, so a coordinate without its
89
+ /// view is not a position, and multi-window apps tell pinches apart by
90
+ /// these. `scale` is the magnification DELTA for this event (nonzero
91
+ /// only on "change"), and the delta is MULTIPLICATIVE: the cumulative
92
+ /// gesture scale is the running product of `1 + scale` — apply it
93
+ /// memorylessly, `zoom *= 1 + scale`, no gesture-start bookkeeping. On
94
+ /// macOS this is AppKit's raw per-event `NSEvent.magnification`, which
95
+ /// IS that multiplicative delta per the browser-engine convention, so
96
+ /// the product matches the zoom the same gesture performs in Safari and
97
+ /// Chrome. `x`/`y` is the pointer anchor in view-local canvas
98
+ /// points — the pointer location during the gesture (hosts report gesture
99
+ /// events at the pointer, not at a midpoint between the fingers), so a
100
+ /// zoom can anchor under the cursor. Pinch is a view-global gesture — it
101
+ /// never routes through widgets — so this is the honest home for timeline
102
+ /// and canvas zoom. Only hosts with a pinch source emit it (macOS today).
103
+ export interface PinchEvent {
104
+ readonly windowId: number;
105
+ readonly label: string;
106
+ readonly phase: PinchPhase;
107
+ readonly scale: number;
108
+ readonly x: number;
109
+ readonly y: number;
110
+ }
111
+
75
112
  /// The appearance vocabulary — a NAMED light/dark alias (the host matches
76
113
  /// enum members by name, so this is the `colorScheme` field's type in the
77
114
  /// arm `appearanceMsg` names).
@@ -795,7 +795,7 @@ export class SubsetChecker {
795
795
  /// entry points, but the exports themselves live in the entry module.
796
796
  private static readonly entryOnlyExports = new Set([
797
797
  "update", "initialModel", "subscriptions",
798
- "commandMsg", "keyMsg", "frameMsg", "appearanceMsg", "chromeMsg", "envMsgs",
798
+ "commandMsg", "keyMsg", "frameMsg", "pinchMsg", "appearanceMsg", "chromeMsg", "envMsgs",
799
799
  "viewUnbound",
800
800
  ]);
801
801