@native-sdk/cli 0.8.3 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/build/app.zig +905 -61
  2. package/build.zig +674 -373
  3. package/build.zig.zon +1 -0
  4. package/native-sdk.d.ts +6 -0
  5. package/package.json +12 -11
  6. package/packages/core/compile-surface/core.ts +455 -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/npm_static_spike.mjs +64 -0
  12. package/packages/core/scripts/run_external_core_compiler.mjs +77 -6
  13. package/packages/core/scripts/run_external_service_compiler.mjs +240 -0
  14. package/packages/core/scripts/stage_external_core.mjs +9 -1
  15. package/packages/core/scripts/stage_external_services.mjs +172 -0
  16. package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
  17. package/packages/core/scripts/vendor_service_packages.mjs +189 -0
  18. package/packages/core/sdk/core.d.ts +214 -2
  19. package/packages/core/sdk/core.ts +715 -42
  20. package/packages/core/sdk/events.d.ts +50 -0
  21. package/packages/core/sdk/events.ts +75 -0
  22. package/packages/core/src/checker.ts +528 -15
  23. package/packages/core/src/cli.ts +143 -3
  24. package/packages/core/src/contract.ts +26 -5
  25. package/packages/core/src/devhost.ts +1849 -18
  26. package/packages/core/src/devhost_journal.mjs +181 -0
  27. package/packages/core/src/devhost_resolver.mjs +17 -1
  28. package/packages/core/src/devhost_service_worker.mjs +90 -0
  29. package/packages/core/src/diagnostics.ts +84 -18
  30. package/packages/core/src/frontend.ts +204 -34
  31. package/packages/core/src/modules.ts +129 -80
  32. package/packages/core/src/service_contract.ts +597 -0
  33. package/packages/core/src/sqlite_cli.ts +93 -0
  34. package/packages/core/src/sqlite_codegen.ts +806 -0
  35. package/packages/core/src/sqlite_runtime_policy.ts +364 -0
  36. package/packages/core/src/typed_ast.ts +36 -8
  37. package/skill-data/core/SKILL.md +4 -2
  38. package/skill-data/core/references/project-anatomy.md +3 -2
  39. package/skill-data/core/references/web-engines-packaging-debugging.md +3 -1
  40. package/skill-data/native-ui/SKILL.md +55 -8
  41. package/skill-data/ts-core/SKILL.md +92 -40
  42. package/skill-data/ts-services/SKILL.md +126 -0
  43. package/skill-data/ts-services/references/service-surface.md +603 -0
  44. package/skill-data/zig/SKILL.md +1 -1
  45. package/skills/native-sdk/SKILL.md +1 -1
  46. package/src/app_runner/no_migrations.zig +3 -0
  47. package/src/app_runner/no_services.zig +20 -0
  48. package/src/app_runner/root.zig +104 -4
  49. package/src/app_runner/ts_core_main.zig +268 -4
  50. package/src/automation/snapshot.zig +23 -5
  51. package/src/embed/app_exports.zig +11 -1
  52. package/src/embed/c_api.zig +48 -2
  53. package/src/embed/conversions.zig +4 -5
  54. package/src/embed/host.zig +115 -1
  55. package/src/embed/root.zig +7 -0
  56. package/src/embed/tests.zig +213 -0
  57. package/src/embed/types.zig +51 -0
  58. package/src/embed/ui_host.zig +121 -5
  59. package/src/platform/android/NativeSdkActivity.java +131 -0
  60. package/src/platform/android/android_host.c +182 -1
  61. package/src/platform/android/native_sdk_app.h +17 -0
  62. package/src/platform/ios/native_sdk_app.h +17 -0
  63. package/src/platform/ios/uikit_host.m +115 -0
  64. package/src/platform/linux/cef_host.cpp +1 -1
  65. package/src/platform/linux/gtk_host.c +89 -17
  66. package/src/platform/linux/gtk_host.h +3 -0
  67. package/src/platform/linux/root.zig +41 -18
  68. package/src/platform/macos/appkit_host.h +26 -3
  69. package/src/platform/macos/appkit_host.m +1051 -129
  70. package/src/platform/macos/capture_info_plist.c +25 -0
  71. package/src/platform/macos/cef_host.mm +270 -36
  72. package/src/platform/macos/root.zig +312 -34
  73. package/src/platform/null_platform.zig +281 -19
  74. package/src/platform/null_platform_tests.zig +74 -0
  75. package/src/platform/root.zig +16 -0
  76. package/src/platform/types.zig +279 -15
  77. package/src/platform/windows/root.zig +243 -21
  78. package/src/platform/windows/webview2_host.cpp +464 -46
  79. package/src/primitives/app_manifest/comptime_scene.zig +2 -0
  80. package/src/primitives/app_manifest/root.zig +4 -0
  81. package/src/primitives/app_manifest/tests.zig +3 -0
  82. package/src/primitives/app_manifest/types.zig +34 -0
  83. package/src/primitives/app_manifest/validation.zig +19 -1
  84. package/src/primitives/canvas/code_tests.zig +9 -9
  85. package/src/primitives/canvas/events.zig +12 -11
  86. package/src/primitives/canvas/frame.zig +44 -9
  87. package/src/primitives/canvas/icons/mic.svg +1 -0
  88. package/src/primitives/canvas/icons.zig +2 -0
  89. package/src/primitives/canvas/root.zig +8 -0
  90. package/src/primitives/canvas/text_span_tests.zig +39 -0
  91. package/src/primitives/canvas/ui.zig +23 -4
  92. package/src/primitives/canvas/ui_markup.zig +15 -0
  93. package/src/primitives/canvas/ui_markup_compiled.zig +9 -0
  94. package/src/primitives/canvas/ui_markup_compiled_tests.zig +1 -1
  95. package/src/primitives/canvas/ui_markup_tests.zig +5 -0
  96. package/src/primitives/canvas/ui_markup_view.zig +9 -0
  97. package/src/primitives/canvas/ui_markup_view_tests.zig +9 -6
  98. package/src/primitives/canvas/ui_schema.zig +19 -10
  99. package/src/primitives/canvas/ui_schema_tests.zig +5 -3
  100. package/src/primitives/canvas/ui_tests.zig +18 -4
  101. package/src/primitives/canvas/widget_invalidation.zig +9 -2
  102. package/src/primitives/canvas/widget_render.zig +296 -114
  103. package/src/primitives/canvas/widget_runtime_tests.zig +133 -0
  104. package/src/primitives/canvas/widget_text_input.zig +10 -10
  105. package/src/primitives/canvas/widget_tree.zig +1 -1
  106. package/src/primitives/canvas/widgets.zig +29 -5
  107. package/src/root.zig +56 -0
  108. package/src/runtime/api.zig +11 -0
  109. package/src/runtime/automation_snapshot.zig +4 -0
  110. package/src/runtime/automation_widget_dispatch.zig +1 -0
  111. package/src/runtime/bridge_payload.zig +2 -0
  112. package/src/runtime/bridge_permission_tests.zig +23 -2
  113. package/src/runtime/bridge_responses.zig +3 -1
  114. package/src/runtime/canvas_frame.zig +31 -13
  115. package/src/runtime/canvas_frame_animation_tests.zig +4 -0
  116. package/src/runtime/canvas_frame_invalidation_tests.zig +35 -10
  117. package/src/runtime/canvas_widget_anchored_tests.zig +83 -0
  118. package/src/runtime/canvas_widget_events.zig +69 -24
  119. package/src/runtime/canvas_widget_runtime.zig +101 -6
  120. package/src/runtime/canvas_widget_scroll_driver_tests.zig +47 -4
  121. package/src/runtime/canvas_widget_scroll_drivers.zig +3 -3
  122. package/src/runtime/canvas_widget_semantics_tests.zig +2 -0
  123. package/src/runtime/canvas_widget_split_tree_tests.zig +228 -0
  124. package/src/runtime/canvas_widget_state.zig +6 -1
  125. package/src/runtime/canvas_widget_text_tests.zig +112 -3
  126. package/src/runtime/clock.zig +13 -1
  127. package/src/runtime/core.zig +133 -1
  128. package/src/runtime/credentials_store.zig +115 -0
  129. package/src/runtime/effects.zig +2568 -75
  130. package/src/runtime/effects_audio_capture_tests.zig +251 -0
  131. package/src/runtime/effects_credentials_tests.zig +332 -0
  132. package/src/runtime/effects_host_tests.zig +208 -1
  133. package/src/runtime/effects_relational_tests.zig +314 -0
  134. package/src/runtime/effects_store_tests.zig +211 -0
  135. package/src/runtime/flow.zig +14 -1
  136. package/src/runtime/gpu_surface_events.zig +6 -1
  137. package/src/runtime/native_command_event_tests.zig +42 -0
  138. package/src/runtime/persist_store.zig +666 -0
  139. package/src/runtime/record_store.zig +788 -0
  140. package/src/runtime/relational_store.zig +854 -0
  141. package/src/runtime/root.zig +52 -0
  142. package/src/runtime/runtime_event_tests.zig +70 -0
  143. package/src/runtime/service_host.zig +711 -0
  144. package/src/runtime/service_pool.zig +1314 -0
  145. package/src/runtime/session_blobs.zig +1 -1
  146. package/src/runtime/session_journal.zig +102 -0
  147. package/src/runtime/session_record.zig +177 -0
  148. package/src/runtime/session_replay.zig +109 -4
  149. package/src/runtime/shell_layout.zig +1 -0
  150. package/src/runtime/shell_layout_tests.zig +120 -0
  151. package/src/runtime/sqlite_engine.zig +474 -0
  152. package/src/runtime/state.zig +6 -0
  153. package/src/runtime/system_services.zig +49 -10
  154. package/src/runtime/tests.zig +5 -0
  155. package/src/runtime/ts_core_host.zig +1189 -118
  156. package/src/runtime/ts_core_host_tests.zig +638 -11
  157. package/src/runtime/ts_ui_app.zig +537 -1
  158. package/src/runtime/ui_app.zig +160 -19
  159. package/src/runtime/ui_app_tests.zig +203 -5
  160. package/src/runtime/validation.zig +22 -0
  161. package/src/runtime/view.zig +11 -0
  162. package/src/runtime/view_widget_scroll.zig +56 -5
  163. package/src/runtime/view_widget_text.zig +24 -5
  164. package/src/runtime/view_widget_tree.zig +1 -1
  165. package/src/runtime/window_storage.zig +1 -0
  166. package/src/runtime/window_view_runtime.zig +2 -3
  167. package/src/runtime/window_views.zig +19 -0
  168. package/src/tooling/android.zig +21 -16
  169. package/src/tooling/db.zig +160 -0
  170. package/src/tooling/ios.zig +7 -1
  171. package/src/tooling/manifest.zig +1248 -2
  172. package/src/tooling/package.zig +953 -6
  173. package/src/tooling/raw_manifest.zig +65 -0
  174. package/src/tooling/root.zig +1 -0
  175. package/src/tooling/templates.zig +216 -4
  176. package/src/tooling/ts_core.zig +283 -17
  177. package/src/tooling/verbs.zig +7 -0
  178. package/third_party/sqlite/README.md +13 -0
  179. package/third_party/sqlite/sqlite3.c +269649 -0
  180. package/third_party/sqlite/sqlite3.h +14349 -0
  181. package/tools/corewire/core_abi.zig +14 -2
  182. package/tools/corewire/emit.zig +98 -29
  183. package/tools/corewire/emit_facade.zig +414 -23
  184. package/tools/corewire/emit_profile.zig +6 -2
  185. package/tools/corewire/emit_service.zig +924 -0
  186. package/tools/corewire/main.zig +122 -0
  187. package/tools/corewire/service_contract.zig +250 -0
  188. package/tools/corewire/sidecar.zig +26 -15
@@ -12,13 +12,84 @@
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
+ /** Cooperative cancellation capability supplied by generated service hosts. */
88
+ export interface ServiceCancellation {
89
+ readonly cancelled: () => boolean;
90
+ readonly throwIfCancelled: () => void;
91
+ }
92
+
22
93
  export interface EnvMsg<M extends Msgish> {
23
94
  readonly env: string;
24
95
  readonly msg: M["kind"];
@@ -55,18 +126,74 @@ export interface RequestRoute<M extends Msgish> {
55
126
  readonly err: M["kind"];
56
127
  }
57
128
 
129
+ export interface ServiceRoute<M extends Msgish, P> {
130
+ readonly key?: string;
131
+ readonly ok: M["kind"];
132
+ readonly err: M["kind"];
133
+ }
134
+
135
+ export interface ServiceStreamRoute<M extends Msgish, P> extends ServiceRoute<M, P> {
136
+ readonly channelKey: number;
137
+ readonly event: M["kind"];
138
+ }
139
+
58
140
  export interface WriteRoute<M extends Msgish> {
59
141
  readonly key?: string;
60
142
  readonly ok: M["kind"];
61
143
  readonly err: M["kind"];
62
144
  }
63
145
 
146
+ export interface StoreScanOptions {
147
+ readonly limit?: number;
148
+ readonly after?: string | Uint8Array;
149
+ }
150
+
151
+ export interface DbText {
152
+ readonly __dbText: true;
153
+ readonly bytes: ReadonlyArray<number>;
154
+ }
155
+
156
+ export function dbText(bytes: Uint8Array): DbText {
157
+ const out: number[] = [];
158
+ for (let i = 0; i < bytes.length; i++) out.push(bytes[i]!);
159
+ return { __dbText: true, bytes: out };
160
+ }
161
+
162
+ export type DbValue = null | number | string | Uint8Array | boolean | DbText;
163
+ export type DbStatement = readonly [sql: string, params: ReadonlyArray<DbValue>];
164
+
165
+ export interface DbRowsRoute<M extends Msgish> {
166
+ readonly key?: string;
167
+ readonly page: M["kind"];
168
+ readonly done: M["kind"];
169
+ readonly err: M["kind"];
170
+ }
171
+
172
+ export interface TypedRowsRoute<Row, M extends Msgish> extends DbRowsRoute<M> {
173
+ readonly __row?: Row;
174
+ }
175
+
176
+ export interface TypedDbStatement {
177
+ readonly sql: string;
178
+ readonly params: ReadonlyArray<DbValue>;
179
+ readonly __typedDbStatement: true;
180
+ }
181
+
182
+ // @native-sqlite-generated-types
183
+
64
184
  export interface FetchRoute<M extends Msgish> {
65
185
  readonly key?: string;
66
186
  readonly ok: M["kind"];
67
187
  readonly err: M["kind"];
68
188
  }
69
189
 
190
+ export interface FetchStreamRoute<M extends Msgish> {
191
+ readonly key?: string;
192
+ readonly line: M["kind"];
193
+ readonly ok: M["kind"];
194
+ readonly err: M["kind"];
195
+ }
196
+
70
197
  export interface SpawnRoute<M extends Msgish> {
71
198
  readonly key?: string;
72
199
  readonly stdin?: Uint8Array;
@@ -122,6 +249,36 @@ export interface ChannelRoute<M extends Msgish> {
122
249
  readonly event: M["kind"];
123
250
  }
124
251
 
252
+ export type AudioCaptureSource = "microphone" | "system";
253
+ export type AudioCaptureState = "started" | "data" | "failed" | "stopped" | "rejected";
254
+ export type AudioCaptureSampleRate = 16000 | 24000 | 48000;
255
+ export type AudioCaptureChannels = 1 | 2;
256
+
257
+ export interface AudioCaptureSpec {
258
+ // Inline the event-module alias here: the external-compile stager
259
+ // deliberately deduplicates aliases shared by core.ts and events.ts.
260
+ readonly source: "microphone" | "system";
261
+ readonly sampleRate?: AudioCaptureSampleRate;
262
+ readonly channels?: AudioCaptureChannels;
263
+ }
264
+
265
+ export type AudioCaptureEventArm = {
266
+ readonly key: number;
267
+ readonly state: "started" | "data" | "failed" | "stopped" | "rejected";
268
+ readonly source: "microphone" | "system";
269
+ readonly sampleRate: number;
270
+ readonly channels: number;
271
+ readonly timestampMs: number;
272
+ readonly frames: number;
273
+ readonly pcm: Uint8Array;
274
+ readonly droppedPending: number;
275
+ readonly droppedTotal: number;
276
+ };
277
+
278
+ export interface AudioCaptureRoute<M extends Msgish> {
279
+ readonly event: M["kind"];
280
+ }
281
+
125
282
  export interface PtyRoute<M extends Msgish> {
126
283
  readonly key?: string;
127
284
  readonly cols?: number;
@@ -140,12 +297,18 @@ export interface FetchSpec {
140
297
  readonly timeoutMs?: number;
141
298
  }
142
299
 
300
+ export interface FetchStreamSpec extends FetchSpec {
301
+ readonly maxLineBytes?: number;
302
+ }
303
+
143
304
  export interface NotificationSpec {
144
305
  readonly title: Uint8Array;
145
306
  readonly subtitle?: Uint8Array;
146
307
  readonly body?: Uint8Array;
147
308
  }
148
309
 
310
+ export type LocalTimeStyle = "date" | "time" | "datetime";
311
+
149
312
  /// The inert command data — the reference module's Cmd<M> union with
150
313
  /// the type parameter erased (M constrains only the factories' arm-name
151
314
  /// checking, never the data).
@@ -161,6 +324,19 @@ export type CmdData =
161
324
  readonly key: string;
162
325
  readonly okKind: string;
163
326
  readonly errKind: string;
327
+ readonly typedService: boolean;
328
+ readonly payload: Uint8Array;
329
+ }
330
+ | {
331
+ readonly op: "service_stream_request";
332
+ readonly name: string;
333
+ readonly key: string;
334
+ readonly okKind: string;
335
+ readonly errKind: string;
336
+ readonly typedService: true;
337
+ readonly channelKey: number;
338
+ readonly eventKind: string;
339
+ readonly maxPending: number;
164
340
  readonly payload: Uint8Array;
165
341
  }
166
342
  | { readonly op: "cancel"; readonly key: string }
@@ -179,6 +355,53 @@ export type CmdData =
179
355
  readonly path: Uint8Array;
180
356
  readonly bytes: Uint8Array;
181
357
  }
358
+ | {
359
+ readonly op: "store_set";
360
+ readonly key: string;
361
+ readonly okKind: string;
362
+ readonly errKind: string;
363
+ readonly storeKey: string;
364
+ readonly bytes: Uint8Array;
365
+ }
366
+ | {
367
+ readonly op: "store_get" | "store_delete";
368
+ readonly key: string;
369
+ readonly okKind: string;
370
+ readonly errKind: string;
371
+ readonly storeKey: string;
372
+ }
373
+ | {
374
+ readonly op: "store_scan";
375
+ readonly key: string;
376
+ readonly okKind: string;
377
+ readonly errKind: string;
378
+ readonly prefix: string;
379
+ readonly limit: number;
380
+ readonly after: string | Uint8Array;
381
+ }
382
+ | {
383
+ readonly op: "store_set_many";
384
+ readonly key: string;
385
+ readonly okKind: string;
386
+ readonly errKind: string;
387
+ readonly entries: ReadonlyArray<readonly [string, Uint8Array]>;
388
+ }
389
+ | {
390
+ readonly op: "db_query";
391
+ readonly key: string;
392
+ readonly pageKind: string;
393
+ readonly doneKind: string;
394
+ readonly errKind: string;
395
+ readonly sql: string;
396
+ readonly params: ReadonlyArray<DbValue>;
397
+ }
398
+ | {
399
+ readonly op: "db_exec";
400
+ readonly key: string;
401
+ readonly okKind: string;
402
+ readonly errKind: string;
403
+ readonly statements: ReadonlyArray<DbStatement>;
404
+ }
182
405
  | {
183
406
  readonly op: "fetch";
184
407
  readonly key: string;
@@ -190,6 +413,19 @@ export type CmdData =
190
413
  readonly headers: readonly { readonly name: string; readonly value: string | Uint8Array }[];
191
414
  readonly body: Uint8Array;
192
415
  }
416
+ | {
417
+ readonly op: "fetch_stream";
418
+ readonly key: string;
419
+ readonly lineKind: string;
420
+ readonly okKind: string;
421
+ readonly errKind: string;
422
+ readonly method: FetchMethod;
423
+ readonly timeoutMs: number;
424
+ readonly maxLineBytes: number;
425
+ readonly url: Uint8Array;
426
+ readonly headers: readonly { readonly name: string; readonly value: string | Uint8Array }[];
427
+ readonly body: Uint8Array;
428
+ }
193
429
  | { readonly op: "clip_write"; readonly bytes: Uint8Array }
194
430
  | { readonly op: "clip_read"; readonly key: string; readonly okKind: string; readonly errKind: string }
195
431
  | { readonly op: "show_notification"; readonly title: Uint8Array; readonly subtitle: Uint8Array; readonly body: Uint8Array }
@@ -237,6 +473,8 @@ export type CmdData =
237
473
  readonly value: number;
238
474
  }
239
475
  | { readonly op: "window_show"; readonly label: string }
476
+ | { readonly op: "window_hide"; readonly label: string }
477
+ | { readonly op: "dock_presence"; readonly visible: boolean }
240
478
  | { readonly op: "quit_app" }
241
479
  | {
242
480
  readonly op: "image_load";
@@ -249,8 +487,10 @@ export type CmdData =
249
487
  }
250
488
  | { readonly op: "image_cancel"; readonly id: number }
251
489
  | { readonly op: "image_unregister"; readonly id: number }
252
- | { readonly op: "channel_open"; readonly key: number; readonly eventKind: string }
490
+ | { readonly op: "channel_open"; readonly key: number; readonly eventKind: string; readonly maxPending: number }
253
491
  | { readonly op: "channel_close"; readonly key: number }
492
+ | { readonly op: "audio_capture_start"; readonly key: number; readonly source: "microphone" | "system"; readonly sampleRate: number; readonly channels: number; readonly eventKind: string }
493
+ | { readonly op: "audio_capture_stop"; readonly key: number }
254
494
  | {
255
495
  readonly op: "pty_spawn";
256
496
  readonly key: string;
@@ -305,6 +545,68 @@ export function hostRecordBytes(payload: HostRecord): Uint8Array {
305
545
  return out;
306
546
  }
307
547
 
548
+ function serviceU32(value: number): Uint8Array {
549
+ const out = new Uint8Array(4);
550
+ out[0] = value % 256;
551
+ out[1] = Math.floor(value / 256) % 256;
552
+ out[2] = Math.floor(value / 65536) % 256;
553
+ out[3] = Math.floor(value / 16777216) % 256;
554
+ return out;
555
+ }
556
+
557
+ export function serviceConcat(parts: readonly Uint8Array[]): Uint8Array {
558
+ let length = 0;
559
+ for (const part of parts) length += part.length;
560
+ const out = new Uint8Array(length);
561
+ let at = 0;
562
+ for (const part of parts) {
563
+ for (let i = 0; i < part.length; i++) out[at + i] = part[i]!;
564
+ at += part.length;
565
+ }
566
+ return out;
567
+ }
568
+
569
+ export function serviceBoolBytes(value: boolean): Uint8Array {
570
+ return new Uint8Array([value ? 1 : 0]);
571
+ }
572
+
573
+ export function serviceF64Bytes(value: number): Uint8Array {
574
+ const out = new Uint8Array(8);
575
+ const buf = Buffer.alloc(8);
576
+ buf.writeDoubleLE(Number.isNaN(value) ? Number.NaN : value, 0);
577
+ for (let i = 0; i < 8; i++) out[i] = buf[i]!;
578
+ return out;
579
+ }
580
+
581
+ export function serviceI64Bytes(value: number): Uint8Array {
582
+ const base = 4294967296;
583
+ let low = value % base;
584
+ if (low < 0) low += base;
585
+ let high = Math.floor(value / base);
586
+ if (high < 0) high += base;
587
+ return serviceConcat([serviceU32(low), serviceU32(high)]);
588
+ }
589
+
590
+ export function serviceBytes(value: Uint8Array): Uint8Array {
591
+ return serviceConcat([serviceU32(value.length), value]);
592
+ }
593
+
594
+ export function serviceEnumBytes(index: number): Uint8Array {
595
+ return serviceU32(index);
596
+ }
597
+
598
+ export function serviceUnionBytes(index: number): Uint8Array {
599
+ return new Uint8Array([index]);
600
+ }
601
+
602
+ export function serviceOptionalBytes(value: Uint8Array | null): Uint8Array {
603
+ return value === null ? new Uint8Array([0]) : serviceConcat([new Uint8Array([1]), value]);
604
+ }
605
+
606
+ export function serviceSliceBytes(values: readonly Uint8Array[]): Uint8Array {
607
+ return serviceConcat([serviceU32(values.length), ...values]);
608
+ }
609
+
308
610
  /// A host command by name — the reference module's overloaded `host`
309
611
  /// restated as the raw-bytes form (the whole corpus's usage; overloads,
310
612
  /// rest-args, and the `Uint8Array | HostRecord` runtime discrimination
@@ -326,6 +628,8 @@ export function hostArgs(name: string, args: readonly number[]): CmdData {
326
628
  export const Cmd = {
327
629
  none: { op: "none" } as CmdData,
328
630
 
631
+ /// Snapshot the just-committed Model through the capability-gated,
632
+ /// engine-owned persistence store. Wire output remains the reserved 0x01.
329
633
  persist(): CmdData {
330
634
  return { op: "persist" };
331
635
  },
@@ -343,10 +647,48 @@ export const Cmd = {
343
647
  key: route.key ?? "",
344
648
  okKind: route.ok,
345
649
  errKind: route.err,
650
+ typedService: false,
346
651
  payload: payload,
347
652
  };
348
653
  },
349
654
 
655
+ serviceRequest(
656
+ name: string,
657
+ payload: Uint8Array,
658
+ route: { readonly key?: string; readonly ok: string; readonly err: string },
659
+ ): CmdData {
660
+ return {
661
+ op: "request",
662
+ name,
663
+ key: route.key ?? "",
664
+ okKind: route.ok,
665
+ errKind: route.err,
666
+ typedService: true,
667
+ payload,
668
+ };
669
+ },
670
+
671
+ serviceStreamRequest(
672
+ name: string,
673
+ channelKey: number,
674
+ payload: Uint8Array,
675
+ route: { readonly key?: string; readonly ok: string; readonly err: string; readonly event: string },
676
+ maxPending: number,
677
+ ): CmdData {
678
+ return {
679
+ op: "service_stream_request",
680
+ name,
681
+ key: route.key ?? "",
682
+ okKind: route.ok,
683
+ errKind: route.err,
684
+ typedService: true,
685
+ channelKey,
686
+ eventKind: route.event,
687
+ maxPending,
688
+ payload: serviceConcat([serviceF64Bytes(channelKey), payload]),
689
+ };
690
+ },
691
+
350
692
  cancel(key: string): CmdData {
351
693
  return { op: "cancel", key };
352
694
  },
@@ -359,12 +701,71 @@ export const Cmd = {
359
701
  return { op: "write_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path, bytes };
360
702
  },
361
703
 
362
- fetch(spec: FetchSpec, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
704
+ store: {
705
+ set(storeKey: string, bytes: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
706
+ return { op: "store_set", key: route.key ?? "", okKind: route.ok, errKind: route.err, storeKey, bytes };
707
+ },
708
+ get(storeKey: string, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
709
+ return { op: "store_get", key: route.key ?? "", okKind: route.ok, errKind: route.err, storeKey };
710
+ },
711
+ delete(storeKey: string, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
712
+ return { op: "store_delete", key: route.key ?? "", okKind: route.ok, errKind: route.err, storeKey };
713
+ },
714
+ scan(prefix: string, options: StoreScanOptions, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
715
+ return { op: "store_scan", key: route.key ?? "", okKind: route.ok, errKind: route.err, prefix, limit: options.limit ?? 0, after: options.after ?? "" };
716
+ },
717
+ setMany(entries: ReadonlyArray<readonly [string, Uint8Array]>, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
718
+ return { op: "store_set_many", key: route.key ?? "", okKind: route.ok, errKind: route.err, entries };
719
+ },
720
+ },
721
+
722
+ credentials: {
723
+ set(credentialKey: string, secret: Uint8Array, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
724
+ return { op: "request", name: "core.credentials.set", key: route.key ?? "", okKind: route.ok, errKind: route.err, typedService: false, payload: hostRecordBytes({ key: utf8Bytes(credentialKey), secret }) };
725
+ },
726
+ get(credentialKey: string, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
727
+ return Cmd.request("core.credentials.get", hostRecordBytes({ key: utf8Bytes(credentialKey) }), route);
728
+ },
729
+ delete(credentialKey: string, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
730
+ return { op: "request", name: "core.credentials.delete", key: route.key ?? "", okKind: route.ok, errKind: route.err, typedService: false, payload: hostRecordBytes({ key: utf8Bytes(credentialKey) }) };
731
+ },
732
+ },
733
+
734
+ db: {
735
+ query(sql: string, params: ReadonlyArray<DbValue>, route: { readonly key?: string; readonly page: string; readonly done: string; readonly err: string }): CmdData {
736
+ return { op: "db_query", key: route.key ?? "", pageKind: route.page, doneKind: route.done, errKind: route.err, sql, params };
737
+ },
738
+ exec(statements: ReadonlyArray<DbStatement>, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
739
+ return { op: "db_exec", key: route.key ?? "", okKind: route.ok, errKind: route.err, statements };
740
+ },
741
+ },
742
+
743
+ // @native-sqlite-generated-cmds
744
+
745
+ fetch(
746
+ spec: FetchStreamSpec,
747
+ route: { readonly key?: string; readonly line?: string; readonly ok: string; readonly err: string },
748
+ ): CmdData {
363
749
  const names = Object.keys(spec.headers ?? {}).sort();
364
750
  const headers: { readonly name: string; readonly value: string | Uint8Array }[] = [];
365
751
  for (const n of names) {
366
752
  headers.push({ name: n, value: spec.headers![n]! });
367
753
  }
754
+ if (route.line !== undefined) {
755
+ return {
756
+ op: "fetch_stream",
757
+ key: route.key ?? "",
758
+ lineKind: route.line,
759
+ okKind: route.ok,
760
+ errKind: route.err,
761
+ method: spec.method ?? "GET",
762
+ timeoutMs: spec.timeoutMs ?? 0,
763
+ maxLineBytes: spec.maxLineBytes ?? 0,
764
+ url: spec.url,
765
+ headers: headers,
766
+ body: spec.body ?? new Uint8Array(0),
767
+ };
768
+ }
368
769
  return {
369
770
  op: "fetch",
370
771
  key: route.key ?? "",
@@ -395,6 +796,23 @@ export const Cmd = {
395
796
  };
396
797
  },
397
798
 
799
+ openExternalUrl(url: Uint8Array): CmdData {
800
+ return { op: "host_bytes", name: "native-sdk.os.openUrl", payload: url };
801
+ },
802
+
803
+ revealPath(path: Uint8Array): CmdData {
804
+ return { op: "host_bytes", name: "native-sdk.os.revealPath", payload: path };
805
+ },
806
+
807
+ formatLocalTime(
808
+ timestampMs: number,
809
+ style: LocalTimeStyle,
810
+ route: { readonly key?: string; readonly ok: string; readonly err: string },
811
+ ): CmdData {
812
+ const styleCode = style === "date" ? 0 : style === "time" ? 1 : 2;
813
+ return Cmd.request("native-sdk.time.formatLocal", hostRecordBytes({ style: styleCode, timestampMs }), route);
814
+ },
815
+
398
816
  delay(key: string, ms: number, msgKind: string): CmdData {
399
817
  return { op: "delay", key, afterMs: ms, msgKind };
400
818
  },
@@ -494,6 +912,22 @@ export const Cmd = {
494
912
  return { op: "window_show", label };
495
913
  },
496
914
 
915
+ hideWindow(label: string): CmdData {
916
+ return { op: "window_hide", label };
917
+ },
918
+
919
+ setDockPresence(visible: boolean): CmdData {
920
+ return { op: "dock_presence", visible };
921
+ },
922
+
923
+ launchAtLoginStatus(route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
924
+ return Cmd.request("native-sdk.launch-at-login.status", new Uint8Array(0), route);
925
+ },
926
+
927
+ setLaunchAtLogin(enabled: boolean, route: { readonly key?: string; readonly ok: string; readonly err: string }): CmdData {
928
+ return Cmd.request("native-sdk.launch-at-login.set", new Uint8Array([enabled ? 1 : 0]), route);
929
+ },
930
+
497
931
  quitApp(): CmdData {
498
932
  return { op: "quit_app" };
499
933
  },
@@ -519,13 +953,28 @@ export const Cmd = {
519
953
  },
520
954
 
521
955
  channelOpen(key: number, route: { readonly event: string }): CmdData {
522
- return { op: "channel_open", key, eventKind: route.event };
956
+ return { op: "channel_open", key, eventKind: route.event, maxPending: 64 };
523
957
  },
524
958
 
525
959
  channelClose(key: number): CmdData {
526
960
  return { op: "channel_close", key };
527
961
  },
528
962
 
963
+ audioCaptureStart(key: number, spec: AudioCaptureSpec, route: { readonly event: string }): CmdData {
964
+ return {
965
+ op: "audio_capture_start",
966
+ key,
967
+ source: spec.source,
968
+ sampleRate: spec.sampleRate ?? 48000,
969
+ channels: spec.channels ?? 1,
970
+ eventKind: route.event,
971
+ };
972
+ },
973
+
974
+ audioCaptureStop(key: number): CmdData {
975
+ return { op: "audio_capture_stop", key };
976
+ },
977
+
529
978
  ptySpawn(argv: readonly Uint8Array[], route: { readonly key?: string; readonly cols?: number; readonly rows?: number; readonly term?: string; readonly event: string }): CmdData {
530
979
  return {
531
980
  op: "pty_spawn",
@@ -558,6 +1007,7 @@ export const Cmd = {
558
1007
  export type SubData =
559
1008
  | { readonly op: "none" }
560
1009
  | { readonly op: "timer"; readonly key: string; readonly everyMs: number; readonly msgKind: string }
1010
+ | { 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[] }
561
1011
  | { readonly op: "batch"; readonly subs: readonly SubData[] };
562
1012
 
563
1013
  export type Sub<M extends Msgish> = SubData;
@@ -569,6 +1019,8 @@ export const Sub = {
569
1019
  return { op: "timer", key, everyMs, msgKind };
570
1020
  },
571
1021
 
1022
+ // @native-sqlite-generated-subs
1023
+
572
1024
  batch(subs: readonly SubData[]): SubData {
573
1025
  return { op: "batch", subs };
574
1026
  },
@@ -1,32 +1,32 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.8.3",
3
+ "version": "0.9.0",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@native-sdk/core",
9
- "version": "0.8.3",
9
+ "version": "0.9.0",
10
10
  "dependencies": {
11
- "scriptc": "0.0.22"
11
+ "scriptc": "0.0.28"
12
12
  },
13
13
  "devDependencies": {
14
14
  "@typescript/old": "npm:typescript@6.0.3"
15
15
  }
16
16
  },
17
17
  "node_modules/@scriptc/compiler": {
18
- "version": "0.0.22",
19
- "integrity": "sha512-cZil7ZgK64yRpSk1X3BSq1Q2DBru53KfC4X0i/qa0vHNk/rvk3teDzykSP5l3nb5wY2ckh0Es3fojfD0kUp/gA==",
18
+ "version": "0.0.28",
19
+ "integrity": "sha512-zq41x81F209cPrW4T+qMGlcIu8joveB2S26vYePIktbmpCVe+ZwdLnDvAY6aTuktoqTVjXXcsR3ebxGyuGh7rQ==",
20
20
  "license": "Apache-2.0",
21
21
  "dependencies": {
22
- "@scriptc/runtime": "0.0.22",
22
+ "@scriptc/runtime": "0.0.28",
23
23
  "typescript": "7.0.2",
24
24
  "typescript5": "npm:typescript@5.9.3"
25
25
  }
26
26
  },
27
27
  "node_modules/@scriptc/runtime": {
28
- "version": "0.0.22",
29
- "integrity": "sha512-UytlS/6vxWXYIpIO2lQYVh4xTzMoybX0Uz1wKA41ezq62sMeuhHT6JVappUG55DgVNAWGgMI/WAHun2TeRutNg==",
28
+ "version": "0.0.28",
29
+ "integrity": "sha512-x7wO/i75fW4sJ8wY16Tr8ImX1SBROy3BIDZK2H4fafAC0rBI1LsYnxJogHqdeahkxUPDkWwuXZPoPC1vxAljGg==",
30
30
  "license": "Apache-2.0"
31
31
  },
32
32
  "node_modules/@typescript/old": {
@@ -344,11 +344,11 @@
344
344
  }
345
345
  },
346
346
  "node_modules/scriptc": {
347
- "version": "0.0.22",
348
- "integrity": "sha512-gJQ5Johx477Al1EqZOTeXOPsPgwzSOvVljIc9l1S0BqhaffyZtxXa1Mm3YFKZaCV3u4YNAEMsbO9EBgvW1awDg==",
347
+ "version": "0.0.28",
348
+ "integrity": "sha512-adYCjzHtD7XJyJg3g+gtkrTvONRqiRHsp8ZjkH2ot4FNCHPeix6ebqi88pyP9ZFHMh2bNZe2z3M3/2yHZFwOTg==",
349
349
  "license": "Apache-2.0",
350
350
  "dependencies": {
351
- "@scriptc/compiler": "0.0.22"
351
+ "@scriptc/compiler": "0.0.28"
352
352
  },
353
353
  "bin": {
354
354
  "scriptc": "dist/main.js"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.8.3",
3
+ "version": "0.9.0",
4
4
  "description": "The TypeScript authoring tier: the app-core subset, its checker and contract frontend, the exact-pinned core compiler dependency, and the SDK module cores import",
5
5
  "repository": {
6
6
  "type": "git",
@@ -36,6 +36,6 @@
36
36
  "@typescript/old": "npm:typescript@6.0.3"
37
37
  },
38
38
  "dependencies": {
39
- "scriptc": "0.0.22"
39
+ "scriptc": "0.0.28"
40
40
  }
41
41
  }