@native-sdk/cli 0.8.4 → 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 (146) hide show
  1. package/build/app.zig +859 -62
  2. package/build.zig +543 -13
  3. package/build.zig.zon +1 -0
  4. package/native-sdk.d.ts +2 -0
  5. package/package.json +12 -11
  6. package/packages/core/compile-surface/core.ts +365 -2
  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 +149 -0
  19. package/packages/core/sdk/core.ts +529 -12
  20. package/packages/core/sdk/events.d.ts +36 -0
  21. package/packages/core/sdk/events.ts +57 -0
  22. package/packages/core/src/checker.ts +468 -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 +1847 -16
  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 +82 -16
  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/references/project-anatomy.md +1 -1
  38. package/skill-data/native-ui/SKILL.md +47 -0
  39. package/skill-data/ts-core/SKILL.md +80 -31
  40. package/skill-data/ts-services/SKILL.md +126 -0
  41. package/skill-data/ts-services/references/service-surface.md +603 -0
  42. package/skill-data/zig/SKILL.md +1 -1
  43. package/skills/native-sdk/SKILL.md +1 -1
  44. package/src/app_runner/no_migrations.zig +3 -0
  45. package/src/app_runner/no_services.zig +20 -0
  46. package/src/app_runner/root.zig +104 -4
  47. package/src/app_runner/ts_core_main.zig +249 -8
  48. package/src/automation/snapshot.zig +23 -5
  49. package/src/embed/app_exports.zig +11 -1
  50. package/src/embed/c_api.zig +48 -2
  51. package/src/embed/conversions.zig +4 -5
  52. package/src/embed/host.zig +109 -1
  53. package/src/embed/root.zig +7 -0
  54. package/src/embed/tests.zig +213 -0
  55. package/src/embed/types.zig +51 -0
  56. package/src/embed/ui_host.zig +119 -5
  57. package/src/platform/android/NativeSdkActivity.java +131 -0
  58. package/src/platform/android/android_host.c +182 -1
  59. package/src/platform/android/native_sdk_app.h +17 -0
  60. package/src/platform/ios/native_sdk_app.h +17 -0
  61. package/src/platform/ios/uikit_host.m +115 -0
  62. package/src/platform/linux/cef_host.cpp +1 -1
  63. package/src/platform/linux/gtk_host.c +89 -17
  64. package/src/platform/linux/gtk_host.h +3 -0
  65. package/src/platform/linux/root.zig +40 -18
  66. package/src/platform/macos/appkit_host.h +16 -3
  67. package/src/platform/macos/appkit_host.m +536 -36
  68. package/src/platform/macos/cef_host.mm +248 -36
  69. package/src/platform/macos/root.zig +244 -34
  70. package/src/platform/null_platform.zig +223 -19
  71. package/src/platform/null_platform_tests.zig +74 -0
  72. package/src/platform/root.zig +9 -0
  73. package/src/platform/types.zig +179 -15
  74. package/src/platform/windows/root.zig +187 -21
  75. package/src/platform/windows/webview2_host.cpp +293 -46
  76. package/src/primitives/app_manifest/comptime_scene.zig +2 -0
  77. package/src/primitives/app_manifest/root.zig +4 -0
  78. package/src/primitives/app_manifest/tests.zig +3 -0
  79. package/src/primitives/app_manifest/types.zig +32 -0
  80. package/src/primitives/app_manifest/validation.zig +19 -1
  81. package/src/root.zig +46 -0
  82. package/src/runtime/api.zig +11 -0
  83. package/src/runtime/automation_snapshot.zig +4 -0
  84. package/src/runtime/bridge_permission_tests.zig +23 -2
  85. package/src/runtime/bridge_responses.zig +3 -1
  86. package/src/runtime/canvas_frame.zig +18 -11
  87. package/src/runtime/canvas_frame_animation_tests.zig +4 -0
  88. package/src/runtime/clock.zig +13 -1
  89. package/src/runtime/core.zig +133 -1
  90. package/src/runtime/credentials_store.zig +115 -0
  91. package/src/runtime/effects.zig +2295 -113
  92. package/src/runtime/effects_credentials_tests.zig +332 -0
  93. package/src/runtime/effects_host_tests.zig +208 -1
  94. package/src/runtime/effects_relational_tests.zig +314 -0
  95. package/src/runtime/effects_store_tests.zig +211 -0
  96. package/src/runtime/flow.zig +14 -1
  97. package/src/runtime/gpu_surface_events.zig +6 -1
  98. package/src/runtime/native_command_event_tests.zig +42 -0
  99. package/src/runtime/persist_store.zig +666 -0
  100. package/src/runtime/record_store.zig +788 -0
  101. package/src/runtime/relational_store.zig +854 -0
  102. package/src/runtime/root.zig +49 -0
  103. package/src/runtime/runtime_event_tests.zig +70 -0
  104. package/src/runtime/service_host.zig +711 -0
  105. package/src/runtime/service_pool.zig +1314 -0
  106. package/src/runtime/session_blobs.zig +1 -1
  107. package/src/runtime/session_journal.zig +102 -0
  108. package/src/runtime/session_record.zig +177 -0
  109. package/src/runtime/session_replay.zig +109 -4
  110. package/src/runtime/shell_layout.zig +1 -0
  111. package/src/runtime/shell_layout_tests.zig +120 -0
  112. package/src/runtime/sqlite_engine.zig +474 -0
  113. package/src/runtime/state.zig +6 -0
  114. package/src/runtime/system_services.zig +49 -10
  115. package/src/runtime/tests.zig +4 -0
  116. package/src/runtime/ts_core_host.zig +788 -86
  117. package/src/runtime/ts_core_host_tests.zig +231 -11
  118. package/src/runtime/ts_ui_app.zig +499 -1
  119. package/src/runtime/ui_app.zig +142 -16
  120. package/src/runtime/ui_app_tests.zig +155 -5
  121. package/src/runtime/validation.zig +22 -0
  122. package/src/runtime/view.zig +9 -0
  123. package/src/runtime/window_storage.zig +1 -0
  124. package/src/runtime/window_view_runtime.zig +2 -3
  125. package/src/runtime/window_views.zig +19 -0
  126. package/src/tooling/android.zig +21 -16
  127. package/src/tooling/db.zig +160 -0
  128. package/src/tooling/ios.zig +7 -1
  129. package/src/tooling/manifest.zig +214 -2
  130. package/src/tooling/package.zig +116 -0
  131. package/src/tooling/raw_manifest.zig +30 -0
  132. package/src/tooling/root.zig +1 -0
  133. package/src/tooling/templates.zig +161 -4
  134. package/src/tooling/ts_core.zig +283 -17
  135. package/src/tooling/verbs.zig +7 -0
  136. package/third_party/sqlite/README.md +13 -0
  137. package/third_party/sqlite/sqlite3.c +269649 -0
  138. package/third_party/sqlite/sqlite3.h +14349 -0
  139. package/tools/corewire/core_abi.zig +14 -2
  140. package/tools/corewire/emit.zig +98 -29
  141. package/tools/corewire/emit_facade.zig +378 -23
  142. package/tools/corewire/emit_profile.zig +6 -2
  143. package/tools/corewire/emit_service.zig +924 -0
  144. package/tools/corewire/main.zig +122 -0
  145. package/tools/corewire/service_contract.zig +250 -0
  146. 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;
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.0",
4
4
  "description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
5
5
  "type": "module",
6
6
  "bin": {
@@ -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.28"
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.0",
39
+ "@native-sdk/cli-darwin-x64": "0.9.0",
40
+ "@native-sdk/cli-linux-arm64-gnu": "0.9.0",
41
+ "@native-sdk/cli-linux-arm64-musl": "0.9.0",
42
+ "@native-sdk/cli-linux-x64-gnu": "0.9.0",
43
+ "@native-sdk/cli-linux-x64-musl": "0.9.0",
44
+ "@native-sdk/cli-win32-arm64": "0.9.0",
45
+ "@native-sdk/cli-win32-x64": "0.9.0"
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,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,12 +126,61 @@ 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"];
@@ -187,6 +307,8 @@ export interface NotificationSpec {
187
307
  readonly body?: Uint8Array;
188
308
  }
189
309
 
310
+ export type LocalTimeStyle = "date" | "time" | "datetime";
311
+
190
312
  /// The inert command data — the reference module's Cmd<M> union with
191
313
  /// the type parameter erased (M constrains only the factories' arm-name
192
314
  /// checking, never the data).
@@ -202,6 +324,19 @@ export type CmdData =
202
324
  readonly key: string;
203
325
  readonly okKind: string;
204
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;
205
340
  readonly payload: Uint8Array;
206
341
  }
207
342
  | { readonly op: "cancel"; readonly key: string }
@@ -220,6 +355,53 @@ export type CmdData =
220
355
  readonly path: Uint8Array;
221
356
  readonly bytes: Uint8Array;
222
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
+ }
223
405
  | {
224
406
  readonly op: "fetch";
225
407
  readonly key: string;
@@ -291,6 +473,8 @@ export type CmdData =
291
473
  readonly value: number;
292
474
  }
293
475
  | { readonly op: "window_show"; readonly label: string }
476
+ | { readonly op: "window_hide"; readonly label: string }
477
+ | { readonly op: "dock_presence"; readonly visible: boolean }
294
478
  | { readonly op: "quit_app" }
295
479
  | {
296
480
  readonly op: "image_load";
@@ -303,7 +487,7 @@ export type CmdData =
303
487
  }
304
488
  | { readonly op: "image_cancel"; readonly id: number }
305
489
  | { readonly op: "image_unregister"; readonly id: number }
306
- | { readonly op: "channel_open"; readonly key: number; readonly eventKind: string }
490
+ | { readonly op: "channel_open"; readonly key: number; readonly eventKind: string; readonly maxPending: number }
307
491
  | { readonly op: "channel_close"; readonly key: number }
308
492
  | { readonly op: "audio_capture_start"; readonly key: number; readonly source: "microphone" | "system"; readonly sampleRate: number; readonly channels: number; readonly eventKind: string }
309
493
  | { readonly op: "audio_capture_stop"; readonly key: number }
@@ -361,6 +545,68 @@ export function hostRecordBytes(payload: HostRecord): Uint8Array {
361
545
  return out;
362
546
  }
363
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
+
364
610
  /// A host command by name — the reference module's overloaded `host`
365
611
  /// restated as the raw-bytes form (the whole corpus's usage; overloads,
366
612
  /// rest-args, and the `Uint8Array | HostRecord` runtime discrimination
@@ -382,6 +628,8 @@ export function hostArgs(name: string, args: readonly number[]): CmdData {
382
628
  export const Cmd = {
383
629
  none: { op: "none" } as CmdData,
384
630
 
631
+ /// Snapshot the just-committed Model through the capability-gated,
632
+ /// engine-owned persistence store. Wire output remains the reserved 0x01.
385
633
  persist(): CmdData {
386
634
  return { op: "persist" };
387
635
  },
@@ -399,10 +647,48 @@ export const Cmd = {
399
647
  key: route.key ?? "",
400
648
  okKind: route.ok,
401
649
  errKind: route.err,
650
+ typedService: false,
402
651
  payload: payload,
403
652
  };
404
653
  },
405
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
+
406
692
  cancel(key: string): CmdData {
407
693
  return { op: "cancel", key };
408
694
  },
@@ -415,6 +701,47 @@ export const Cmd = {
415
701
  return { op: "write_file", key: route.key ?? "", okKind: route.ok, errKind: route.err, path, bytes };
416
702
  },
417
703
 
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
+
418
745
  fetch(
419
746
  spec: FetchStreamSpec,
420
747
  route: { readonly key?: string; readonly line?: string; readonly ok: string; readonly err: string },
@@ -469,6 +796,23 @@ export const Cmd = {
469
796
  };
470
797
  },
471
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
+
472
816
  delay(key: string, ms: number, msgKind: string): CmdData {
473
817
  return { op: "delay", key, afterMs: ms, msgKind };
474
818
  },
@@ -568,6 +912,22 @@ export const Cmd = {
568
912
  return { op: "window_show", label };
569
913
  },
570
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
+
571
931
  quitApp(): CmdData {
572
932
  return { op: "quit_app" };
573
933
  },
@@ -593,7 +953,7 @@ export const Cmd = {
593
953
  },
594
954
 
595
955
  channelOpen(key: number, route: { readonly event: string }): CmdData {
596
- return { op: "channel_open", key, eventKind: route.event };
956
+ return { op: "channel_open", key, eventKind: route.event, maxPending: 64 };
597
957
  },
598
958
 
599
959
  channelClose(key: number): CmdData {
@@ -647,6 +1007,7 @@ export const Cmd = {
647
1007
  export type SubData =
648
1008
  | { readonly op: "none" }
649
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[] }
650
1011
  | { readonly op: "batch"; readonly subs: readonly SubData[] };
651
1012
 
652
1013
  export type Sub<M extends Msgish> = SubData;
@@ -658,6 +1019,8 @@ export const Sub = {
658
1019
  return { op: "timer", key, everyMs, msgKind };
659
1020
  },
660
1021
 
1022
+ // @native-sqlite-generated-subs
1023
+
661
1024
  batch(subs: readonly SubData[]): SubData {
662
1025
  return { op: "batch", subs };
663
1026
  },
@@ -1,32 +1,32 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.8.4",
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.4",
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.4",
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
  }