@native-sdk/cli 0.8.4 → 0.9.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 (161) hide show
  1. package/build/app.zig +1178 -74
  2. package/build.zig +715 -17
  3. package/build.zig.zon +1 -0
  4. package/native-sdk.d.ts +10 -0
  5. package/package.json +12 -11
  6. package/packages/core/compile-surface/core.ts +435 -3
  7. package/packages/core/package-lock.json +11 -11
  8. package/packages/core/package.json +2 -2
  9. package/packages/core/scripts/compiler_typecheck.mjs +116 -15
  10. package/packages/core/scripts/gen_service_surface.mjs +268 -0
  11. package/packages/core/scripts/merge_static_archives.mjs +78 -0
  12. package/packages/core/scripts/npm_static_spike.mjs +64 -0
  13. package/packages/core/scripts/run_external_core_compiler.mjs +122 -6
  14. package/packages/core/scripts/run_external_service_compiler.mjs +280 -0
  15. package/packages/core/scripts/stage_external_core.mjs +9 -1
  16. package/packages/core/scripts/stage_external_services.mjs +172 -0
  17. package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
  18. package/packages/core/scripts/vendor_service_packages.mjs +189 -0
  19. package/packages/core/sdk/core.d.ts +224 -0
  20. package/packages/core/sdk/core.ts +694 -22
  21. package/packages/core/sdk/events.d.ts +89 -0
  22. package/packages/core/sdk/events.ts +128 -0
  23. package/packages/core/src/checker.ts +936 -15
  24. package/packages/core/src/cli.ts +156 -3
  25. package/packages/core/src/contract.ts +28 -5
  26. package/packages/core/src/devhost.ts +1876 -16
  27. package/packages/core/src/devhost_journal.mjs +183 -0
  28. package/packages/core/src/devhost_resolver.mjs +17 -1
  29. package/packages/core/src/devhost_service_worker.mjs +90 -0
  30. package/packages/core/src/diagnostics.ts +179 -22
  31. package/packages/core/src/frontend.ts +210 -34
  32. package/packages/core/src/infer.ts +24 -0
  33. package/packages/core/src/modules.ts +129 -80
  34. package/packages/core/src/service_contract.ts +597 -0
  35. package/packages/core/src/sqlite_cli.ts +93 -0
  36. package/packages/core/src/sqlite_codegen.ts +806 -0
  37. package/packages/core/src/sqlite_runtime_policy.ts +364 -0
  38. package/packages/core/src/typed_ast.ts +36 -8
  39. package/skill-data/automation/SKILL.md +1 -1
  40. package/skill-data/core/references/project-anatomy.md +1 -1
  41. package/skill-data/native-ui/SKILL.md +58 -5
  42. package/skill-data/ts-core/SKILL.md +123 -41
  43. package/skill-data/ts-services/SKILL.md +126 -0
  44. package/skill-data/ts-services/references/service-surface.md +604 -0
  45. package/skill-data/zig/SKILL.md +1 -1
  46. package/skills/native-sdk/SKILL.md +1 -1
  47. package/src/app_runner/no_migrations.zig +3 -0
  48. package/src/app_runner/no_services.zig +20 -0
  49. package/src/app_runner/root.zig +133 -4
  50. package/src/app_runner/ts_core_main.zig +254 -8
  51. package/src/app_runner/ts_core_mobile.zig +241 -0
  52. package/src/automation/protocol.zig +5 -1
  53. package/src/automation/snapshot.zig +31 -11
  54. package/src/embed/app_exports.zig +12 -1
  55. package/src/embed/c_api.zig +48 -2
  56. package/src/embed/conversions.zig +4 -5
  57. package/src/embed/host.zig +109 -1
  58. package/src/embed/root.zig +8 -0
  59. package/src/embed/tests.zig +241 -0
  60. package/src/embed/types.zig +51 -0
  61. package/src/embed/ui_host.zig +185 -5
  62. package/src/platform/android/NativeSdkActivity.java +131 -0
  63. package/src/platform/android/android_host.c +182 -1
  64. package/src/platform/android/native_sdk_app.h +17 -0
  65. package/src/platform/ios/native_sdk_app.h +17 -0
  66. package/src/platform/ios/uikit_host.m +115 -0
  67. package/src/platform/linux/cef_host.cpp +8 -2
  68. package/src/platform/linux/gtk_host.c +289 -22
  69. package/src/platform/linux/gtk_host.h +5 -1
  70. package/src/platform/linux/root.zig +109 -22
  71. package/src/platform/macos/appkit_host.h +24 -7
  72. package/src/platform/macos/appkit_host.m +686 -64
  73. package/src/platform/macos/cef_host.mm +400 -66
  74. package/src/platform/macos/root.zig +304 -47
  75. package/src/platform/null_platform.zig +435 -48
  76. package/src/platform/null_platform_tests.zig +113 -0
  77. package/src/platform/root.zig +19 -0
  78. package/src/platform/types.zig +281 -28
  79. package/src/platform/windows/root.zig +207 -27
  80. package/src/platform/windows/webview2_host.cpp +334 -51
  81. package/src/primitives/app_manifest/comptime_scene.zig +2 -0
  82. package/src/primitives/app_manifest/root.zig +4 -0
  83. package/src/primitives/app_manifest/tests.zig +3 -0
  84. package/src/primitives/app_manifest/types.zig +32 -0
  85. package/src/primitives/app_manifest/validation.zig +19 -1
  86. package/src/root.zig +53 -0
  87. package/src/runtime/api.zig +19 -0
  88. package/src/runtime/automation_commands.zig +35 -2
  89. package/src/runtime/automation_snapshot.zig +32 -20
  90. package/src/runtime/bridge_permission_tests.zig +58 -3
  91. package/src/runtime/bridge_responses.zig +4 -2
  92. package/src/runtime/builtin_bridge.zig +11 -1
  93. package/src/runtime/canvas_frame.zig +18 -11
  94. package/src/runtime/canvas_frame_animation_tests.zig +4 -0
  95. package/src/runtime/clock.zig +13 -1
  96. package/src/runtime/core.zig +145 -7
  97. package/src/runtime/credentials_store.zig +115 -0
  98. package/src/runtime/effects.zig +3701 -231
  99. package/src/runtime/effects_credentials_tests.zig +332 -0
  100. package/src/runtime/effects_file_tests.zig +587 -0
  101. package/src/runtime/effects_host_tests.zig +208 -1
  102. package/src/runtime/effects_notification_tests.zig +11 -0
  103. package/src/runtime/effects_relational_tests.zig +314 -0
  104. package/src/runtime/effects_store_tests.zig +211 -0
  105. package/src/runtime/file_access.zig +400 -0
  106. package/src/runtime/file_effect_crash_helper.zig +28 -0
  107. package/src/runtime/file_effect_crash_tests.zig +37 -0
  108. package/src/runtime/flow.zig +35 -10
  109. package/src/runtime/gpu_surface_events.zig +6 -1
  110. package/src/runtime/native_command_event_tests.zig +86 -2
  111. package/src/runtime/persist_store.zig +666 -0
  112. package/src/runtime/pty.zig +5 -2
  113. package/src/runtime/record_store.zig +788 -0
  114. package/src/runtime/relational_store.zig +854 -0
  115. package/src/runtime/root.zig +54 -0
  116. package/src/runtime/runtime_event_tests.zig +70 -0
  117. package/src/runtime/service_host.zig +711 -0
  118. package/src/runtime/service_pool.zig +1314 -0
  119. package/src/runtime/session_blobs.zig +4 -1
  120. package/src/runtime/session_journal.zig +158 -5
  121. package/src/runtime/session_record.zig +215 -0
  122. package/src/runtime/session_replay.zig +206 -11
  123. package/src/runtime/session_tests.zig +81 -0
  124. package/src/runtime/shell_layout.zig +1 -0
  125. package/src/runtime/shell_layout_tests.zig +120 -0
  126. package/src/runtime/sqlite_engine.zig +474 -0
  127. package/src/runtime/state.zig +16 -0
  128. package/src/runtime/system_services.zig +170 -38
  129. package/src/runtime/tests.zig +4 -0
  130. package/src/runtime/ts_core_host.zig +1067 -95
  131. package/src/runtime/ts_core_host_tests.zig +325 -11
  132. package/src/runtime/ts_ui_app.zig +953 -2
  133. package/src/runtime/ui_app.zig +434 -96
  134. package/src/runtime/ui_app_tests.zig +287 -11
  135. package/src/runtime/ui_app_window_tests.zig +61 -7
  136. package/src/runtime/validation.zig +42 -0
  137. package/src/runtime/view.zig +9 -0
  138. package/src/runtime/window_storage.zig +1 -0
  139. package/src/runtime/window_view_runtime.zig +2 -3
  140. package/src/runtime/window_views.zig +19 -0
  141. package/src/tooling/android.zig +21 -16
  142. package/src/tooling/db.zig +160 -0
  143. package/src/tooling/ios.zig +7 -1
  144. package/src/tooling/manifest.zig +214 -2
  145. package/src/tooling/package.zig +116 -0
  146. package/src/tooling/raw_manifest.zig +30 -0
  147. package/src/tooling/root.zig +1 -0
  148. package/src/tooling/templates.zig +189 -4
  149. package/src/tooling/ts_core.zig +366 -17
  150. package/src/tooling/verbs.zig +7 -0
  151. package/third_party/sqlite/README.md +13 -0
  152. package/third_party/sqlite/sqlite3.c +269649 -0
  153. package/third_party/sqlite/sqlite3.h +14349 -0
  154. package/tools/corewire/core_abi.zig +14 -2
  155. package/tools/corewire/emit.zig +98 -29
  156. package/tools/corewire/emit_facade.zig +442 -27
  157. package/tools/corewire/emit_profile.zig +6 -2
  158. package/tools/corewire/emit_service.zig +924 -0
  159. package/tools/corewire/main.zig +122 -0
  160. package/tools/corewire/service_contract.zig +250 -0
  161. package/tools/corewire/sidecar.zig +26 -15
@@ -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 v3 command set:
13
+ // The v5 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
@@ -32,9 +32,11 @@
32
32
  // re-issuing a live key replaces it, and
33
33
  // Cmd.cancel(key) drops it.
34
34
  // Cmd.cancel(key) drop the in-flight keyed effect — request,
35
- // readFile/writeFile/fetch/clipboardRead, or
35
+ // readFile/writeFile/readFileStream/fetch/
36
+ // clipboardRead, or
36
37
  // delay — SILENTLY (no terminal arm dispatch).
37
- // Aimed at a live spawn or streaming fetch it
38
+ // Aimed at a live spawn, streaming fetch, or
39
+ // streaming service or write-file sink it
38
40
  // stays LOUD: the err arm runs with
39
41
  // "cancelled" — ending a stream is observable
40
42
  // Cmd.batch([a, b, ...]) several commands from one dispatch
@@ -52,6 +54,12 @@
52
54
  // whole-file write (parents created, replaced
53
55
  // whole); ok arm carries NOTHING (an arm with
54
56
  // no payload fields), err arm the reason bytes
57
+ // Cmd.appendFile / statFile / deleteFile
58
+ // bounded append, metadata probe, and deletion
59
+ // Cmd.readFileStream 256-KiB chunks, then done(total) or err
60
+ // Cmd.writeFileStream / writeFileChunk / writeFileClose
61
+ // atomic streamed sink; chunks are acknowledged
62
+ // in order and close installs the destination
55
63
  // Cmd.fetch({ url, method?, headers?, body?, timeoutMs? }, { key?, ok, err })
56
64
  // buffered HTTP(S) exchange; ok arm carries a
57
65
  // two-field record — one number field (the real
@@ -72,9 +80,21 @@
72
80
  // clipboard read; ok arm carries the text bytes,
73
81
  // err arm the reason bytes ("failed",
74
82
  // "rejected")
75
- // Cmd.showNotification({ title, subtitle?, body? })
83
+ // Cmd.showNotification({ id?, title, subtitle?, body?, actionLabel?, actionCommand? })
76
84
  // fire-and-forget desktop notification; the OS
77
85
  // remains authoritative over final delivery
86
+ // Cmd.openExternalUrl(url) open an allowed HTTP(S) URL in the system
87
+ // browser; denied/invalid URLs fail closed
88
+ // Cmd.revealPath(path) reveal a path in the system file manager;
89
+ // invalid/unavailable requests fail closed
90
+ // Cmd.credentials.set(key, secret, route)
91
+ // Cmd.credentials.get(key, route)
92
+ // Cmd.credentials.delete(key, route)
93
+ // routed access to Keychain / Secret Service /
94
+ // Credential Manager
95
+ // Cmd.formatLocalTime(ms, style, route)
96
+ // format an epoch timestamp through the host's
97
+ // current locale and time zone
78
98
  // Cmd.delay(key, ms, "fired") a keyed ONE-SHOT timer: dispatches the named
79
99
  // arm once after `ms`, with the fire time (ms)
80
100
  // as its single number payload; re-issuing a
@@ -229,6 +249,10 @@
229
249
  // "Open" consequence; also restores a
230
250
  // minimized window. An unknown label is a
231
251
  // no-op.
252
+ // Cmd.hideWindow(label) order a live window out while retaining
253
+ // its views; showWindow is the inverse.
254
+ // Cmd.setDockPresence(visible) show or remove the app from the macOS
255
+ // Dock/app switcher.
232
256
  // Cmd.quitApp() graceful terminate, the tray "Quit"
233
257
  // consequence: the host quits through the
234
258
  // SAME shutdown path a last-window close
@@ -238,10 +262,12 @@
238
262
  // The keyed-effect discipline is ONE rule: a keyed effect REPLACES its live
239
263
  // predecessor (the superseded effect's result is dropped — no message), and
240
264
  // Cmd.cancel drops it silently. That holds for request, readFile, writeFile,
241
- // buffered fetch, clipboardRead, and delay alike. Live spawn and streaming-
242
- // fetch keys are the exceptions: a duplicate REJECTS the new stream (err arm
243
- // "rejected") so results from two sources are never spliced together. Cancel
244
- // either stream first; its err arm runs with "cancelled".
265
+ // readFileStream, buffered fetch, clipboardRead, and delay alike. A reissued
266
+ // readFileStream key retires the old read silently and starts the replacement.
267
+ // Live spawn, streaming-fetch, streaming-service, and write-file SINK keys are
268
+ // the exceptions: a duplicate REJECTS the new stream/sink so two producers are
269
+ // never spliced. Cancelling a sink is loud (`err: cancelled`) because a
270
+ // half-written export is observable; cancelling a read stream is silent.
245
271
  //
246
272
  // `Sub` is the recurring-effects surface: an app may export
247
273
  // `subscriptions(model): Sub<Msg>` returning declarative descriptors the
@@ -262,22 +288,127 @@
262
288
  // import "@native-sdk/core", so tsc-in-the-editor and `native check` agree.
263
289
  /// <reference path="./bytes_text_methods.d.ts" />
264
290
 
265
- /// The text intrinsic: turn a string literal or template into bytes. The
266
- /// transpiler recognizes calls BY IDENTITY (this import, renames honored)
267
- /// and folds them at compile time — a literal argument becomes rodata, a
268
- /// template becomes frame-arena bytes via bufPrint — so no string ever
269
- /// exists at native runtime. Under node this body runs as-is, byte for
270
- /// byte the same result. Arguments must be literals or templates; dynamic
271
- /// text lives in the model as Uint8Array from the start.
291
+ /// The ASCII text intrinsic: turn a string literal or template whose code
292
+ /// units are all 0x00..0x7f into bytes. The transpiler recognizes calls BY
293
+ /// IDENTITY (this import, renames honored) and folds them at compile time —
294
+ /// a literal argument becomes rodata, a template becomes frame-arena bytes
295
+ /// via bufPrint — so no string ever exists at native runtime. Under node
296
+ /// this body runs as-is, byte for byte the same result. Use `utf8Bytes` for
297
+ /// user-visible text that may contain Unicode. Arguments must be literals
298
+ /// or templates; dynamic text lives in the model as Uint8Array from the
299
+ /// start.
272
300
  export function asciiBytes(s: string): Uint8Array {
301
+ for (let i = 0; i < s.length; i++) {
302
+ if (s.charCodeAt(i) > 0x7f) {
303
+ throw new RangeError("asciiBytes accepts ASCII only; use utf8Bytes for Unicode text");
304
+ }
305
+ }
273
306
  const out = new Uint8Array(s.length);
274
307
  for (let i = 0; i < s.length; i++) out[i] = s.charCodeAt(i);
275
308
  return out;
276
309
  }
277
310
 
311
+ /// The UTF-8 text intrinsic. Like `asciiBytes`, literals become rodata and
312
+ /// templates become frame-arena bytes in a native core; under node this
313
+ /// implementation performs the same encoding directly. Invalid lone UTF-16
314
+ /// surrogates encode as U+FFFD, matching the platform TextEncoder contract.
315
+ export function utf8Bytes(s: string): Uint8Array {
316
+ let byteLength = 0;
317
+ for (let i = 0; i < s.length; i++) {
318
+ const code = s.charCodeAt(i);
319
+ if (code <= 0x7f) {
320
+ byteLength += 1;
321
+ } else if (code <= 0x7ff) {
322
+ byteLength += 2;
323
+ } else if (code >= 0xd800 && code <= 0xdbff && i + 1 < s.length) {
324
+ const next = s.charCodeAt(i + 1);
325
+ if (next >= 0xdc00 && next <= 0xdfff) {
326
+ byteLength += 4;
327
+ i += 1;
328
+ } else {
329
+ byteLength += 3;
330
+ }
331
+ } else {
332
+ byteLength += 3;
333
+ }
334
+ }
335
+
336
+ const out = new Uint8Array(byteLength);
337
+ let at = 0;
338
+ for (let i = 0; i < s.length; i++) {
339
+ let code = s.charCodeAt(i);
340
+ if (code >= 0xd800 && code <= 0xdbff && i + 1 < s.length) {
341
+ const next = s.charCodeAt(i + 1);
342
+ if (next >= 0xdc00 && next <= 0xdfff) {
343
+ code = 0x10000 + ((code - 0xd800) << 10) + (next - 0xdc00);
344
+ i += 1;
345
+ } else {
346
+ code = 0xfffd;
347
+ }
348
+ } else if (code >= 0xd800 && code <= 0xdfff) {
349
+ code = 0xfffd;
350
+ }
351
+
352
+ if (code <= 0x7f) {
353
+ out[at] = code;
354
+ at += 1;
355
+ } else if (code <= 0x7ff) {
356
+ out[at] = 0xc0 | (code >> 6);
357
+ out[at + 1] = 0x80 | (code & 0x3f);
358
+ at += 2;
359
+ } else if (code <= 0xffff) {
360
+ out[at] = 0xe0 | (code >> 12);
361
+ out[at + 1] = 0x80 | ((code >> 6) & 0x3f);
362
+ out[at + 2] = 0x80 | (code & 0x3f);
363
+ at += 3;
364
+ } else {
365
+ out[at] = 0xf0 | (code >> 18);
366
+ out[at + 1] = 0x80 | ((code >> 12) & 0x3f);
367
+ out[at + 2] = 0x80 | ((code >> 6) & 0x3f);
368
+ out[at + 3] = 0x80 | (code & 0x3f);
369
+ at += 4;
370
+ }
371
+ }
372
+ return out;
373
+ }
374
+
278
375
  /// Every app Msg is a discriminated union on a string `kind` tag.
279
376
  export type Msgish = { readonly kind: string };
280
377
 
378
+ import { type WindowDescriptor, type WindowDescriptorSpec } from "./events.ts";
379
+
380
+ /// Fill the canonical defaults for a model-declared secondary window.
381
+ export function windowDescriptor(spec: WindowDescriptorSpec): WindowDescriptor {
382
+ return {
383
+ label: spec.label,
384
+ canvasLabel: spec.canvasLabel,
385
+ title: spec.title ?? new Uint8Array(0),
386
+ width: spec.width ?? 480,
387
+ height: spec.height ?? 360,
388
+ x: spec.x ?? null,
389
+ y: spec.y ?? null,
390
+ resizable: spec.resizable ?? true,
391
+ minWidth: spec.minWidth ?? 0,
392
+ minHeight: spec.minHeight ?? 0,
393
+ titlebar: spec.titlebar ?? "standard",
394
+ transparent: spec.transparent ?? false,
395
+ alwaysOnTop: spec.alwaysOnTop ?? false,
396
+ clickThrough: spec.clickThrough ?? false,
397
+ activateOnShow: spec.activateOnShow ?? true,
398
+ allowsFullscreen: spec.allowsFullscreen ?? true,
399
+ closePolicy: spec.closePolicy ?? "quit",
400
+ onCloseCommand: spec.onCloseCommand ?? new Uint8Array(0),
401
+ };
402
+ }
403
+
404
+ /** Cooperative cancellation capability supplied by generated service hosts. */
405
+ export interface ServiceCancellation {
406
+ /** True after Cmd.cancel or the operation deadline requests cancellation. */
407
+ readonly cancelled: () => boolean;
408
+ /** Throw a boundary-tagged cancellation error when cancellation was requested. */
409
+ readonly throwIfCancelled: () => void;
410
+ }
411
+
281
412
  /// The Msg arms `Cmd.now` may target: arms whose payload is exactly one
282
413
  /// number-typed field (the runtime dispatches the arm with the timestamp in
283
414
  /// that field). Anything else is unrepresentable — the runtime has only a
@@ -305,6 +436,38 @@ export type BytesKind<M extends Msgish> = M extends Msgish
305
436
  }[Exclude<keyof M, "kind">]
306
437
  : never;
307
438
 
439
+ /// The Msg arms a generated typed service client may target: exactly one
440
+ /// payload field whose type is the operation's declared result shape.
441
+ export type ServiceKind<M extends Msgish, P> = M extends Msgish
442
+ ? {
443
+ [K in Exclude<keyof M, "kind">]-?: M[K] extends P
444
+ ? P extends M[K]
445
+ ? [Exclude<keyof M, "kind">] extends [K]
446
+ ? M["kind"]
447
+ : never
448
+ : never
449
+ : never;
450
+ }[Exclude<keyof M, "kind">]
451
+ : never;
452
+
453
+ /// Routing for a generated typed service call. Success carries the
454
+ /// operation's declared record/value shape; failures remain UTF-8 bytes so
455
+ /// transport, timeout, cancellation, and service `{ kind, message }` errors
456
+ /// share one stable error channel.
457
+ export interface ServiceRoute<M extends Msgish, P> {
458
+ readonly key?: string;
459
+ readonly ok: ServiceKind<M, P>;
460
+ readonly err: BytesKind<M>;
461
+ }
462
+
463
+ /// A streaming service opens an external-source channel before issuing the
464
+ /// request. Interim chunks arrive as canonical bytes on `event`; `ok` is the
465
+ /// one typed terminal and `err` is the loud cancellation/timeout/error arm.
466
+ export interface ServiceStreamRoute<M extends Msgish, P> extends ServiceRoute<M, P> {
467
+ readonly channelKey: number;
468
+ readonly event: ChannelEventKind<M>;
469
+ }
470
+
308
471
  /// The Msg arms a payload-less routed result may target: arms with no
309
472
  /// payload fields at all (`Cmd.writeFile`'s ok route — a successful write
310
473
  /// has nothing to report beyond success).
@@ -722,6 +885,92 @@ export interface WriteRoute<M extends Msgish> {
722
885
  readonly err: BytesKind<M>;
723
886
  }
724
887
 
888
+ /// Streaming read routing: zero or more 256-KiB `chunk` messages, then one
889
+ /// `done` carrying the total byte count, or one `err` carrying a closed file
890
+ /// outcome.
891
+ export interface FileReadStreamRoute<M extends Msgish> {
892
+ readonly key?: string;
893
+ readonly chunk: BytesKind<M>;
894
+ readonly done: TimestampKind<M>;
895
+ readonly err: BytesKind<M>;
896
+ }
897
+
898
+ export interface FileStatArm {
899
+ readonly exists: boolean;
900
+ readonly size: number;
901
+ readonly mtimeMs: number;
902
+ }
903
+
904
+ export type FileStatKind<M extends Msgish> = M extends Msgish
905
+ ? [Exclude<keyof M, "kind">] extends [keyof FileStatArm]
906
+ ? [keyof FileStatArm] extends [Exclude<keyof M, "kind">]
907
+ ? M extends Msgish & FileStatArm ? M["kind"] : never
908
+ : never
909
+ : never
910
+ : never;
911
+
912
+ export interface FileStatRoute<M extends Msgish> {
913
+ readonly key?: string;
914
+ readonly ok: FileStatKind<M>;
915
+ readonly err: BytesKind<M>;
916
+ }
917
+
918
+ /// Pagination controls for `Cmd.store.scan`. `limit` defaults to 100 and is
919
+ /// bounded at 256. `after` is the opaque key cursor returned by the previous
920
+ /// page; omit it for the first page.
921
+ export interface StoreScanOptions {
922
+ readonly limit?: number;
923
+ readonly after?: string | Uint8Array;
924
+ }
925
+
926
+ /// Dynamic UTF-8 SQLite TEXT. App-core text is byte-honest, so generated
927
+ /// TEXT parameters wrap model bytes with this marker; literal strings remain
928
+ /// accepted by the raw escape hatch.
929
+ export interface DbText {
930
+ readonly __dbText: true;
931
+ readonly bytes: ReadonlyArray<number>;
932
+ }
933
+
934
+ export function dbText(bytes: Uint8Array): DbText {
935
+ const out: number[] = [];
936
+ for (let i = 0; i < bytes.length; i++) out.push(bytes[i]!);
937
+ return { __dbText: true, bytes: out };
938
+ }
939
+
940
+ /// Runtime SQL parameter values. Numbers preserve integer storage when they
941
+ /// are finite integral values; booleans bind as SQLite INTEGER 0/1.
942
+ export type DbValue = null | number | string | Uint8Array | boolean | DbText;
943
+ export type DbStatement = readonly [sql: string, params: ReadonlyArray<DbValue>];
944
+
945
+ /// A query dispatches every encoded row page through `page`, then exactly one
946
+ /// payload-less `done`. Any closed DbOutcome instead dispatches `err` as its
947
+ /// UTF-8 name (`constraint`, `busy`, `io_failed`, `corrupt`, `misuse`,
948
+ /// `rejected`, or `cancelled`).
949
+ export interface DbRowsRoute<M extends Msgish> {
950
+ readonly key?: string;
951
+ readonly page: BytesKind<M>;
952
+ readonly done: EmptyKind<M>;
953
+ readonly err: BytesKind<M>;
954
+ }
955
+
956
+ /// A generated declared-query route. The row parameter is intentionally
957
+ /// phantom on the wire: generated `decode<Name>Page` turns each bounded page
958
+ /// into this exact row shape without reflection.
959
+ export interface TypedRowsRoute<Row, M extends Msgish> extends DbRowsRoute<M> {
960
+ readonly __row?: Row;
961
+ }
962
+
963
+ /// One generated, already-validated write statement. Only generated query
964
+ /// constructors create the brand; `Cmd.qTx` therefore cannot receive a
965
+ /// raw SQL string by accident.
966
+ export interface TypedDbStatement {
967
+ readonly sql: string;
968
+ readonly params: ReadonlyArray<DbValue>;
969
+ readonly __typedDbStatement: true;
970
+ }
971
+
972
+ // @native-sqlite-generated-types
973
+
725
974
  /// `Cmd.fetch` routing: the ok arm carries `{ status, body }` (one number
726
975
  /// field, one bytes field — matched by type); the err arm the reason bytes.
727
976
  export interface FetchRoute<M extends Msgish> {
@@ -858,11 +1107,19 @@ export interface FetchStreamSpec extends FetchSpec {
858
1107
  /// fire-and-forget because the OS may suppress an accepted request through
859
1108
  /// Focus / Do Not Disturb or the user's notification settings.
860
1109
  export interface NotificationSpec {
1110
+ readonly id?: Uint8Array;
861
1111
  readonly title: Uint8Array;
862
1112
  readonly subtitle?: Uint8Array;
863
1113
  readonly body?: Uint8Array;
1114
+ readonly actionLabel?: Uint8Array;
1115
+ readonly actionCommand?: Uint8Array;
864
1116
  }
865
1117
 
1118
+ /// The three bounded host-local timestamp presentations. Unlike the markup
1119
+ /// `date`/`time`/`datetime` functions (fixed UTC), this is intentionally an
1120
+ /// effect because the user's locale and time zone are ambient host state.
1121
+ export type LocalTimeStyle = "date" | "time" | "datetime";
1122
+
866
1123
  /// An inert command value, parameterized by the app's Msg union so the
867
1124
  /// factories can validate message targets. Opaque to app code: build with
868
1125
  /// the `Cmd.*` factories, return from `update`/`initialModel`, never inspect
@@ -879,6 +1136,19 @@ export type Cmd<M extends Msgish> =
879
1136
  readonly key: string;
880
1137
  readonly okKind: string;
881
1138
  readonly errKind: string;
1139
+ readonly typedService: boolean;
1140
+ readonly payload: Uint8Array;
1141
+ }
1142
+ | {
1143
+ readonly op: "service_stream_request";
1144
+ readonly name: string;
1145
+ readonly key: string;
1146
+ readonly okKind: string;
1147
+ readonly errKind: string;
1148
+ readonly typedService: true;
1149
+ readonly channelKey: number;
1150
+ readonly eventKind: string;
1151
+ readonly maxPending: number;
882
1152
  readonly payload: Uint8Array;
883
1153
  }
884
1154
  | { readonly op: "cancel"; readonly key: string }
@@ -897,6 +1167,103 @@ export type Cmd<M extends Msgish> =
897
1167
  readonly path: Uint8Array;
898
1168
  readonly bytes: Uint8Array;
899
1169
  }
1170
+ | {
1171
+ readonly op: "append_file";
1172
+ readonly key: string;
1173
+ readonly okKind: string;
1174
+ readonly errKind: string;
1175
+ readonly path: Uint8Array;
1176
+ readonly bytes: Uint8Array;
1177
+ }
1178
+ | {
1179
+ readonly op: "stat_file";
1180
+ readonly key: string;
1181
+ readonly okKind: string;
1182
+ readonly errKind: string;
1183
+ readonly path: Uint8Array;
1184
+ }
1185
+ | {
1186
+ readonly op: "delete_file";
1187
+ readonly key: string;
1188
+ readonly okKind: string;
1189
+ readonly errKind: string;
1190
+ readonly path: Uint8Array;
1191
+ }
1192
+ | {
1193
+ readonly op: "read_file_stream";
1194
+ readonly key: string;
1195
+ readonly chunkKind: string;
1196
+ readonly doneKind: string;
1197
+ readonly errKind: string;
1198
+ readonly path: Uint8Array;
1199
+ }
1200
+ | {
1201
+ readonly op: "write_file_stream";
1202
+ readonly key: string;
1203
+ readonly okKind: string;
1204
+ readonly errKind: string;
1205
+ readonly path: Uint8Array;
1206
+ }
1207
+ | {
1208
+ readonly op: "write_file_chunk";
1209
+ readonly key: string;
1210
+ readonly okKind: string;
1211
+ readonly errKind: string;
1212
+ readonly bytes: Uint8Array;
1213
+ }
1214
+ | {
1215
+ readonly op: "write_file_close";
1216
+ readonly key: string;
1217
+ readonly okKind: string;
1218
+ readonly errKind: string;
1219
+ }
1220
+ | {
1221
+ readonly op: "store_set";
1222
+ readonly key: string;
1223
+ readonly okKind: string;
1224
+ readonly errKind: string;
1225
+ readonly storeKey: string;
1226
+ readonly bytes: Uint8Array;
1227
+ }
1228
+ | {
1229
+ readonly op: "store_get" | "store_delete";
1230
+ readonly key: string;
1231
+ readonly okKind: string;
1232
+ readonly errKind: string;
1233
+ readonly storeKey: string;
1234
+ }
1235
+ | {
1236
+ readonly op: "store_scan";
1237
+ readonly key: string;
1238
+ readonly okKind: string;
1239
+ readonly errKind: string;
1240
+ readonly prefix: string;
1241
+ readonly limit: number;
1242
+ readonly after: string | Uint8Array;
1243
+ }
1244
+ | {
1245
+ readonly op: "store_set_many";
1246
+ readonly key: string;
1247
+ readonly okKind: string;
1248
+ readonly errKind: string;
1249
+ readonly entries: ReadonlyArray<readonly [string, Uint8Array]>;
1250
+ }
1251
+ | {
1252
+ readonly op: "db_query";
1253
+ readonly key: string;
1254
+ readonly pageKind: string;
1255
+ readonly doneKind: string;
1256
+ readonly errKind: string;
1257
+ readonly sql: string;
1258
+ readonly params: ReadonlyArray<DbValue>;
1259
+ }
1260
+ | {
1261
+ readonly op: "db_exec";
1262
+ readonly key: string;
1263
+ readonly okKind: string;
1264
+ readonly errKind: string;
1265
+ readonly statements: ReadonlyArray<DbStatement>;
1266
+ }
900
1267
  | {
901
1268
  readonly op: "fetch";
902
1269
  readonly key: string;
@@ -927,7 +1294,7 @@ export type Cmd<M extends Msgish> =
927
1294
  }
928
1295
  | { readonly op: "clip_write"; readonly bytes: Uint8Array }
929
1296
  | { readonly op: "clip_read"; readonly key: string; readonly okKind: string; readonly errKind: string }
930
- | { readonly op: "show_notification"; readonly title: Uint8Array; readonly subtitle: Uint8Array; readonly body: Uint8Array }
1297
+ | { readonly op: "show_notification"; readonly id: Uint8Array; readonly title: Uint8Array; readonly subtitle: Uint8Array; readonly body: Uint8Array; readonly actionLabel: Uint8Array; readonly actionCommand: Uint8Array }
931
1298
  | { readonly op: "delay"; readonly key: string; readonly afterMs: number; readonly msgKind: string }
932
1299
  | {
933
1300
  readonly op: "spawn";
@@ -977,6 +1344,8 @@ export type Cmd<M extends Msgish> =
977
1344
  readonly value: number;
978
1345
  }
979
1346
  | { readonly op: "window_show"; readonly label: string }
1347
+ | { readonly op: "window_hide"; readonly label: string }
1348
+ | { readonly op: "dock_presence"; readonly visible: boolean }
980
1349
  | { readonly op: "quit_app" }
981
1350
  | {
982
1351
  readonly op: "image_load";
@@ -989,7 +1358,7 @@ export type Cmd<M extends Msgish> =
989
1358
  }
990
1359
  | { readonly op: "image_cancel"; readonly id: number }
991
1360
  | { readonly op: "image_unregister"; readonly id: number }
992
- | { readonly op: "channel_open"; readonly key: number; readonly eventKind: string }
1361
+ | { readonly op: "channel_open"; readonly key: number; readonly eventKind: string; readonly maxPending: number }
993
1362
  | { readonly op: "channel_close"; readonly key: number }
994
1363
  | {
995
1364
  readonly op: "audio_capture_start";
@@ -1050,6 +1419,74 @@ export function hostRecordBytes(payload: HostRecord): Uint8Array {
1050
1419
  return out;
1051
1420
  }
1052
1421
 
1422
+ function serviceU32(value: number): Uint8Array {
1423
+ const out = new Uint8Array(4);
1424
+ out[0] = value & 255;
1425
+ out[1] = (value >>> 8) & 255;
1426
+ out[2] = (value >>> 16) & 255;
1427
+ out[3] = (value >>> 24) & 255;
1428
+ return out;
1429
+ }
1430
+
1431
+ /// Canonical service-value codec primitives. Generated clients compose these
1432
+ /// in declaration order; the service host and Zig result dispatcher consume
1433
+ /// the same format as shim_rt (LE scalars, length-prefixed bytes/slices,
1434
+ /// declaration-order enum/union tags).
1435
+ export function serviceConcat(parts: readonly Uint8Array[]): Uint8Array {
1436
+ let length = 0;
1437
+ for (const part of parts) length += part.length;
1438
+ const out = new Uint8Array(length);
1439
+ let at = 0;
1440
+ for (const part of parts) {
1441
+ out.set(part, at);
1442
+ at += part.length;
1443
+ }
1444
+ return out;
1445
+ }
1446
+
1447
+ export function serviceBoolBytes(value: boolean): Uint8Array {
1448
+ return new Uint8Array([value ? 1 : 0]);
1449
+ }
1450
+
1451
+ export function serviceF64Bytes(value: number): Uint8Array {
1452
+ const out = new Uint8Array(8);
1453
+ const view = new DataView(out.buffer);
1454
+ view.setFloat64(0, Number.isNaN(value) ? Number.NaN : value, true);
1455
+ return out;
1456
+ }
1457
+
1458
+ export function serviceI64Bytes(value: number): Uint8Array {
1459
+ const out = new Uint8Array(8);
1460
+ const view = new DataView(out.buffer);
1461
+ const base = 4294967296;
1462
+ let low = value % base;
1463
+ if (low < 0) low += base;
1464
+ const high = Math.floor(value / base);
1465
+ view.setUint32(0, low, true);
1466
+ view.setInt32(4, high, true);
1467
+ return out;
1468
+ }
1469
+
1470
+ export function serviceBytes(value: Uint8Array): Uint8Array {
1471
+ return serviceConcat([serviceU32(value.length), value]);
1472
+ }
1473
+
1474
+ export function serviceEnumBytes(index: number): Uint8Array {
1475
+ return serviceU32(index);
1476
+ }
1477
+
1478
+ export function serviceUnionBytes(index: number): Uint8Array {
1479
+ return new Uint8Array([index]);
1480
+ }
1481
+
1482
+ export function serviceOptionalBytes(value: Uint8Array | null): Uint8Array {
1483
+ return value === null ? new Uint8Array([0]) : serviceConcat([new Uint8Array([1]), value]);
1484
+ }
1485
+
1486
+ export function serviceSliceBytes(values: readonly Uint8Array[]): Uint8Array {
1487
+ return serviceConcat([serviceU32(values.length), ...values]);
1488
+ }
1489
+
1053
1490
  function lowerHostPayload(payload: Uint8Array | HostRecord): Uint8Array {
1054
1491
  return payload instanceof Uint8Array ? payload : hostRecordBytes(payload);
1055
1492
  }
@@ -1113,7 +1550,9 @@ export const Cmd = {
1113
1550
  /// No effects. `return model` is sugar for `return [model, Cmd.none]`.
1114
1551
  none: { op: "none" } as Cmd<never>,
1115
1552
 
1116
- /// Ask the host to persist the committed model.
1553
+ /// Snapshot the just-committed Model through the engine-owned store.
1554
+ /// Requires app.zon's `persist` capability and restore-route config;
1555
+ /// the host owns coalescing, atomic placement, and journal/replay.
1117
1556
  persist(): Cmd<never> {
1118
1557
  return { op: "persist" };
1119
1558
  },
@@ -1143,13 +1582,54 @@ export const Cmd = {
1143
1582
  key: route.key ?? "",
1144
1583
  okKind: route.ok,
1145
1584
  errKind: route.err,
1585
+ typedService: false,
1146
1586
  payload: lowerHostPayload(payload),
1147
1587
  };
1148
1588
  },
1149
1589
 
1590
+ /// Generated typed service clients use this constructor after encoding the
1591
+ /// request shape. It lowers to the ordinary request wire record with the
1592
+ /// typed-result bit set so the host decodes the success payload.
1593
+ serviceRequest<M extends Msgish, P>(
1594
+ name: string,
1595
+ payload: Uint8Array,
1596
+ route: ServiceRoute<M, P>,
1597
+ ): Cmd<M> {
1598
+ return {
1599
+ op: "request",
1600
+ name,
1601
+ key: route.key ?? "",
1602
+ okKind: route.ok,
1603
+ errKind: route.err,
1604
+ typedService: true,
1605
+ payload,
1606
+ };
1607
+ },
1608
+
1609
+ serviceStreamRequest<M extends Msgish, P>(
1610
+ name: string,
1611
+ channelKey: number,
1612
+ payload: Uint8Array,
1613
+ route: ServiceStreamRoute<M, P>,
1614
+ maxPending: number,
1615
+ ): Cmd<M> {
1616
+ return {
1617
+ op: "service_stream_request",
1618
+ name,
1619
+ key: route.key ?? "",
1620
+ okKind: route.ok,
1621
+ errKind: route.err,
1622
+ typedService: true,
1623
+ channelKey,
1624
+ eventKind: route.event,
1625
+ maxPending,
1626
+ payload: serviceConcat([serviceF64Bytes(channelKey), payload]),
1627
+ };
1628
+ },
1629
+
1150
1630
  /// Drop the in-flight keyed effect — request, named engine op, or delay —
1151
1631
  /// with this key, if any, SILENTLY (neither routing arm is dispatched for
1152
- /// it). Live spawn and streaming-fetch operations are the exceptions:
1632
+ /// it). Live spawn, streaming-fetch, streaming-service, and write-file-sink operations are the exceptions:
1153
1633
  /// cancel ends the stream and its err arm runs with "cancelled".
1154
1634
  cancel(key: string): Cmd<never> {
1155
1635
  return { op: "cancel", key };
@@ -1169,6 +1649,134 @@ export const Cmd = {
1169
1649
  return { op: "write_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path, bytes };
1170
1650
  },
1171
1651
 
1652
+ appendFile<M extends Msgish>(path: Uint8Array, bytes: Uint8Array, route: WriteRoute<M>): Cmd<M> {
1653
+ return { op: "append_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path, bytes };
1654
+ },
1655
+
1656
+ statFile<M extends Msgish>(path: Uint8Array, route: FileStatRoute<M>): Cmd<M> {
1657
+ return { op: "stat_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path };
1658
+ },
1659
+
1660
+ /// Delete one file. The ok arm carries no payload. A final symlink is
1661
+ /// unlinked without deleting its target. A missing file routes the err arm
1662
+ /// with "not_found"; directories and other OS refusals route "io_failed".
1663
+ deleteFile<M extends Msgish>(path: Uint8Array, route: WriteRoute<M>): Cmd<M> {
1664
+ return { op: "delete_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path };
1665
+ },
1666
+
1667
+ readFileStream<M extends Msgish>(path: Uint8Array, route: FileReadStreamRoute<M>): Cmd<M> {
1668
+ return { op: "read_file_stream", key: route.key ?? "", chunkKind: route.chunk, doneKind: route.done, errKind: route.err, path };
1669
+ },
1670
+
1671
+ writeFileStream<M extends Msgish>(key: string, path: Uint8Array, route: WriteRoute<M>): Cmd<M> {
1672
+ return { op: "write_file_stream", key, okKind: route.ok, errKind: route.err, path };
1673
+ },
1674
+
1675
+ writeFileChunk<M extends Msgish>(key: string, bytes: Uint8Array, route: WriteRoute<M>): Cmd<M> {
1676
+ return { op: "write_file_chunk", key, okKind: route.ok, errKind: route.err, bytes };
1677
+ },
1678
+
1679
+ writeFileClose<M extends Msgish>(key: string, route: WriteRoute<M>): Cmd<M> {
1680
+ return { op: "write_file_close", key, okKind: route.ok, errKind: route.err };
1681
+ },
1682
+
1683
+ /// Capability-gated, engine-owned per-record storage. Keys are UTF-8 text
1684
+ /// up to 512 bytes; values are bytes up to 1 MiB. Results remain effects:
1685
+ /// they arrive through the supplied Msg routes after update commits.
1686
+ store: {
1687
+ set<M extends Msgish>(storeKey: string, bytes: Uint8Array, route: WriteRoute<M>): Cmd<M> {
1688
+ return { op: "store_set", key: route.key ?? "", okKind: route.ok, errKind: route.err, storeKey, bytes };
1689
+ },
1690
+
1691
+ /// The ok payload is `[1][value...]` for a hit or `[0]` for a miss, so
1692
+ /// an empty stored value remains distinguishable from absence.
1693
+ get<M extends Msgish>(storeKey: string, route: RequestRoute<M>): Cmd<M> {
1694
+ return { op: "store_get", key: route.key ?? "", okKind: route.ok, errKind: route.err, storeKey };
1695
+ },
1696
+
1697
+ /// Deleting an absent key succeeds.
1698
+ delete<M extends Msgish>(storeKey: string, route: WriteRoute<M>): Cmd<M> {
1699
+ return { op: "store_delete", key: route.key ?? "", okKind: route.ok, errKind: route.err, storeKey };
1700
+ },
1701
+
1702
+ /// The ok payload is a length-prefixed page of `(key,value)` pairs and
1703
+ /// a next-key cursor. Pages end at record boundaries; data is never cut.
1704
+ scan<M extends Msgish>(prefix: string, options: StoreScanOptions, route: RequestRoute<M>): Cmd<M> {
1705
+ return {
1706
+ op: "store_scan",
1707
+ key: route.key ?? "",
1708
+ okKind: route.ok,
1709
+ errKind: route.err,
1710
+ prefix,
1711
+ limit: options.limit ?? 0,
1712
+ after: options.after ?? "",
1713
+ };
1714
+ },
1715
+
1716
+ /// Atomically upsert all entries (at most 64 entries / 8 MiB encoded).
1717
+ setMany<M extends Msgish>(entries: ReadonlyArray<readonly [string, Uint8Array]>, route: WriteRoute<M>): Cmd<M> {
1718
+ return { op: "store_set_many", key: route.key ?? "", okKind: route.ok, errKind: route.err, entries };
1719
+ },
1720
+ },
1721
+
1722
+ /// App-scoped OS credential storage. The app manifest id supplies the
1723
+ /// service namespace, so authored code chooses only a UTF-8 key. Declare
1724
+ /// both the `credentials` capability and permission in app.zon.
1725
+ credentials: {
1726
+ set<M extends Msgish>(credentialKey: string, secret: Uint8Array, route: WriteRoute<M>): Cmd<M> {
1727
+ return {
1728
+ op: "request",
1729
+ name: "core.credentials.set",
1730
+ key: route.key ?? "",
1731
+ okKind: route.ok,
1732
+ errKind: route.err,
1733
+ typedService: false,
1734
+ payload: hostRecordBytes({ key: utf8Bytes(credentialKey), secret }),
1735
+ };
1736
+ },
1737
+
1738
+ /// The ok arm carries secret bytes; a miss routes err with `miss`.
1739
+ get<M extends Msgish>(credentialKey: string, route: RequestRoute<M>): Cmd<M> {
1740
+ return Cmd.request("core.credentials.get", { key: utf8Bytes(credentialKey) }, route);
1741
+ },
1742
+
1743
+ /// Deleting an absent key succeeds.
1744
+ delete<M extends Msgish>(credentialKey: string, route: WriteRoute<M>): Cmd<M> {
1745
+ return {
1746
+ op: "request",
1747
+ name: "core.credentials.delete",
1748
+ key: route.key ?? "",
1749
+ okKind: route.ok,
1750
+ errKind: route.err,
1751
+ typedService: false,
1752
+ payload: hostRecordBytes({ key: utf8Bytes(credentialKey) }),
1753
+ };
1754
+ },
1755
+ },
1756
+
1757
+ /// Capability-gated relational SQLite. Reads remain effects: pages and the
1758
+ /// terminal arrive as Msg values after the issuing model has committed.
1759
+ /// Every exec statement in one command commits atomically or all roll back.
1760
+ db: {
1761
+ query<M extends Msgish>(sql: string, params: ReadonlyArray<DbValue>, route: DbRowsRoute<M>): Cmd<M> {
1762
+ return {
1763
+ op: "db_query",
1764
+ key: route.key ?? "",
1765
+ pageKind: route.page,
1766
+ doneKind: route.done,
1767
+ errKind: route.err,
1768
+ sql,
1769
+ params,
1770
+ };
1771
+ },
1772
+
1773
+ exec<M extends Msgish>(statements: ReadonlyArray<DbStatement>, route: WriteRoute<M>): Cmd<M> {
1774
+ return { op: "db_exec", key: route.key ?? "", okKind: route.ok, errKind: route.err, statements };
1775
+ },
1776
+ },
1777
+
1778
+ // @native-sqlite-generated-cmds
1779
+
1172
1780
  fetch: fetchCmd,
1173
1781
 
1174
1782
  /// Put bytes on the system clipboard, fire-and-forget (an over-bound or
@@ -1186,17 +1794,44 @@ export const Cmd = {
1186
1794
 
1187
1795
  /// Ask the desktop host to show a system notification. Fire-and-forget:
1188
1796
  /// platform acceptance cannot promise display while OS focus modes and user
1189
- /// notification settings remain authoritative. Empty or over-bound titles,
1190
- /// over-bound optional fields, and unavailable services fail closed.
1797
+ /// notification settings remain authoritative. A stable id replaces the
1798
+ /// earlier notification with that id; paired actionLabel/actionCommand bytes
1799
+ /// dispatch through the normal app-command path while the process is live.
1800
+ /// Empty or over-bound titles, over-bound optional fields, unpaired actions,
1801
+ /// invalid command names, and unavailable services fail closed.
1191
1802
  showNotification(spec: NotificationSpec): Cmd<never> {
1192
1803
  return {
1193
1804
  op: "show_notification",
1805
+ id: spec.id ?? new Uint8Array(0),
1194
1806
  title: spec.title,
1195
1807
  subtitle: spec.subtitle ?? new Uint8Array(0),
1196
1808
  body: spec.body ?? new Uint8Array(0),
1809
+ actionLabel: spec.actionLabel ?? new Uint8Array(0),
1810
+ actionCommand: spec.actionCommand ?? new Uint8Array(0),
1197
1811
  };
1198
1812
  },
1199
1813
 
1814
+ /// Open an HTTP(S) URL in the user's system browser. Fire-and-forget: the
1815
+ /// runtime validates the URL and enforces `external_links`; invalid,
1816
+ /// denied, or unavailable requests fail closed.
1817
+ openExternalUrl(url: Uint8Array): Cmd<never> {
1818
+ return { op: "host_bytes", name: "native-sdk.os.openUrl", payload: url };
1819
+ },
1820
+
1821
+ /// Reveal a path in the system file manager (Finder, Files, or Explorer).
1822
+ /// Fire-and-forget; invalid or unavailable requests fail closed.
1823
+ revealPath(path: Uint8Array): Cmd<never> {
1824
+ return { op: "host_bytes", name: "native-sdk.os.revealPath", payload: path };
1825
+ },
1826
+
1827
+ /// Format an epoch timestamp (milliseconds, the same unit as `Cmd.now`) in
1828
+ /// the host's current locale and local time zone. The localized UTF-8 text
1829
+ /// arrives on ok; invalid timestamps or unavailable services route err.
1830
+ formatLocalTime<M extends Msgish>(timestampMs: number, style: LocalTimeStyle, route: RequestRoute<M>): Cmd<M> {
1831
+ const styleCode = style === "date" ? 0 : style === "time" ? 1 : 2;
1832
+ return Cmd.request("native-sdk.time.formatLocal", { style: styleCode, timestampMs }, route);
1833
+ },
1834
+
1200
1835
  /// A keyed one-shot delay: dispatch the named Msg arm once, `ms` from now,
1201
1836
  /// with the fire time (milliseconds) as its single number payload field.
1202
1837
  /// Re-issuing a live key re-arms it from now (the debounce discipline);
@@ -1364,6 +1999,31 @@ export const Cmd = {
1364
1999
  return { op: "window_show", label };
1365
2000
  },
1366
2001
 
2002
+ /// Hide a live window without closing it. Its views and native identity
2003
+ /// remain intact; `showWindow` brings it back. Unknown labels no-op.
2004
+ hideWindow(label: string): Cmd<never> {
2005
+ return { op: "window_hide", label };
2006
+ },
2007
+
2008
+ /// Control whether the app appears in the macOS Dock and app switcher.
2009
+ /// Unsupported hosts ignore the command.
2010
+ setDockPresence(visible: boolean): Cmd<never> {
2011
+ return { op: "dock_presence", visible };
2012
+ },
2013
+
2014
+ /// Query the installed bundle's launch-at-login registration. The ok
2015
+ /// route receives UTF-8 bytes naming `enabled`, `disabled`,
2016
+ /// `requires_approval`, or `not_found`; the err route receives a reason.
2017
+ launchAtLoginStatus<M extends Msgish>(route: RequestRoute<M>): Cmd<M> {
2018
+ return Cmd.request("native-sdk.launch-at-login.status", new Uint8Array(0), route);
2019
+ },
2020
+
2021
+ /// Register or unregister the installed bundle for launch at login. The
2022
+ /// ok and err payloads follow `launchAtLoginStatus`.
2023
+ setLaunchAtLogin<M extends Msgish>(enabled: boolean, route: RequestRoute<M>): Cmd<M> {
2024
+ return Cmd.request("native-sdk.launch-at-login.set", new Uint8Array([enabled ? 1 : 0]), route);
2025
+ },
2026
+
1367
2027
  /// Quit the app for real — the graceful terminate, and the tray "Quit"
1368
2028
  /// consequence. The host quits through the SAME shutdown path a
1369
2029
  /// last-window close takes, so the stop hook runs exactly once and a
@@ -1455,7 +2115,7 @@ export const Cmd = {
1455
2115
  /// one that consults the handle's live() before launching never
1456
2116
  /// starts, keeping replay fully offline.
1457
2117
  channelOpen<M extends Msgish>(key: number, route: ChannelRoute<M>): Cmd<M> {
1458
- return { op: "channel_open", key, eventKind: route.event };
2118
+ return { op: "channel_open", key, eventKind: route.event, maxPending: 64 };
1459
2119
  },
1460
2120
 
1461
2121
  /// Close the open channel under `key`: posts stop landing, the
@@ -1558,6 +2218,16 @@ export const Cmd = {
1558
2218
  export type Sub<M extends Msgish> =
1559
2219
  | { readonly op: "none" }
1560
2220
  | { readonly op: "timer"; readonly key: string; readonly everyMs: number; readonly msgKind: string }
2221
+ | {
2222
+ readonly op: "db_live";
2223
+ readonly key: string;
2224
+ readonly pageKind: string;
2225
+ readonly doneKind: string;
2226
+ readonly errKind: string;
2227
+ readonly sql: string;
2228
+ readonly params: ReadonlyArray<DbValue>;
2229
+ readonly tables: readonly string[];
2230
+ }
1561
2231
  | { readonly op: "batch"; readonly subs: readonly Sub<M>[] };
1562
2232
 
1563
2233
  export const Sub = {
@@ -1571,6 +2241,8 @@ export const Sub = {
1571
2241
  return { op: "timer", key, everyMs, msgKind };
1572
2242
  },
1573
2243
 
2244
+ // @native-sqlite-generated-subs
2245
+
1574
2246
  /// Several subscriptions at once.
1575
2247
  batch<M extends Msgish>(subs: readonly Sub<M>[]): Sub<M> {
1576
2248
  return { op: "batch", subs };