@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
package/build.zig.zon CHANGED
@@ -27,6 +27,7 @@
27
27
  "src",
28
28
  "templates",
29
29
  "tests",
30
+ "third_party/sqlite",
30
31
  "tools",
31
32
  },
32
33
  }
package/native-sdk.d.ts CHANGED
@@ -216,6 +216,7 @@ export interface NativeSdkViewInfo {
216
216
  gpuFrame: number;
217
217
  gpuTimestampNs: number;
218
218
  gpuFrameIntervalNs: number;
219
+ gpuInputCount: number;
219
220
  gpuInputTimestampNs: number;
220
221
  gpuInputLatencyNs: number;
221
222
  gpuInputLatencyBudgetNs: number;
@@ -226,6 +227,7 @@ export interface NativeSdkViewInfo {
226
227
  gpuFirstFrameLatencyBudgetExceededCount: number;
227
228
  gpuFirstFrameLatencyBudgetOk: boolean;
228
229
  gpuNonblank: boolean;
230
+ gpuOccluded: boolean;
229
231
  gpuSampleColor: number;
230
232
  gpuBackend: NativeSdkGpuSurfaceBackend;
231
233
  gpuPixelFormat: NativeSdkGpuSurfacePixelFormat;
@@ -471,6 +473,8 @@ export interface NativeSdkCommandEvent {
471
473
  source: NativeSdkCommandSource;
472
474
  windowId: number;
473
475
  viewLabel: string;
476
+ /** Native status-item id for tray-sourced commands, otherwise 0. */
477
+ statusItemId: number;
474
478
  /** Native tray item id for tray-sourced commands, otherwise 0. */
475
479
  trayItemId: number;
476
480
  }
@@ -547,9 +551,15 @@ export interface NativeSdkRecentDocumentOptions {
547
551
  }
548
552
 
549
553
  export interface NativeSdkNotificationOptions {
554
+ /** Stable replacement/deduplication identifier. */
555
+ id?: string;
550
556
  title: string;
551
557
  subtitle?: string;
552
558
  body?: string;
559
+ /** Paired with actionCommand; both must be present or both omitted. */
560
+ actionLabel?: string;
561
+ /** Normal application command dispatched when the user activates the action. */
562
+ actionCommand?: string;
553
563
  }
554
564
 
555
565
  export interface NativeSdkClipboardReadOptions {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.8.4",
3
+ "version": "0.9.1",
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": {
@@ -25,23 +25,24 @@
25
25
  "packages/core/package-lock.json",
26
26
  "tools/corewire",
27
27
  "third_party/webview2",
28
+ "third_party/sqlite",
28
29
  "native-sdk.d.ts",
29
30
  "README.md",
30
31
  "LICENSE"
31
32
  ],
32
33
  "dependencies": {
33
34
  "@typescript/old": "npm:typescript@6.0.3",
34
- "scriptc": "0.0.22"
35
+ "scriptc": "0.0.31"
35
36
  },
36
37
  "optionalDependencies": {
37
- "@native-sdk/cli-darwin-arm64": "0.8.4",
38
- "@native-sdk/cli-darwin-x64": "0.8.4",
39
- "@native-sdk/cli-linux-arm64-gnu": "0.8.4",
40
- "@native-sdk/cli-linux-arm64-musl": "0.8.4",
41
- "@native-sdk/cli-linux-x64-gnu": "0.8.4",
42
- "@native-sdk/cli-linux-x64-musl": "0.8.4",
43
- "@native-sdk/cli-win32-arm64": "0.8.4",
44
- "@native-sdk/cli-win32-x64": "0.8.4"
38
+ "@native-sdk/cli-darwin-arm64": "0.9.1",
39
+ "@native-sdk/cli-darwin-x64": "0.9.1",
40
+ "@native-sdk/cli-linux-arm64-gnu": "0.9.1",
41
+ "@native-sdk/cli-linux-arm64-musl": "0.9.1",
42
+ "@native-sdk/cli-linux-x64-gnu": "0.9.1",
43
+ "@native-sdk/cli-linux-x64-musl": "0.9.1",
44
+ "@native-sdk/cli-win32-arm64": "0.9.1",
45
+ "@native-sdk/cli-win32-x64": "0.9.1"
45
46
  },
46
47
  "repository": {
47
48
  "type": "git",
@@ -49,7 +50,7 @@
49
50
  },
50
51
  "homepage": "https://native-sdk.dev",
51
52
  "scripts": {
52
- "version": "npm run version:sync && git add ../../tools/native-sdk/main.zig ../../packages/core/package.json ../../packages/core/package-lock.json ../../examples/kanban/package.json ../../examples/soundboard-ts/package.json ../../examples/system-monitor-ts/package.json npm/*/package.json package.json",
53
+ "version": "npm run version:sync && git add ../../tools/native-sdk/main.zig ../../packages/core/package.json ../../packages/core/package-lock.json ../../examples/*/package.json npm/*/package.json package.json",
53
54
  "version:sync": "node scripts/sync-version.js",
54
55
  "version:check": "node scripts/check-version-sync.js",
55
56
  "scripts:check": "node --check bin/native.js && node --check scripts/copy-native.js && node --check scripts/copy-framework.js && node --check scripts/sync-version.js && node --check scripts/check-version-sync.js && node --check scripts/check-framework-sync.js && node --check scripts/check-runtime-types.js && node scripts/copy-framework.js && node scripts/check-framework-sync.js && node scripts/check-runtime-types.js",
@@ -12,13 +12,109 @@
12
12
  // stage_external_core.mjs) alike.
13
13
 
14
14
  export function asciiBytes(s: string): Uint8Array {
15
+ for (let i = 0; i < s.length; i++) {
16
+ if (s.charCodeAt(i) > 0x7f) {
17
+ throw new RangeError("asciiBytes accepts ASCII only; use utf8Bytes for Unicode text");
18
+ }
19
+ }
15
20
  const out = new Uint8Array(s.length);
16
21
  for (let i = 0; i < s.length; i++) out[i] = s.charCodeAt(i);
17
22
  return out;
18
23
  }
19
24
 
25
+ export function utf8Bytes(s: string): Uint8Array {
26
+ let byteLength = 0;
27
+ for (let i = 0; i < s.length; i++) {
28
+ const code = s.charCodeAt(i);
29
+ if (code <= 0x7f) {
30
+ byteLength += 1;
31
+ } else if (code <= 0x7ff) {
32
+ byteLength += 2;
33
+ } else if (code >= 0xd800 && code <= 0xdbff && i + 1 < s.length) {
34
+ const next = s.charCodeAt(i + 1);
35
+ if (next >= 0xdc00 && next <= 0xdfff) {
36
+ byteLength += 4;
37
+ i += 1;
38
+ } else {
39
+ byteLength += 3;
40
+ }
41
+ } else {
42
+ byteLength += 3;
43
+ }
44
+ }
45
+
46
+ const out = new Uint8Array(byteLength);
47
+ let at = 0;
48
+ for (let i = 0; i < s.length; i++) {
49
+ let code = s.charCodeAt(i);
50
+ if (code >= 0xd800 && code <= 0xdbff && i + 1 < s.length) {
51
+ const next = s.charCodeAt(i + 1);
52
+ if (next >= 0xdc00 && next <= 0xdfff) {
53
+ code = 0x10000 + ((code - 0xd800) << 10) + (next - 0xdc00);
54
+ i += 1;
55
+ } else {
56
+ code = 0xfffd;
57
+ }
58
+ } else if (code >= 0xd800 && code <= 0xdfff) {
59
+ code = 0xfffd;
60
+ }
61
+
62
+ if (code <= 0x7f) {
63
+ out[at] = code;
64
+ at += 1;
65
+ } else if (code <= 0x7ff) {
66
+ out[at] = 0xc0 | (code >> 6);
67
+ out[at + 1] = 0x80 | (code & 0x3f);
68
+ at += 2;
69
+ } else if (code <= 0xffff) {
70
+ out[at] = 0xe0 | (code >> 12);
71
+ out[at + 1] = 0x80 | ((code >> 6) & 0x3f);
72
+ out[at + 2] = 0x80 | (code & 0x3f);
73
+ at += 3;
74
+ } else {
75
+ out[at] = 0xf0 | (code >> 18);
76
+ out[at + 1] = 0x80 | ((code >> 12) & 0x3f);
77
+ out[at + 2] = 0x80 | ((code >> 6) & 0x3f);
78
+ out[at + 3] = 0x80 | (code & 0x3f);
79
+ at += 4;
80
+ }
81
+ }
82
+ return out;
83
+ }
84
+
20
85
  export type Msgish = { readonly kind: string };
21
86
 
87
+ import { type WindowDescriptor, type WindowDescriptorSpec } from "./events.ts";
88
+
89
+ export function windowDescriptor(spec: WindowDescriptorSpec): WindowDescriptor {
90
+ return {
91
+ label: spec.label,
92
+ canvasLabel: spec.canvasLabel,
93
+ title: spec.title ?? new Uint8Array(0),
94
+ width: spec.width ?? 480,
95
+ height: spec.height ?? 360,
96
+ x: spec.x ?? null,
97
+ y: spec.y ?? null,
98
+ resizable: spec.resizable ?? true,
99
+ minWidth: spec.minWidth ?? 0,
100
+ minHeight: spec.minHeight ?? 0,
101
+ titlebar: spec.titlebar ?? "standard",
102
+ transparent: spec.transparent ?? false,
103
+ alwaysOnTop: spec.alwaysOnTop ?? false,
104
+ clickThrough: spec.clickThrough ?? false,
105
+ activateOnShow: spec.activateOnShow ?? true,
106
+ allowsFullscreen: spec.allowsFullscreen ?? true,
107
+ closePolicy: spec.closePolicy ?? "quit",
108
+ onCloseCommand: spec.onCloseCommand ?? new Uint8Array(0),
109
+ };
110
+ }
111
+
112
+ /** Cooperative cancellation capability supplied by generated service hosts. */
113
+ export interface ServiceCancellation {
114
+ readonly cancelled: () => boolean;
115
+ readonly throwIfCancelled: () => void;
116
+ }
117
+
22
118
  export interface EnvMsg<M extends Msgish> {
23
119
  readonly env: string;
24
120
  readonly msg: M["kind"];
@@ -55,12 +151,71 @@ export interface RequestRoute<M extends Msgish> {
55
151
  readonly err: M["kind"];
56
152
  }
57
153
 
154
+ export interface ServiceRoute<M extends Msgish, P> {
155
+ readonly key?: string;
156
+ readonly ok: M["kind"];
157
+ readonly err: M["kind"];
158
+ }
159
+
160
+ export interface ServiceStreamRoute<M extends Msgish, P> extends ServiceRoute<M, P> {
161
+ readonly channelKey: number;
162
+ readonly event: M["kind"];
163
+ }
164
+
58
165
  export interface WriteRoute<M extends Msgish> {
59
166
  readonly key?: string;
60
167
  readonly ok: M["kind"];
61
168
  readonly err: M["kind"];
62
169
  }
63
170
 
171
+ export interface FileReadStreamRoute<M extends Msgish> {
172
+ readonly key?: string;
173
+ readonly chunk: M["kind"];
174
+ readonly done: M["kind"];
175
+ readonly err: M["kind"];
176
+ }
177
+
178
+ export interface FileStatArm { readonly exists: boolean; readonly size: number; readonly mtimeMs: number; }
179
+ export interface FileStatRoute<M extends Msgish> { readonly key?: string; readonly ok: M["kind"]; readonly err: M["kind"]; }
180
+
181
+ export interface StoreScanOptions {
182
+ readonly limit?: number;
183
+ readonly after?: string | Uint8Array;
184
+ }
185
+
186
+ export interface DbText {
187
+ readonly __dbText: true;
188
+ readonly bytes: ReadonlyArray<number>;
189
+ }
190
+
191
+ export function dbText(bytes: Uint8Array): DbText {
192
+ const out: number[] = [];
193
+ for (let i = 0; i < bytes.length; i++) out.push(bytes[i]!);
194
+ return { __dbText: true, bytes: out };
195
+ }
196
+
197
+ export type DbValue = null | number | string | Uint8Array | boolean | DbText;
198
+ export type DbStatement = readonly [sql: string, params: ReadonlyArray<DbValue>];
199
+
200
+ export interface DbRowsRoute<M extends Msgish> {
201
+ readonly key?: string;
202
+ readonly page: M["kind"];
203
+ readonly done: M["kind"];
204
+ readonly err: M["kind"];
205
+ }
206
+
207
+ export interface TypedRowsRoute<Row, M extends Msgish> extends DbRowsRoute<M> {
208
+ readonly __row?: Row;
209
+ }
210
+
211
+ export interface TypedDbStatement {
212
+ readonly sql: string;
213
+ readonly params: ReadonlyArray<DbValue>;
214
+ readonly __typedDbStatement: true;
215
+ }
216
+
217
+ // @native-sqlite-generated-types
218
+
64
219
  export interface FetchRoute<M extends Msgish> {
65
220
  readonly key?: string;
66
221
  readonly ok: M["kind"];
@@ -182,11 +337,16 @@ export interface FetchStreamSpec extends FetchSpec {
182
337
  }
183
338
 
184
339
  export interface NotificationSpec {
340
+ readonly id?: Uint8Array;
185
341
  readonly title: Uint8Array;
186
342
  readonly subtitle?: Uint8Array;
187
343
  readonly body?: Uint8Array;
344
+ readonly actionLabel?: Uint8Array;
345
+ readonly actionCommand?: Uint8Array;
188
346
  }
189
347
 
348
+ export type LocalTimeStyle = "date" | "time" | "datetime";
349
+
190
350
  /// The inert command data — the reference module's Cmd<M> union with
191
351
  /// the type parameter erased (M constrains only the factories' arm-name
192
352
  /// checking, never the data).
@@ -202,6 +362,19 @@ export type CmdData =
202
362
  readonly key: string;
203
363
  readonly okKind: string;
204
364
  readonly errKind: string;
365
+ readonly typedService: boolean;
366
+ readonly payload: Uint8Array;
367
+ }
368
+ | {
369
+ readonly op: "service_stream_request";
370
+ readonly name: string;
371
+ readonly key: string;
372
+ readonly okKind: string;
373
+ readonly errKind: string;
374
+ readonly typedService: true;
375
+ readonly channelKey: number;
376
+ readonly eventKind: string;
377
+ readonly maxPending: number;
205
378
  readonly payload: Uint8Array;
206
379
  }
207
380
  | { readonly op: "cancel"; readonly key: string }
@@ -220,6 +393,60 @@ export type CmdData =
220
393
  readonly path: Uint8Array;
221
394
  readonly bytes: Uint8Array;
222
395
  }
396
+ | { readonly op: "append_file"; readonly key: string; readonly okKind: string; readonly errKind: string; readonly path: Uint8Array; readonly bytes: Uint8Array }
397
+ | { readonly op: "stat_file"; readonly key: string; readonly okKind: string; readonly errKind: string; readonly path: Uint8Array }
398
+ | { readonly op: "delete_file"; readonly key: string; readonly okKind: string; readonly errKind: string; readonly path: Uint8Array }
399
+ | { readonly op: "read_file_stream"; readonly key: string; readonly chunkKind: string; readonly doneKind: string; readonly errKind: string; readonly path: Uint8Array }
400
+ | { readonly op: "write_file_stream"; readonly key: string; readonly okKind: string; readonly errKind: string; readonly path: Uint8Array }
401
+ | { readonly op: "write_file_chunk"; readonly key: string; readonly okKind: string; readonly errKind: string; readonly bytes: Uint8Array }
402
+ | { readonly op: "write_file_close"; readonly key: string; readonly okKind: string; readonly errKind: string }
403
+ | {
404
+ readonly op: "store_set";
405
+ readonly key: string;
406
+ readonly okKind: string;
407
+ readonly errKind: string;
408
+ readonly storeKey: string;
409
+ readonly bytes: Uint8Array;
410
+ }
411
+ | {
412
+ readonly op: "store_get" | "store_delete";
413
+ readonly key: string;
414
+ readonly okKind: string;
415
+ readonly errKind: string;
416
+ readonly storeKey: string;
417
+ }
418
+ | {
419
+ readonly op: "store_scan";
420
+ readonly key: string;
421
+ readonly okKind: string;
422
+ readonly errKind: string;
423
+ readonly prefix: string;
424
+ readonly limit: number;
425
+ readonly after: string | Uint8Array;
426
+ }
427
+ | {
428
+ readonly op: "store_set_many";
429
+ readonly key: string;
430
+ readonly okKind: string;
431
+ readonly errKind: string;
432
+ readonly entries: ReadonlyArray<readonly [string, Uint8Array]>;
433
+ }
434
+ | {
435
+ readonly op: "db_query";
436
+ readonly key: string;
437
+ readonly pageKind: string;
438
+ readonly doneKind: string;
439
+ readonly errKind: string;
440
+ readonly sql: string;
441
+ readonly params: ReadonlyArray<DbValue>;
442
+ }
443
+ | {
444
+ readonly op: "db_exec";
445
+ readonly key: string;
446
+ readonly okKind: string;
447
+ readonly errKind: string;
448
+ readonly statements: ReadonlyArray<DbStatement>;
449
+ }
223
450
  | {
224
451
  readonly op: "fetch";
225
452
  readonly key: string;
@@ -246,7 +473,7 @@ export type CmdData =
246
473
  }
247
474
  | { readonly op: "clip_write"; readonly bytes: Uint8Array }
248
475
  | { readonly op: "clip_read"; readonly key: string; readonly okKind: string; readonly errKind: string }
249
- | { readonly op: "show_notification"; readonly title: Uint8Array; readonly subtitle: Uint8Array; readonly body: Uint8Array }
476
+ | { readonly op: "show_notification"; readonly id: Uint8Array; readonly title: Uint8Array; readonly subtitle: Uint8Array; readonly body: Uint8Array; readonly actionLabel: Uint8Array; readonly actionCommand: Uint8Array }
250
477
  | { readonly op: "delay"; readonly key: string; readonly afterMs: number; readonly msgKind: string }
251
478
  | {
252
479
  readonly op: "spawn";
@@ -291,6 +518,8 @@ export type CmdData =
291
518
  readonly value: number;
292
519
  }
293
520
  | { readonly op: "window_show"; readonly label: string }
521
+ | { readonly op: "window_hide"; readonly label: string }
522
+ | { readonly op: "dock_presence"; readonly visible: boolean }
294
523
  | { readonly op: "quit_app" }
295
524
  | {
296
525
  readonly op: "image_load";
@@ -303,7 +532,7 @@ export type CmdData =
303
532
  }
304
533
  | { readonly op: "image_cancel"; readonly id: number }
305
534
  | { readonly op: "image_unregister"; readonly id: number }
306
- | { readonly op: "channel_open"; readonly key: number; readonly eventKind: string }
535
+ | { readonly op: "channel_open"; readonly key: number; readonly eventKind: string; readonly maxPending: number }
307
536
  | { readonly op: "channel_close"; readonly key: number }
308
537
  | { readonly op: "audio_capture_start"; readonly key: number; readonly source: "microphone" | "system"; readonly sampleRate: number; readonly channels: number; readonly eventKind: string }
309
538
  | { readonly op: "audio_capture_stop"; readonly key: number }
@@ -361,6 +590,68 @@ export function hostRecordBytes(payload: HostRecord): Uint8Array {
361
590
  return out;
362
591
  }
363
592
 
593
+ function serviceU32(value: number): Uint8Array {
594
+ const out = new Uint8Array(4);
595
+ out[0] = value % 256;
596
+ out[1] = Math.floor(value / 256) % 256;
597
+ out[2] = Math.floor(value / 65536) % 256;
598
+ out[3] = Math.floor(value / 16777216) % 256;
599
+ return out;
600
+ }
601
+
602
+ export function serviceConcat(parts: readonly Uint8Array[]): Uint8Array {
603
+ let length = 0;
604
+ for (const part of parts) length += part.length;
605
+ const out = new Uint8Array(length);
606
+ let at = 0;
607
+ for (const part of parts) {
608
+ for (let i = 0; i < part.length; i++) out[at + i] = part[i]!;
609
+ at += part.length;
610
+ }
611
+ return out;
612
+ }
613
+
614
+ export function serviceBoolBytes(value: boolean): Uint8Array {
615
+ return new Uint8Array([value ? 1 : 0]);
616
+ }
617
+
618
+ export function serviceF64Bytes(value: number): Uint8Array {
619
+ const out = new Uint8Array(8);
620
+ const buf = Buffer.alloc(8);
621
+ buf.writeDoubleLE(Number.isNaN(value) ? Number.NaN : value, 0);
622
+ for (let i = 0; i < 8; i++) out[i] = buf[i]!;
623
+ return out;
624
+ }
625
+
626
+ export function serviceI64Bytes(value: number): Uint8Array {
627
+ const base = 4294967296;
628
+ let low = value % base;
629
+ if (low < 0) low += base;
630
+ let high = Math.floor(value / base);
631
+ if (high < 0) high += base;
632
+ return serviceConcat([serviceU32(low), serviceU32(high)]);
633
+ }
634
+
635
+ export function serviceBytes(value: Uint8Array): Uint8Array {
636
+ return serviceConcat([serviceU32(value.length), value]);
637
+ }
638
+
639
+ export function serviceEnumBytes(index: number): Uint8Array {
640
+ return serviceU32(index);
641
+ }
642
+
643
+ export function serviceUnionBytes(index: number): Uint8Array {
644
+ return new Uint8Array([index]);
645
+ }
646
+
647
+ export function serviceOptionalBytes(value: Uint8Array | null): Uint8Array {
648
+ return value === null ? new Uint8Array([0]) : serviceConcat([new Uint8Array([1]), value]);
649
+ }
650
+
651
+ export function serviceSliceBytes(values: readonly Uint8Array[]): Uint8Array {
652
+ return serviceConcat([serviceU32(values.length), ...values]);
653
+ }
654
+
364
655
  /// A host command by name — the reference module's overloaded `host`
365
656
  /// restated as the raw-bytes form (the whole corpus's usage; overloads,
366
657
  /// rest-args, and the `Uint8Array | HostRecord` runtime discrimination
@@ -382,6 +673,8 @@ export function hostArgs(name: string, args: readonly number[]): CmdData {
382
673
  export const Cmd = {
383
674
  none: { op: "none" } as CmdData,
384
675
 
676
+ /// Snapshot the just-committed Model through the capability-gated,
677
+ /// engine-owned persistence store. Wire output remains the reserved 0x01.
385
678
  persist(): CmdData {
386
679
  return { op: "persist" };
387
680
  },
@@ -399,10 +692,48 @@ export const Cmd = {
399
692
  key: route.key ?? "",
400
693
  okKind: route.ok,
401
694
  errKind: route.err,
695
+ typedService: false,
402
696
  payload: payload,
403
697
  };
404
698
  },
405
699
 
700
+ serviceRequest(
701
+ name: string,
702
+ payload: Uint8Array,
703
+ route: { readonly key?: string; readonly ok: string; readonly err: string },
704
+ ): CmdData {
705
+ return {
706
+ op: "request",
707
+ name,
708
+ key: route.key ?? "",
709
+ okKind: route.ok,
710
+ errKind: route.err,
711
+ typedService: true,
712
+ payload,
713
+ };
714
+ },
715
+
716
+ serviceStreamRequest(
717
+ name: string,
718
+ channelKey: number,
719
+ payload: Uint8Array,
720
+ route: { readonly key?: string; readonly ok: string; readonly err: string; readonly event: string },
721
+ maxPending: number,
722
+ ): CmdData {
723
+ return {
724
+ op: "service_stream_request",
725
+ name,
726
+ key: route.key ?? "",
727
+ okKind: route.ok,
728
+ errKind: route.err,
729
+ typedService: true,
730
+ channelKey,
731
+ eventKind: route.event,
732
+ maxPending,
733
+ payload: serviceConcat([serviceF64Bytes(channelKey), payload]),
734
+ };
735
+ },
736
+
406
737
  cancel(key: string): CmdData {
407
738
  return { op: "cancel", key };
408
739
  },
@@ -414,6 +745,68 @@ export const Cmd = {
414
745
  writeFile(path: Uint8Array, bytes: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
415
746
  return { op: "write_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path, bytes };
416
747
  },
748
+ appendFile(path: Uint8Array, bytes: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
749
+ return { op: "append_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path, bytes };
750
+ },
751
+ statFile(path: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
752
+ return { op: "stat_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path };
753
+ },
754
+ deleteFile(path: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
755
+ return { op: "delete_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path };
756
+ },
757
+ readFileStream(path: Uint8Array, route: { readonly key?: string; readonly chunk: string; readonly done: string; readonly err: string }): CmdData {
758
+ return { op: "read_file_stream", key: route.key ?? "", chunkKind: route.chunk, doneKind: route.done, errKind: route.err, path };
759
+ },
760
+ writeFileStream(key: string, path: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
761
+ return { op: "write_file_stream", key, okKind: route.ok, errKind: route.err, path };
762
+ },
763
+ writeFileChunk(key: string, bytes: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
764
+ return { op: "write_file_chunk", key, okKind: route.ok, errKind: route.err, bytes };
765
+ },
766
+ writeFileClose(key: string, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
767
+ return { op: "write_file_close", key, okKind: route.ok, errKind: route.err };
768
+ },
769
+
770
+ store: {
771
+ set(storeKey: string, bytes: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
772
+ return { op: "store_set", key: route.key ?? "", okKind: route.ok, errKind: route.err, storeKey, bytes };
773
+ },
774
+ get(storeKey: string, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
775
+ return { op: "store_get", key: route.key ?? "", okKind: route.ok, errKind: route.err, storeKey };
776
+ },
777
+ delete(storeKey: string, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
778
+ return { op: "store_delete", key: route.key ?? "", okKind: route.ok, errKind: route.err, storeKey };
779
+ },
780
+ scan(prefix: string, options: StoreScanOptions, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
781
+ return { op: "store_scan", key: route.key ?? "", okKind: route.ok, errKind: route.err, prefix, limit: options.limit ?? 0, after: options.after ?? "" };
782
+ },
783
+ setMany(entries: ReadonlyArray<readonly [string, Uint8Array]>, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
784
+ return { op: "store_set_many", key: route.key ?? "", okKind: route.ok, errKind: route.err, entries };
785
+ },
786
+ },
787
+
788
+ credentials: {
789
+ set(credentialKey: string, secret: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
790
+ return { op: "request", name: "core.credentials.set", key: route.key ?? "", okKind: route.ok, errKind: route.err, typedService: false, payload: hostRecordBytes({ key: utf8Bytes(credentialKey), secret }) };
791
+ },
792
+ get(credentialKey: string, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
793
+ return Cmd.request("core.credentials.get", hostRecordBytes({ key: utf8Bytes(credentialKey) }), route);
794
+ },
795
+ delete(credentialKey: string, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
796
+ return { op: "request", name: "core.credentials.delete", key: route.key ?? "", okKind: route.ok, errKind: route.err, typedService: false, payload: hostRecordBytes({ key: utf8Bytes(credentialKey) }) };
797
+ },
798
+ },
799
+
800
+ db: {
801
+ query(sql: string, params: ReadonlyArray<DbValue>, route: { readonly key?: string; readonly page: string; readonly done: string; readonly err: string }): CmdData {
802
+ return { op: "db_query", key: route.key ?? "", pageKind: route.page, doneKind: route.done, errKind: route.err, sql, params };
803
+ },
804
+ exec(statements: ReadonlyArray<DbStatement>, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
805
+ return { op: "db_exec", key: route.key ?? "", okKind: route.ok, errKind: route.err, statements };
806
+ },
807
+ },
808
+
809
+ // @native-sqlite-generated-cmds
417
810
 
418
811
  fetch(
419
812
  spec: FetchStreamSpec,
@@ -463,12 +856,32 @@ export const Cmd = {
463
856
  showNotification(spec: NotificationSpec): CmdData {
464
857
  return {
465
858
  op: "show_notification",
859
+ id: spec.id ?? new Uint8Array(0),
466
860
  title: spec.title,
467
861
  subtitle: spec.subtitle ?? new Uint8Array(0),
468
862
  body: spec.body ?? new Uint8Array(0),
863
+ actionLabel: spec.actionLabel ?? new Uint8Array(0),
864
+ actionCommand: spec.actionCommand ?? new Uint8Array(0),
469
865
  };
470
866
  },
471
867
 
868
+ openExternalUrl(url: Uint8Array): CmdData {
869
+ return { op: "host_bytes", name: "native-sdk.os.openUrl", payload: url };
870
+ },
871
+
872
+ revealPath(path: Uint8Array): CmdData {
873
+ return { op: "host_bytes", name: "native-sdk.os.revealPath", payload: path };
874
+ },
875
+
876
+ formatLocalTime(
877
+ timestampMs: number,
878
+ style: LocalTimeStyle,
879
+ route: { readonly key?: string; readonly ok: string; readonly err: string },
880
+ ): CmdData {
881
+ const styleCode = style === "date" ? 0 : style === "time" ? 1 : 2;
882
+ return Cmd.request("native-sdk.time.formatLocal", hostRecordBytes({ style: styleCode, timestampMs }), route);
883
+ },
884
+
472
885
  delay(key: string, ms: number, msgKind: string): CmdData {
473
886
  return { op: "delay", key, afterMs: ms, msgKind };
474
887
  },
@@ -568,6 +981,22 @@ export const Cmd = {
568
981
  return { op: "window_show", label };
569
982
  },
570
983
 
984
+ hideWindow(label: string): CmdData {
985
+ return { op: "window_hide", label };
986
+ },
987
+
988
+ setDockPresence(visible: boolean): CmdData {
989
+ return { op: "dock_presence", visible };
990
+ },
991
+
992
+ launchAtLoginStatus(route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
993
+ return Cmd.request("native-sdk.launch-at-login.status", new Uint8Array(0), route);
994
+ },
995
+
996
+ setLaunchAtLogin(enabled: boolean, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
997
+ return Cmd.request("native-sdk.launch-at-login.set", new Uint8Array([enabled ? 1 : 0]), route);
998
+ },
999
+
571
1000
  quitApp(): CmdData {
572
1001
  return { op: "quit_app" };
573
1002
  },
@@ -593,7 +1022,7 @@ export const Cmd = {
593
1022
  },
594
1023
 
595
1024
  channelOpen(key: number, route: { readonly event: string }): CmdData {
596
- return { op: "channel_open", key, eventKind: route.event };
1025
+ return { op: "channel_open", key, eventKind: route.event, maxPending: 64 };
597
1026
  },
598
1027
 
599
1028
  channelClose(key: number): CmdData {
@@ -647,6 +1076,7 @@ export const Cmd = {
647
1076
  export type SubData =
648
1077
  | { readonly op: "none" }
649
1078
  | { readonly op: "timer"; readonly key: string; readonly everyMs: number; readonly msgKind: string }
1079
+ | { readonly op: "db_live"; readonly key: string; readonly pageKind: string; readonly doneKind: string; readonly errKind: string; readonly sql: string; readonly params: ReadonlyArray<DbValue>; readonly tables: readonly string[] }
650
1080
  | { readonly op: "batch"; readonly subs: readonly SubData[] };
651
1081
 
652
1082
  export type Sub<M extends Msgish> = SubData;
@@ -658,6 +1088,8 @@ export const Sub = {
658
1088
  return { op: "timer", key, everyMs, msgKind };
659
1089
  },
660
1090
 
1091
+ // @native-sqlite-generated-subs
1092
+
661
1093
  batch(subs: readonly SubData[]): SubData {
662
1094
  return { op: "batch", subs };
663
1095
  },