@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
@@ -14,7 +14,10 @@
14
14
  //! imports are real files; the resolver hook maps only the SDK names).
15
15
 
16
16
  const std = @import("std");
17
+ const app_dirs = @import("app_dirs");
17
18
  const buildgraph = @import("buildgraph.zig");
19
+ const debug = @import("debug");
20
+ const package_tool = @import("package.zig");
18
21
  const process_tree = @import("process_tree.zig");
19
22
 
20
23
  pub const Error = error{
@@ -403,21 +406,138 @@ pub fn ensureResolvedTranspiler(allocator: std.mem.Allocator, io: std.Io, framew
403
406
  return transpilerDepsMissing(resolved);
404
407
  }
405
408
 
406
- /// `native check` over a TypeScript core: run the frontend in
407
- /// check-only mode on src/core.ts — and, through it, the core's whole
408
- /// import graph under src/ — and surface its NS diagnostics verbatim —
409
- /// they are the teaching layer, nothing wraps them (each diagnostic
410
- /// carries the owning module's path). Exit 0 = typechecked,
411
- /// subset-clean.
412
- pub fn checkCore(allocator: std.mem.Allocator, io: std.Io, base_env: *std.process.Environ.Map, framework_root: []const u8) !void {
409
+ pub const PersistRoutes = struct {
410
+ ok: []const u8,
411
+ none: []const u8,
412
+ err: []const u8,
413
+ };
414
+
415
+ /// Run the real-SQLite schema/query lane used by the build and return the
416
+ /// generated SDK core path that exposes this app's Cmd.q/Sub.q surface.
417
+ /// Generated outputs live under ignored .native/cache. The append-only
418
+ /// migration authority lives beside the authored migrations so it is visible
419
+ /// to version control and survives a clean checkout.
420
+ pub fn generateSqliteSurface(
421
+ allocator: std.mem.Allocator,
422
+ io: std.Io,
423
+ base_env: *std.process.Environ.Map,
424
+ framework_root: []const u8,
425
+ install_editor_surface: bool,
426
+ ) ![]u8 {
427
+ const sqlite_cli = try transpilerPath(allocator, io, framework_root, "src/sqlite_cli.ts");
428
+ defer allocator.free(sqlite_cli);
429
+ const runner = try tsRunnerPath(allocator, io, framework_root);
430
+ defer allocator.free(runner);
431
+ const sdk_in = try transpilerPath(allocator, io, framework_root, "sdk/core.ts");
432
+ defer allocator.free(sdk_in);
433
+ const static_in = try transpilerPath(allocator, io, framework_root, "compile-surface/core.ts");
434
+ defer allocator.free(static_in);
435
+ try std.Io.Dir.cwd().createDirPath(io, ".native/cache/sqlite");
436
+ const sdk_out = try allocator.dupe(u8, ".native/cache/sqlite/core.ts");
437
+ errdefer allocator.free(sdk_out);
438
+ var child = std.process.spawn(io, .{
439
+ .argv = &.{
440
+ "node", runner, sqlite_cli,
441
+ "--src", "src", "--sdk-in",
442
+ sdk_in, "--static-in", static_in,
443
+ "--sdk-out", sdk_out, "--dts-out",
444
+ ".native/cache/sqlite/core.d.ts", "--static-out", ".native/cache/sqlite/core_static.ts",
445
+ "--zig-out", ".native/cache/sqlite/migrations.zig", "--metadata-out",
446
+ ".native/cache/sqlite/metadata.json", "--state", "src/schema/migrations.lock.json",
447
+ },
448
+ .stdin = .ignore,
449
+ .stdout = .inherit,
450
+ .stderr = .inherit,
451
+ .environ_map = base_env,
452
+ }) catch return nodeMissing();
453
+ const term = try child.wait(io);
454
+ switch (term) {
455
+ .exited => |code| if (code == 0) {
456
+ if (install_editor_surface) {
457
+ materializeSqliteEditorSurface(allocator, io, ".", sdk_out) catch {};
458
+ }
459
+ const absolute = try std.Io.Dir.cwd().realPathFileAlloc(io, ".native/cache/sqlite/core.d.ts", allocator);
460
+ allocator.free(sdk_out);
461
+ return absolute;
462
+ },
463
+ else => {},
464
+ }
465
+ std.debug.print("native check: the relational schema or declared queries failed (diagnostics above)\n", .{});
466
+ return error.SqliteCheckFailed;
467
+ }
468
+
469
+ pub const ServicePackage = struct {
470
+ name: []const u8,
471
+ version: []const u8,
472
+ content_hash: []const u8,
473
+ };
474
+
475
+ /// Run the TypeScript frontend in check-only mode on src/core.ts — and,
476
+ /// through it, the core's whole import graph under src/ — and surface its NS
477
+ /// diagnostics verbatim. Manifest-owned routes ride into the same typed Msg
478
+ /// contract the watched dev host invokes on each of its own restarts.
479
+ pub fn checkCore(
480
+ allocator: std.mem.Allocator,
481
+ io: std.Io,
482
+ base_env: *std.process.Environ.Map,
483
+ framework_root: []const u8,
484
+ capabilities: []const []const u8,
485
+ permissions: []const []const u8,
486
+ service_packages: []const ServicePackage,
487
+ persist_version: ?u64,
488
+ persist_routes: ?PersistRoutes,
489
+ sdk_core_path: ?[]const u8,
490
+ ) !void {
413
491
  const cli_path = try transpilerPath(allocator, io, framework_root, "src/cli.ts");
414
492
  defer allocator.free(cli_path);
415
493
  const runner_path = try tsRunnerPath(allocator, io, framework_root);
416
494
  defer allocator.free(runner_path);
417
495
  try ensureResolvedTranspiler(allocator, io, framework_root);
418
496
 
497
+ var argv: std.ArrayList([]const u8) = .empty;
498
+ defer argv.deinit(allocator);
499
+ var persist_version_arg: ?[]u8 = null;
500
+ defer if (persist_version_arg) |value| allocator.free(value);
501
+ try argv.appendSlice(allocator, &.{ "node", runner_path, cli_path, "src/core.ts" });
502
+ for (capabilities) |capability| try argv.appendSlice(allocator, &.{ "--capability", capability });
503
+ for (permissions) |permission| try argv.appendSlice(allocator, &.{ "--permission", permission });
504
+ var service_package_args: std.ArrayList([]u8) = .empty;
505
+ defer {
506
+ for (service_package_args.items) |value| allocator.free(value);
507
+ service_package_args.deinit(allocator);
508
+ }
509
+ for (service_packages) |package_entry| {
510
+ const spelling = try std.fmt.allocPrint(allocator, "{s}|{s}|{s}", .{ package_entry.name, package_entry.version, package_entry.content_hash });
511
+ try service_package_args.append(allocator, spelling);
512
+ try argv.appendSlice(allocator, &.{ "--service-package", spelling });
513
+ }
514
+ if (try package_tool.projectHasTypeScriptServices(allocator, io, ".")) {
515
+ try argv.appendSlice(allocator, &.{ "--services-editor-client", "node_modules/@native-sdk/services/index.ts" });
516
+ } else {
517
+ std.Io.Dir.cwd().deleteTree(io, "node_modules/@native-sdk/services") catch {};
518
+ }
519
+ if (persist_version) |version| {
520
+ persist_version_arg = try std.fmt.allocPrint(allocator, "{d}", .{version});
521
+ try argv.appendSlice(allocator, &.{
522
+ "--persist-version",
523
+ persist_version_arg.?,
524
+ "--persist-state",
525
+ ".native/cache/persist-schema.json",
526
+ });
527
+ }
528
+ if (persist_routes) |routes| {
529
+ try argv.appendSlice(allocator, &.{
530
+ "--persist-ok",
531
+ routes.ok,
532
+ "--persist-none",
533
+ routes.none,
534
+ "--persist-err",
535
+ routes.err,
536
+ });
537
+ }
538
+ if (sdk_core_path) |sdk_core| try argv.appendSlice(allocator, &.{ "--sdk-core", sdk_core });
419
539
  var child = std.process.spawn(io, .{
420
- .argv = &.{ "node", runner_path, cli_path, "src/core.ts" },
540
+ .argv = argv.items,
421
541
  .stdin = .ignore,
422
542
  .stdout = .inherit,
423
543
  .stderr = .inherit,
@@ -440,11 +560,15 @@ pub fn checkCore(allocator: std.mem.Allocator, io: std.Io, base_env: *std.proces
440
560
  /// build verdict come from ONE compiler. Analyzer type errors fail the
441
561
  /// check with the compiler's own diagnostics; a toolchain that cannot
442
562
  /// reach a verdict defers to the build rather than wedging check.
443
- pub fn compilerTypecheckCore(allocator: std.mem.Allocator, io: std.Io, base_env: *std.process.Environ.Map, framework_root: []const u8) !void {
563
+ pub fn compilerTypecheckCore(allocator: std.mem.Allocator, io: std.Io, base_env: *std.process.Environ.Map, framework_root: []const u8, sdk_core_path: ?[]const u8) !void {
444
564
  const script_path = try transpilerPath(allocator, io, framework_root, "scripts/compiler_typecheck.mjs");
445
565
  defer allocator.free(script_path);
566
+ var argv: std.ArrayList([]const u8) = .empty;
567
+ defer argv.deinit(allocator);
568
+ try argv.appendSlice(allocator, &.{ "node", script_path, "src/core.ts" });
569
+ if (sdk_core_path) |sdk_core| try argv.appendSlice(allocator, &.{ "--sdk-core", sdk_core });
446
570
  var child = std.process.spawn(io, .{
447
- .argv = &.{ "node", script_path, "src/core.ts" },
571
+ .argv = argv.items,
448
572
  .stdin = .ignore,
449
573
  .stdout = .inherit,
450
574
  .stderr = .inherit,
@@ -465,11 +589,22 @@ pub fn compilerTypecheckCore(allocator: std.mem.Allocator, io: std.Io, base_env:
465
589
 
466
590
  pub const DevHostOptions = struct {
467
591
  base_env: *std.process.Environ.Map,
592
+ app_id: []const u8,
593
+ app_name: []const u8 = "app",
594
+ canvas_label: []const u8 = "canvas",
595
+ window_width: f32 = 800,
596
+ window_height: f32 = 600,
597
+ /// app.zon capabilities installed by the shipping host. The virtual host
598
+ /// receives the same set so capability-shed effects reject identically.
599
+ capabilities: []const []const u8 = &.{},
600
+ permissions: []const []const u8 = &.{},
468
601
  /// NDJSON message script; null = interactive stdin.
469
602
  script: ?[]const u8 = null,
470
603
  /// Re-run the harness whenever any module of the core changes.
471
604
  /// Requires a script (a re-run replays it against the edited core).
472
605
  watch: bool = false,
606
+ persist_routes: ?PersistRoutes = null,
607
+ service_packages: []const ServicePackage = &.{},
473
608
  };
474
609
 
475
610
  /// `native dev --core`: the node dev-harness over src/core.ts — the
@@ -484,10 +619,42 @@ pub fn runDevHost(allocator: std.mem.Allocator, io: std.Io, framework_root: []co
484
619
  defer allocator.free(devhost_path);
485
620
  const runner_path = try tsRunnerPath(allocator, io, framework_root);
486
621
  defer allocator.free(runner_path);
622
+ const app_root = try std.process.currentPathAlloc(io, allocator);
623
+ defer allocator.free(app_root);
624
+ const core_path = try std.fs.path.join(allocator, &.{ app_root, "src/core.ts" });
625
+ defer allocator.free(core_path);
626
+ var script_path: ?[]u8 = null;
627
+ defer if (script_path) |value| allocator.free(value);
628
+ if (options.script) |script| {
629
+ script_path = if (std.fs.path.isAbsolute(script))
630
+ try allocator.dupe(u8, script)
631
+ else
632
+ try std.fs.path.join(allocator, &.{ app_root, script });
633
+ }
634
+ var app_data_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
635
+ const app_data_dir = app_dirs.resolveOne(
636
+ .{ .name = options.app_id },
637
+ app_dirs.currentPlatform(),
638
+ debug.envFromMap(options.base_env),
639
+ .data,
640
+ &app_data_buffer,
641
+ ) catch "";
642
+ if (app_data_dir.len > 0) std.Io.Dir.cwd().createDirPath(io, app_data_dir) catch {};
487
643
  // The harness runs the frontend tier under node, so it needs the
488
644
  // TypeScript toolchain to resolve exactly like check/build do.
489
645
  try ensureResolvedTranspiler(allocator, io, framework_root);
490
646
 
647
+ var sqlite_declarations: ?[]u8 = null;
648
+ defer if (sqlite_declarations) |path_value| allocator.free(path_value);
649
+ var sqlite_source: ?[]u8 = null;
650
+ defer if (sqlite_source) |path_value| allocator.free(path_value);
651
+ for (options.capabilities) |capability| {
652
+ if (!std.mem.eql(u8, capability, "sqlite")) continue;
653
+ sqlite_declarations = try generateSqliteSurface(allocator, io, options.base_env, framework_root, true);
654
+ sqlite_source = try std.Io.Dir.cwd().realPathFileAlloc(io, ".native/cache/sqlite/core.ts", allocator);
655
+ break;
656
+ }
657
+
491
658
  var argv: std.ArrayList([]const u8) = .empty;
492
659
  defer argv.deinit(allocator);
493
660
  try argv.append(allocator, "node");
@@ -500,10 +667,58 @@ pub fn runDevHost(allocator: std.mem.Allocator, io: std.Io, framework_root: []co
500
667
  }
501
668
  try argv.append(allocator, runner_path);
502
669
  try argv.append(allocator, devhost_path);
503
- try argv.append(allocator, "src/core.ts");
504
- if (options.script) |script| {
670
+ try argv.append(allocator, core_path);
671
+ const window_width_arg = try std.fmt.allocPrint(allocator, "{d}", .{options.window_width});
672
+ defer allocator.free(window_width_arg);
673
+ const window_height_arg = try std.fmt.allocPrint(allocator, "{d}", .{options.window_height});
674
+ defer allocator.free(window_height_arg);
675
+ try argv.appendSlice(allocator, &.{
676
+ "--app-name",
677
+ options.app_name,
678
+ "--app-id",
679
+ options.app_id,
680
+ "--canvas-label",
681
+ options.canvas_label,
682
+ "--window-width",
683
+ window_width_arg,
684
+ "--window-height",
685
+ window_height_arg,
686
+ });
687
+ if (script_path) |script| {
505
688
  try argv.appendSlice(allocator, &.{ "--script", script });
506
689
  }
690
+ if (app_data_dir.len > 0) {
691
+ try argv.appendSlice(allocator, &.{ "--service-cwd", app_data_dir });
692
+ }
693
+ for (options.capabilities) |capability| {
694
+ try argv.appendSlice(allocator, &.{ "--capability", capability });
695
+ }
696
+ for (options.permissions) |permission| {
697
+ try argv.appendSlice(allocator, &.{ "--permission", permission });
698
+ }
699
+ if (sqlite_source) |sdk_core| {
700
+ try argv.appendSlice(allocator, &.{ "--sdk-core", sdk_core, "--sqlite-src", "src" });
701
+ }
702
+ if (options.persist_routes) |routes| {
703
+ try argv.appendSlice(allocator, &.{
704
+ "--persist-ok",
705
+ routes.ok,
706
+ "--persist-none",
707
+ routes.none,
708
+ "--persist-err",
709
+ routes.err,
710
+ });
711
+ }
712
+ var service_package_args: std.ArrayList([]u8) = .empty;
713
+ defer {
714
+ for (service_package_args.items) |value| allocator.free(value);
715
+ service_package_args.deinit(allocator);
716
+ }
717
+ for (options.service_packages) |package_entry| {
718
+ const spelling = try std.fmt.allocPrint(allocator, "{s}|{s}|{s}", .{ package_entry.name, package_entry.version, package_entry.content_hash });
719
+ try service_package_args.append(allocator, spelling);
720
+ try argv.appendSlice(allocator, &.{ "--service-package", spelling });
721
+ }
507
722
 
508
723
  std.debug.print("native dev --core: the core-logic loop under node (update/effects, virtual clock) - not a renderer; `native dev` runs the app\n", .{});
509
724
  var child = std.process.spawn(io, .{
@@ -551,6 +766,7 @@ pub const editor_package_dir = "node_modules/@native-sdk/core";
551
766
  /// packages/core/test/package_manifest.test.ts pins the manifest to this
552
767
  /// shape, so copy and tarball cannot drift apart.
553
768
  const editor_package_files = [_][]const u8{ "package.json", "sdk/core.ts", "sdk/text.ts", "sdk/events.ts", "sdk/bytes_text_methods.d.ts" };
769
+ const sqlite_editor_overlay_marker = ".native/cache/sqlite/editor-overlay";
554
770
 
555
771
  /// Extract the top-level "version" of a package.json. A targeted scan, not
556
772
  /// a JSON parse: both inputs are our own manifest and npm's byte-identical
@@ -588,6 +804,8 @@ pub const EditorPackageStatus = struct {
588
804
  /// The app copy's version, or null when the copy is missing or
589
805
  /// incomplete (owned when present).
590
806
  installed: ?[]const u8,
807
+ /// The package's core.ts is the current app-specific relational overlay.
808
+ sqlite_overlay: bool,
591
809
 
592
810
  pub fn fresh(self: EditorPackageStatus) bool {
593
811
  const installed = self.installed orelse return false;
@@ -602,10 +820,13 @@ pub const EditorPackageStatus = struct {
602
820
 
603
821
  /// Compare `<app_root>/node_modules/@native-sdk/core` against the SDK's
604
822
  /// bundled package. Cheap by design (the refresh trigger runs on every
605
- /// check/dev/build): two one-field manifest reads plus two stats.
823
+ /// check/dev/build): small manifest/source reads plus file stats.
606
824
  pub fn editorPackageStatus(allocator: std.mem.Allocator, io: std.Io, framework_root: []const u8, app_root: []const u8) !EditorPackageStatus {
607
825
  const bundled = try bundledSdkVersion(allocator, io, framework_root);
608
826
  errdefer allocator.free(bundled);
827
+ const overlay_path = try std.fs.path.join(allocator, &.{ app_root, sqlite_editor_overlay_marker });
828
+ defer allocator.free(overlay_path);
829
+ const sqlite_overlay = buildgraph.fileExists(io, overlay_path);
609
830
 
610
831
  const installed: ?[]const u8 = read: {
611
832
  const manifest_path = try std.fs.path.join(allocator, &.{ app_root, editor_package_dir, "package.json" });
@@ -622,10 +843,10 @@ pub fn editorPackageStatus(allocator: std.mem.Allocator, io: std.Io, framework_r
622
843
  }
623
844
  break :read try allocator.dupe(u8, version);
624
845
  };
625
- return .{ .bundled = bundled, .installed = installed };
846
+ return .{ .bundled = bundled, .installed = installed, .sqlite_overlay = sqlite_overlay };
626
847
  }
627
848
 
628
- pub const EnsureOutcome = enum { fresh, materialized };
849
+ pub const EnsureOutcome = enum { fresh, materialized, restored_overlay };
629
850
 
630
851
  /// Make `<app_root>/node_modules/@native-sdk/core` a current copy of the
631
852
  /// SDK's bundled package: leave a version-matching copy alone (that is the
@@ -635,7 +856,10 @@ pub const EnsureOutcome = enum { fresh, materialized };
635
856
  pub fn ensureEditorPackage(allocator: std.mem.Allocator, io: std.Io, framework_root: []const u8, app_root: []const u8) !EnsureOutcome {
636
857
  const status = try editorPackageStatus(allocator, io, framework_root, app_root);
637
858
  defer status.deinit(allocator);
638
- if (status.fresh()) return .fresh;
859
+ // Restore an app-specific overlay before deciding whether sqlite still
860
+ // applies. A sqlite verb regenerates it immediately; a non-sqlite verb
861
+ // leaves the ordinary package behind.
862
+ if (status.fresh() and !status.sqlite_overlay) return .fresh;
639
863
 
640
864
  for (editor_package_files) |sub_path| {
641
865
  const source_path = try std.fs.path.join(allocator, &.{ framework_root, "packages", "core", sub_path });
@@ -650,7 +874,30 @@ pub fn ensureEditorPackage(allocator: std.mem.Allocator, io: std.Io, framework_r
650
874
  }
651
875
  try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = dest_path, .data = data });
652
876
  }
653
- return .materialized;
877
+ const overlay_path = try std.fs.path.join(allocator, &.{ app_root, sqlite_editor_overlay_marker });
878
+ defer allocator.free(overlay_path);
879
+ std.Io.Dir.cwd().deleteFile(io, overlay_path) catch {};
880
+ return if (status.sqlite_overlay) .restored_overlay else .materialized;
881
+ }
882
+
883
+ /// Install the app-specific generated relational SDK where stock editor
884
+ /// TypeScript resolves @native-sdk/core. Build truth continues to use the
885
+ /// ignored cache output; this copy is only the editor overlay.
886
+ pub fn materializeSqliteEditorSurface(
887
+ allocator: std.mem.Allocator,
888
+ io: std.Io,
889
+ app_root: []const u8,
890
+ generated_core_path: []const u8,
891
+ ) !void {
892
+ const source = try std.Io.Dir.cwd().readFileAlloc(io, generated_core_path, allocator, .limited(4 * 1024 * 1024));
893
+ defer allocator.free(source);
894
+ const overlay_path = try std.fs.path.join(allocator, &.{ app_root, sqlite_editor_overlay_marker });
895
+ defer allocator.free(overlay_path);
896
+ if (std.fs.path.dirname(overlay_path)) |parent| try std.Io.Dir.cwd().createDirPath(io, parent);
897
+ try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = overlay_path, .data = "generated relational editor surface\n" });
898
+ const destination = try std.fs.path.join(allocator, &.{ app_root, editor_package_dir, "sdk/core.ts" });
899
+ defer allocator.free(destination);
900
+ try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = destination, .data = source });
654
901
  }
655
902
 
656
903
  /// The self-heal hook `native check|dev|build|test` run over a TS app (cwd
@@ -753,6 +1000,25 @@ test "editor package: materialize, heal, and the npm-install handoff" {
753
1000
  try std.testing.expect(buildgraph.fileExists(io, app ++ "/node_modules/@native-sdk/core/sdk/events.ts"));
754
1001
  try std.testing.expect(buildgraph.fileExists(io, app ++ "/node_modules/@native-sdk/core/sdk/bytes_text_methods.d.ts"));
755
1002
 
1003
+ // A generated relational surface overlays the editor-resolved core and
1004
+ // deliberately makes the package stale. The next verb restores the base
1005
+ // first, so removing sqlite from app.zon cannot leave q<Name> APIs behind.
1006
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/generated-core.ts", .data = "// app-specific qNotes surface" });
1007
+ try materializeSqliteEditorSurface(allocator, io, app, root ++ "/generated-core.ts");
1008
+ const generated = try cwd.readFileAlloc(io, app ++ "/node_modules/@native-sdk/core/sdk/core.ts", allocator, .limited(1024));
1009
+ defer allocator.free(generated);
1010
+ try std.testing.expectEqualStrings("// app-specific qNotes surface", generated);
1011
+ {
1012
+ const overlaid = try editorPackageStatus(allocator, io, sdk, app);
1013
+ defer overlaid.deinit(allocator);
1014
+ try std.testing.expect(overlaid.fresh());
1015
+ try std.testing.expect(overlaid.sqlite_overlay);
1016
+ }
1017
+ try std.testing.expectEqual(EnsureOutcome.restored_overlay, try ensureEditorPackage(allocator, io, sdk, app));
1018
+ const restored = try cwd.readFileAlloc(io, app ++ "/node_modules/@native-sdk/core/sdk/core.ts", allocator, .limited(1024));
1019
+ defer allocator.free(restored);
1020
+ try std.testing.expectEqualStrings("// core module", restored);
1021
+
756
1022
  // Current copy: untouched (this is also the post-publish handoff — a
757
1023
  // real `npm install` writes identical content at the same version, so
758
1024
  // user-owned node_modules stop being rewritten). Prove "untouched"
@@ -57,6 +57,9 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
57
57
  const core_tree = ts_core.detect(io);
58
58
  if (core_tree == .both) return ts_core.failBothCores();
59
59
  if (core_tree == .ts) {
60
+ const sqlite_enabled = for (metadata.capabilities) |capability| {
61
+ if (std.mem.eql(u8, capability, "sqlite")) break true;
62
+ } else false;
60
63
  // Keep the app's editor surface fresh (node_modules/@native-sdk/core,
61
64
  // the pre-publish copy stock tsc resolves): best-effort by design —
62
65
  // build truth never depends on it, so an unresolvable framework here
@@ -69,6 +72,10 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
69
72
  // for graphs the CLI itself generates (see the preflight's own
70
73
  // doc for why ejected apps must flow past it).
71
74
  try tsToolchainPreflight(allocator, io, ".", framework_root);
75
+ if (sqlite_enabled) {
76
+ const sqlite_declarations = try ts_core.generateSqliteSurface(allocator, io, options.base_env, framework_root, true);
77
+ allocator.free(sqlite_declarations);
78
+ }
72
79
  }
73
80
  }
74
81
 
@@ -0,0 +1,13 @@
1
+ # SQLite amalgamation
2
+
3
+ This directory vendors the SQLite 3.53.4 amalgamation (`sqlite3.c` and
4
+ `sqlite3.h`) downloaded from the official SQLite distribution:
5
+
6
+ - archive: `sqlite-amalgamation-3530400.zip`
7
+ - archive SHA3-256: `628a44cfe82c66aed1ccbbe85a562d2e33ebe64b3288981ed76285612227934e`
8
+ - `sqlite3.c` SHA3-256: `67f423e9ebbbdc473cbc4772c872ee6b89f31fde4ed0279a5c25d5f65c043a16`
9
+
10
+ SQLite is in the public domain. See <https://sqlite.org/copyright.html>.
11
+
12
+ Only apps declaring the `store` or `sqlite` capability compile this source
13
+ into their artifact.