@native-sdk/cli 0.8.4 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/build/app.zig +1178 -74
  2. package/build.zig +715 -17
  3. package/build.zig.zon +1 -0
  4. package/native-sdk.d.ts +10 -0
  5. package/package.json +12 -11
  6. package/packages/core/compile-surface/core.ts +435 -3
  7. package/packages/core/package-lock.json +11 -11
  8. package/packages/core/package.json +2 -2
  9. package/packages/core/scripts/compiler_typecheck.mjs +116 -15
  10. package/packages/core/scripts/gen_service_surface.mjs +268 -0
  11. package/packages/core/scripts/merge_static_archives.mjs +78 -0
  12. package/packages/core/scripts/npm_static_spike.mjs +64 -0
  13. package/packages/core/scripts/run_external_core_compiler.mjs +122 -6
  14. package/packages/core/scripts/run_external_service_compiler.mjs +280 -0
  15. package/packages/core/scripts/stage_external_core.mjs +9 -1
  16. package/packages/core/scripts/stage_external_services.mjs +172 -0
  17. package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
  18. package/packages/core/scripts/vendor_service_packages.mjs +189 -0
  19. package/packages/core/sdk/core.d.ts +224 -0
  20. package/packages/core/sdk/core.ts +694 -22
  21. package/packages/core/sdk/events.d.ts +89 -0
  22. package/packages/core/sdk/events.ts +128 -0
  23. package/packages/core/src/checker.ts +936 -15
  24. package/packages/core/src/cli.ts +156 -3
  25. package/packages/core/src/contract.ts +28 -5
  26. package/packages/core/src/devhost.ts +1876 -16
  27. package/packages/core/src/devhost_journal.mjs +183 -0
  28. package/packages/core/src/devhost_resolver.mjs +17 -1
  29. package/packages/core/src/devhost_service_worker.mjs +90 -0
  30. package/packages/core/src/diagnostics.ts +179 -22
  31. package/packages/core/src/frontend.ts +210 -34
  32. package/packages/core/src/infer.ts +24 -0
  33. package/packages/core/src/modules.ts +129 -80
  34. package/packages/core/src/service_contract.ts +597 -0
  35. package/packages/core/src/sqlite_cli.ts +93 -0
  36. package/packages/core/src/sqlite_codegen.ts +806 -0
  37. package/packages/core/src/sqlite_runtime_policy.ts +364 -0
  38. package/packages/core/src/typed_ast.ts +36 -8
  39. package/skill-data/automation/SKILL.md +1 -1
  40. package/skill-data/core/references/project-anatomy.md +1 -1
  41. package/skill-data/native-ui/SKILL.md +58 -5
  42. package/skill-data/ts-core/SKILL.md +123 -41
  43. package/skill-data/ts-services/SKILL.md +126 -0
  44. package/skill-data/ts-services/references/service-surface.md +604 -0
  45. package/skill-data/zig/SKILL.md +1 -1
  46. package/skills/native-sdk/SKILL.md +1 -1
  47. package/src/app_runner/no_migrations.zig +3 -0
  48. package/src/app_runner/no_services.zig +20 -0
  49. package/src/app_runner/root.zig +133 -4
  50. package/src/app_runner/ts_core_main.zig +254 -8
  51. package/src/app_runner/ts_core_mobile.zig +241 -0
  52. package/src/automation/protocol.zig +5 -1
  53. package/src/automation/snapshot.zig +31 -11
  54. package/src/embed/app_exports.zig +12 -1
  55. package/src/embed/c_api.zig +48 -2
  56. package/src/embed/conversions.zig +4 -5
  57. package/src/embed/host.zig +109 -1
  58. package/src/embed/root.zig +8 -0
  59. package/src/embed/tests.zig +241 -0
  60. package/src/embed/types.zig +51 -0
  61. package/src/embed/ui_host.zig +185 -5
  62. package/src/platform/android/NativeSdkActivity.java +131 -0
  63. package/src/platform/android/android_host.c +182 -1
  64. package/src/platform/android/native_sdk_app.h +17 -0
  65. package/src/platform/ios/native_sdk_app.h +17 -0
  66. package/src/platform/ios/uikit_host.m +115 -0
  67. package/src/platform/linux/cef_host.cpp +8 -2
  68. package/src/platform/linux/gtk_host.c +289 -22
  69. package/src/platform/linux/gtk_host.h +5 -1
  70. package/src/platform/linux/root.zig +109 -22
  71. package/src/platform/macos/appkit_host.h +24 -7
  72. package/src/platform/macos/appkit_host.m +686 -64
  73. package/src/platform/macos/cef_host.mm +400 -66
  74. package/src/platform/macos/root.zig +304 -47
  75. package/src/platform/null_platform.zig +435 -48
  76. package/src/platform/null_platform_tests.zig +113 -0
  77. package/src/platform/root.zig +19 -0
  78. package/src/platform/types.zig +281 -28
  79. package/src/platform/windows/root.zig +207 -27
  80. package/src/platform/windows/webview2_host.cpp +334 -51
  81. package/src/primitives/app_manifest/comptime_scene.zig +2 -0
  82. package/src/primitives/app_manifest/root.zig +4 -0
  83. package/src/primitives/app_manifest/tests.zig +3 -0
  84. package/src/primitives/app_manifest/types.zig +32 -0
  85. package/src/primitives/app_manifest/validation.zig +19 -1
  86. package/src/root.zig +53 -0
  87. package/src/runtime/api.zig +19 -0
  88. package/src/runtime/automation_commands.zig +35 -2
  89. package/src/runtime/automation_snapshot.zig +32 -20
  90. package/src/runtime/bridge_permission_tests.zig +58 -3
  91. package/src/runtime/bridge_responses.zig +4 -2
  92. package/src/runtime/builtin_bridge.zig +11 -1
  93. package/src/runtime/canvas_frame.zig +18 -11
  94. package/src/runtime/canvas_frame_animation_tests.zig +4 -0
  95. package/src/runtime/clock.zig +13 -1
  96. package/src/runtime/core.zig +145 -7
  97. package/src/runtime/credentials_store.zig +115 -0
  98. package/src/runtime/effects.zig +3701 -231
  99. package/src/runtime/effects_credentials_tests.zig +332 -0
  100. package/src/runtime/effects_file_tests.zig +587 -0
  101. package/src/runtime/effects_host_tests.zig +208 -1
  102. package/src/runtime/effects_notification_tests.zig +11 -0
  103. package/src/runtime/effects_relational_tests.zig +314 -0
  104. package/src/runtime/effects_store_tests.zig +211 -0
  105. package/src/runtime/file_access.zig +400 -0
  106. package/src/runtime/file_effect_crash_helper.zig +28 -0
  107. package/src/runtime/file_effect_crash_tests.zig +37 -0
  108. package/src/runtime/flow.zig +35 -10
  109. package/src/runtime/gpu_surface_events.zig +6 -1
  110. package/src/runtime/native_command_event_tests.zig +86 -2
  111. package/src/runtime/persist_store.zig +666 -0
  112. package/src/runtime/pty.zig +5 -2
  113. package/src/runtime/record_store.zig +788 -0
  114. package/src/runtime/relational_store.zig +854 -0
  115. package/src/runtime/root.zig +54 -0
  116. package/src/runtime/runtime_event_tests.zig +70 -0
  117. package/src/runtime/service_host.zig +711 -0
  118. package/src/runtime/service_pool.zig +1314 -0
  119. package/src/runtime/session_blobs.zig +4 -1
  120. package/src/runtime/session_journal.zig +158 -5
  121. package/src/runtime/session_record.zig +215 -0
  122. package/src/runtime/session_replay.zig +206 -11
  123. package/src/runtime/session_tests.zig +81 -0
  124. package/src/runtime/shell_layout.zig +1 -0
  125. package/src/runtime/shell_layout_tests.zig +120 -0
  126. package/src/runtime/sqlite_engine.zig +474 -0
  127. package/src/runtime/state.zig +16 -0
  128. package/src/runtime/system_services.zig +170 -38
  129. package/src/runtime/tests.zig +4 -0
  130. package/src/runtime/ts_core_host.zig +1067 -95
  131. package/src/runtime/ts_core_host_tests.zig +325 -11
  132. package/src/runtime/ts_ui_app.zig +953 -2
  133. package/src/runtime/ui_app.zig +434 -96
  134. package/src/runtime/ui_app_tests.zig +287 -11
  135. package/src/runtime/ui_app_window_tests.zig +61 -7
  136. package/src/runtime/validation.zig +42 -0
  137. package/src/runtime/view.zig +9 -0
  138. package/src/runtime/window_storage.zig +1 -0
  139. package/src/runtime/window_view_runtime.zig +2 -3
  140. package/src/runtime/window_views.zig +19 -0
  141. package/src/tooling/android.zig +21 -16
  142. package/src/tooling/db.zig +160 -0
  143. package/src/tooling/ios.zig +7 -1
  144. package/src/tooling/manifest.zig +214 -2
  145. package/src/tooling/package.zig +116 -0
  146. package/src/tooling/raw_manifest.zig +30 -0
  147. package/src/tooling/root.zig +1 -0
  148. package/src/tooling/templates.zig +189 -4
  149. package/src/tooling/ts_core.zig +366 -17
  150. package/src/tooling/verbs.zig +7 -0
  151. package/third_party/sqlite/README.md +13 -0
  152. package/third_party/sqlite/sqlite3.c +269649 -0
  153. package/third_party/sqlite/sqlite3.h +14349 -0
  154. package/tools/corewire/core_abi.zig +14 -2
  155. package/tools/corewire/emit.zig +98 -29
  156. package/tools/corewire/emit_facade.zig +442 -27
  157. package/tools/corewire/emit_profile.zig +6 -2
  158. package/tools/corewire/emit_service.zig +924 -0
  159. package/tools/corewire/main.zig +122 -0
  160. package/tools/corewire/service_contract.zig +250 -0
  161. package/tools/corewire/sidecar.zig +26 -15
@@ -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{
@@ -24,6 +27,7 @@ pub const Error = error{
24
27
  MissingTranspiler,
25
28
  BrokenToolchainInstall,
26
29
  ToolchainVersionMismatch,
30
+ InvalidWindowViewLabel,
27
31
  CoreCheckFailed,
28
32
  DevHostFailed,
29
33
  };
@@ -403,21 +407,183 @@ pub fn ensureResolvedTranspiler(allocator: std.mem.Allocator, io: std.Io, framew
403
407
  return transpilerDepsMissing(resolved);
404
408
  }
405
409
 
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 {
410
+ pub const PersistRoutes = struct {
411
+ ok: []const u8,
412
+ none: []const u8,
413
+ err: []const u8,
414
+ };
415
+
416
+ /// Direct `src/windows/<label>.native` roots, sorted by label. Nested files
417
+ /// are import components, never independently addressable windows.
418
+ pub fn collectWindowViewLabels(allocator: std.mem.Allocator, io: std.Io, app_root: []const u8) ![][]const u8 {
419
+ const windows_path = try std.fs.path.join(allocator, &.{ app_root, "src", "windows" });
420
+ defer allocator.free(windows_path);
421
+ var cwd = std.Io.Dir.cwd();
422
+ var dir = cwd.openDir(io, windows_path, .{ .iterate = true }) catch return try allocator.alloc([]const u8, 0);
423
+ defer dir.close(io);
424
+ var labels: std.ArrayList([]const u8) = .empty;
425
+ errdefer {
426
+ for (labels.items) |label| allocator.free(label);
427
+ labels.deinit(allocator);
428
+ }
429
+ var it = dir.iterate();
430
+ while (try it.next(io)) |entry| {
431
+ if (entry.kind != .file or !std.mem.endsWith(u8, entry.name, ".native")) continue;
432
+ const label = entry.name[0 .. entry.name.len - ".native".len];
433
+ if (label.len == 0 or label.len > 64 or std.mem.eql(u8, label, ".") or std.mem.eql(u8, label, "..")) {
434
+ std.debug.print("invalid TypeScript secondary-window view filename '{s}': use src/windows/<label>.native with a non-empty label of at most 64 bytes\n", .{entry.name});
435
+ return error.InvalidWindowViewLabel;
436
+ }
437
+ for (label) |ch| {
438
+ if (ch == 0 or ch == '/' or ch == '\\') {
439
+ std.debug.print("invalid TypeScript secondary-window view filename '{s}': the filename stem must be a valid window label\n", .{entry.name});
440
+ return error.InvalidWindowViewLabel;
441
+ }
442
+ }
443
+ try labels.append(allocator, try allocator.dupe(u8, label));
444
+ }
445
+ std.mem.sort([]const u8, labels.items, {}, struct {
446
+ fn lessThan(_: void, a: []const u8, b: []const u8) bool {
447
+ return std.mem.order(u8, a, b) == .lt;
448
+ }
449
+ }.lessThan);
450
+ return try labels.toOwnedSlice(allocator);
451
+ }
452
+
453
+ pub fn freeWindowViewLabels(allocator: std.mem.Allocator, labels: [][]const u8) void {
454
+ for (labels) |label| allocator.free(label);
455
+ allocator.free(labels);
456
+ }
457
+
458
+ /// Run the real-SQLite schema/query lane used by the build and return the
459
+ /// generated SDK core path that exposes this app's Cmd.q/Sub.q surface.
460
+ /// Generated outputs live under ignored .native/cache. The append-only
461
+ /// migration authority lives beside the authored migrations so it is visible
462
+ /// to version control and survives a clean checkout.
463
+ pub fn generateSqliteSurface(
464
+ allocator: std.mem.Allocator,
465
+ io: std.Io,
466
+ base_env: *std.process.Environ.Map,
467
+ framework_root: []const u8,
468
+ install_editor_surface: bool,
469
+ ) ![]u8 {
470
+ const sqlite_cli = try transpilerPath(allocator, io, framework_root, "src/sqlite_cli.ts");
471
+ defer allocator.free(sqlite_cli);
472
+ const runner = try tsRunnerPath(allocator, io, framework_root);
473
+ defer allocator.free(runner);
474
+ const sdk_in = try transpilerPath(allocator, io, framework_root, "sdk/core.ts");
475
+ defer allocator.free(sdk_in);
476
+ const static_in = try transpilerPath(allocator, io, framework_root, "compile-surface/core.ts");
477
+ defer allocator.free(static_in);
478
+ try std.Io.Dir.cwd().createDirPath(io, ".native/cache/sqlite");
479
+ const sdk_out = try allocator.dupe(u8, ".native/cache/sqlite/core.ts");
480
+ errdefer allocator.free(sdk_out);
481
+ var child = std.process.spawn(io, .{
482
+ .argv = &.{
483
+ "node", runner, sqlite_cli,
484
+ "--src", "src", "--sdk-in",
485
+ sdk_in, "--static-in", static_in,
486
+ "--sdk-out", sdk_out, "--dts-out",
487
+ ".native/cache/sqlite/core.d.ts", "--static-out", ".native/cache/sqlite/core_static.ts",
488
+ "--zig-out", ".native/cache/sqlite/migrations.zig", "--metadata-out",
489
+ ".native/cache/sqlite/metadata.json", "--state", "src/schema/migrations.lock.json",
490
+ },
491
+ .stdin = .ignore,
492
+ .stdout = .inherit,
493
+ .stderr = .inherit,
494
+ .environ_map = base_env,
495
+ }) catch return nodeMissing();
496
+ const term = try child.wait(io);
497
+ switch (term) {
498
+ .exited => |code| if (code == 0) {
499
+ if (install_editor_surface) {
500
+ materializeSqliteEditorSurface(allocator, io, ".", sdk_out) catch {};
501
+ }
502
+ const absolute = try std.Io.Dir.cwd().realPathFileAlloc(io, ".native/cache/sqlite/core.d.ts", allocator);
503
+ allocator.free(sdk_out);
504
+ return absolute;
505
+ },
506
+ else => {},
507
+ }
508
+ std.debug.print("native check: the relational schema or declared queries failed (diagnostics above)\n", .{});
509
+ return error.SqliteCheckFailed;
510
+ }
511
+
512
+ pub const ServicePackage = struct {
513
+ name: []const u8,
514
+ version: []const u8,
515
+ content_hash: []const u8,
516
+ };
517
+
518
+ /// Run the TypeScript frontend in check-only mode on src/core.ts — and,
519
+ /// through it, the core's whole import graph under src/ — and surface its NS
520
+ /// diagnostics verbatim. Manifest-owned routes ride into the same typed Msg
521
+ /// contract the watched dev host invokes on each of its own restarts.
522
+ pub fn checkCore(
523
+ allocator: std.mem.Allocator,
524
+ io: std.Io,
525
+ base_env: *std.process.Environ.Map,
526
+ framework_root: []const u8,
527
+ capabilities: []const []const u8,
528
+ permissions: []const []const u8,
529
+ service_packages: []const ServicePackage,
530
+ persist_version: ?u64,
531
+ persist_routes: ?PersistRoutes,
532
+ sdk_core_path: ?[]const u8,
533
+ window_views: []const []const u8,
534
+ ) !void {
413
535
  const cli_path = try transpilerPath(allocator, io, framework_root, "src/cli.ts");
414
536
  defer allocator.free(cli_path);
415
537
  const runner_path = try tsRunnerPath(allocator, io, framework_root);
416
538
  defer allocator.free(runner_path);
417
539
  try ensureResolvedTranspiler(allocator, io, framework_root);
418
540
 
541
+ var argv: std.ArrayList([]const u8) = .empty;
542
+ defer argv.deinit(allocator);
543
+ var persist_version_arg: ?[]u8 = null;
544
+ defer if (persist_version_arg) |value| allocator.free(value);
545
+ try argv.appendSlice(allocator, &.{ "node", runner_path, cli_path, "src/core.ts" });
546
+ for (capabilities) |capability| try argv.appendSlice(allocator, &.{ "--capability", capability });
547
+ for (permissions) |permission| try argv.appendSlice(allocator, &.{ "--permission", permission });
548
+ var service_package_args: std.ArrayList([]u8) = .empty;
549
+ defer {
550
+ for (service_package_args.items) |value| allocator.free(value);
551
+ service_package_args.deinit(allocator);
552
+ }
553
+ for (service_packages) |package_entry| {
554
+ const spelling = try std.fmt.allocPrint(allocator, "{s}|{s}|{s}", .{ package_entry.name, package_entry.version, package_entry.content_hash });
555
+ try service_package_args.append(allocator, spelling);
556
+ try argv.appendSlice(allocator, &.{ "--service-package", spelling });
557
+ }
558
+ if (try package_tool.projectHasTypeScriptServices(allocator, io, ".")) {
559
+ try argv.appendSlice(allocator, &.{ "--services-editor-client", "node_modules/@native-sdk/services/index.ts" });
560
+ } else {
561
+ std.Io.Dir.cwd().deleteTree(io, "node_modules/@native-sdk/services") catch {};
562
+ }
563
+ if (persist_version) |version| {
564
+ persist_version_arg = try std.fmt.allocPrint(allocator, "{d}", .{version});
565
+ try argv.appendSlice(allocator, &.{
566
+ "--persist-version",
567
+ persist_version_arg.?,
568
+ "--persist-state",
569
+ ".native/cache/persist-schema.json",
570
+ });
571
+ }
572
+ if (persist_routes) |routes| {
573
+ try argv.appendSlice(allocator, &.{
574
+ "--persist-ok",
575
+ routes.ok,
576
+ "--persist-none",
577
+ routes.none,
578
+ "--persist-err",
579
+ routes.err,
580
+ });
581
+ }
582
+ if (sdk_core_path) |sdk_core| try argv.appendSlice(allocator, &.{ "--sdk-core", sdk_core });
583
+ try argv.append(allocator, "--window-views");
584
+ for (window_views) |label| try argv.appendSlice(allocator, &.{ "--window-view", label });
419
585
  var child = std.process.spawn(io, .{
420
- .argv = &.{ "node", runner_path, cli_path, "src/core.ts" },
586
+ .argv = argv.items,
421
587
  .stdin = .ignore,
422
588
  .stdout = .inherit,
423
589
  .stderr = .inherit,
@@ -440,11 +606,15 @@ pub fn checkCore(allocator: std.mem.Allocator, io: std.Io, base_env: *std.proces
440
606
  /// build verdict come from ONE compiler. Analyzer type errors fail the
441
607
  /// check with the compiler's own diagnostics; a toolchain that cannot
442
608
  /// 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 {
609
+ 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
610
  const script_path = try transpilerPath(allocator, io, framework_root, "scripts/compiler_typecheck.mjs");
445
611
  defer allocator.free(script_path);
612
+ var argv: std.ArrayList([]const u8) = .empty;
613
+ defer argv.deinit(allocator);
614
+ try argv.appendSlice(allocator, &.{ "node", script_path, "src/core.ts" });
615
+ if (sdk_core_path) |sdk_core| try argv.appendSlice(allocator, &.{ "--sdk-core", sdk_core });
446
616
  var child = std.process.spawn(io, .{
447
- .argv = &.{ "node", script_path, "src/core.ts" },
617
+ .argv = argv.items,
448
618
  .stdin = .ignore,
449
619
  .stdout = .inherit,
450
620
  .stderr = .inherit,
@@ -465,11 +635,23 @@ pub fn compilerTypecheckCore(allocator: std.mem.Allocator, io: std.Io, base_env:
465
635
 
466
636
  pub const DevHostOptions = struct {
467
637
  base_env: *std.process.Environ.Map,
638
+ app_id: []const u8,
639
+ app_name: []const u8 = "app",
640
+ canvas_label: []const u8 = "canvas",
641
+ window_width: f32 = 800,
642
+ window_height: f32 = 600,
643
+ /// app.zon capabilities installed by the shipping host. The virtual host
644
+ /// receives the same set so capability-shed effects reject identically.
645
+ capabilities: []const []const u8 = &.{},
646
+ permissions: []const []const u8 = &.{},
468
647
  /// NDJSON message script; null = interactive stdin.
469
648
  script: ?[]const u8 = null,
470
649
  /// Re-run the harness whenever any module of the core changes.
471
650
  /// Requires a script (a re-run replays it against the edited core).
472
651
  watch: bool = false,
652
+ persist_routes: ?PersistRoutes = null,
653
+ service_packages: []const ServicePackage = &.{},
654
+ window_views: []const []const u8 = &.{},
473
655
  };
474
656
 
475
657
  /// `native dev --core`: the node dev-harness over src/core.ts — the
@@ -484,10 +666,42 @@ pub fn runDevHost(allocator: std.mem.Allocator, io: std.Io, framework_root: []co
484
666
  defer allocator.free(devhost_path);
485
667
  const runner_path = try tsRunnerPath(allocator, io, framework_root);
486
668
  defer allocator.free(runner_path);
669
+ const app_root = try std.process.currentPathAlloc(io, allocator);
670
+ defer allocator.free(app_root);
671
+ const core_path = try std.fs.path.join(allocator, &.{ app_root, "src/core.ts" });
672
+ defer allocator.free(core_path);
673
+ var script_path: ?[]u8 = null;
674
+ defer if (script_path) |value| allocator.free(value);
675
+ if (options.script) |script| {
676
+ script_path = if (std.fs.path.isAbsolute(script))
677
+ try allocator.dupe(u8, script)
678
+ else
679
+ try std.fs.path.join(allocator, &.{ app_root, script });
680
+ }
681
+ var app_data_buffer: [std.Io.Dir.max_path_bytes]u8 = undefined;
682
+ const app_data_dir = app_dirs.resolveOne(
683
+ .{ .name = options.app_id },
684
+ app_dirs.currentPlatform(),
685
+ debug.envFromMap(options.base_env),
686
+ .data,
687
+ &app_data_buffer,
688
+ ) catch "";
689
+ if (app_data_dir.len > 0) std.Io.Dir.cwd().createDirPath(io, app_data_dir) catch {};
487
690
  // The harness runs the frontend tier under node, so it needs the
488
691
  // TypeScript toolchain to resolve exactly like check/build do.
489
692
  try ensureResolvedTranspiler(allocator, io, framework_root);
490
693
 
694
+ var sqlite_declarations: ?[]u8 = null;
695
+ defer if (sqlite_declarations) |path_value| allocator.free(path_value);
696
+ var sqlite_source: ?[]u8 = null;
697
+ defer if (sqlite_source) |path_value| allocator.free(path_value);
698
+ for (options.capabilities) |capability| {
699
+ if (!std.mem.eql(u8, capability, "sqlite")) continue;
700
+ sqlite_declarations = try generateSqliteSurface(allocator, io, options.base_env, framework_root, true);
701
+ sqlite_source = try std.Io.Dir.cwd().realPathFileAlloc(io, ".native/cache/sqlite/core.ts", allocator);
702
+ break;
703
+ }
704
+
491
705
  var argv: std.ArrayList([]const u8) = .empty;
492
706
  defer argv.deinit(allocator);
493
707
  try argv.append(allocator, "node");
@@ -500,10 +714,60 @@ pub fn runDevHost(allocator: std.mem.Allocator, io: std.Io, framework_root: []co
500
714
  }
501
715
  try argv.append(allocator, runner_path);
502
716
  try argv.append(allocator, devhost_path);
503
- try argv.append(allocator, "src/core.ts");
504
- if (options.script) |script| {
717
+ try argv.append(allocator, core_path);
718
+ const window_width_arg = try std.fmt.allocPrint(allocator, "{d}", .{options.window_width});
719
+ defer allocator.free(window_width_arg);
720
+ const window_height_arg = try std.fmt.allocPrint(allocator, "{d}", .{options.window_height});
721
+ defer allocator.free(window_height_arg);
722
+ try argv.appendSlice(allocator, &.{
723
+ "--app-name",
724
+ options.app_name,
725
+ "--app-id",
726
+ options.app_id,
727
+ "--canvas-label",
728
+ options.canvas_label,
729
+ "--window-width",
730
+ window_width_arg,
731
+ "--window-height",
732
+ window_height_arg,
733
+ });
734
+ if (script_path) |script| {
505
735
  try argv.appendSlice(allocator, &.{ "--script", script });
506
736
  }
737
+ if (app_data_dir.len > 0) {
738
+ try argv.appendSlice(allocator, &.{ "--service-cwd", app_data_dir });
739
+ }
740
+ for (options.capabilities) |capability| {
741
+ try argv.appendSlice(allocator, &.{ "--capability", capability });
742
+ }
743
+ for (options.permissions) |permission| {
744
+ try argv.appendSlice(allocator, &.{ "--permission", permission });
745
+ }
746
+ try argv.append(allocator, "--window-views");
747
+ for (options.window_views) |label| try argv.appendSlice(allocator, &.{ "--window-view", label });
748
+ if (sqlite_source) |sdk_core| {
749
+ try argv.appendSlice(allocator, &.{ "--sdk-core", sdk_core, "--sqlite-src", "src" });
750
+ }
751
+ if (options.persist_routes) |routes| {
752
+ try argv.appendSlice(allocator, &.{
753
+ "--persist-ok",
754
+ routes.ok,
755
+ "--persist-none",
756
+ routes.none,
757
+ "--persist-err",
758
+ routes.err,
759
+ });
760
+ }
761
+ var service_package_args: std.ArrayList([]u8) = .empty;
762
+ defer {
763
+ for (service_package_args.items) |value| allocator.free(value);
764
+ service_package_args.deinit(allocator);
765
+ }
766
+ for (options.service_packages) |package_entry| {
767
+ const spelling = try std.fmt.allocPrint(allocator, "{s}|{s}|{s}", .{ package_entry.name, package_entry.version, package_entry.content_hash });
768
+ try service_package_args.append(allocator, spelling);
769
+ try argv.appendSlice(allocator, &.{ "--service-package", spelling });
770
+ }
507
771
 
508
772
  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
773
  var child = std.process.spawn(io, .{
@@ -551,6 +815,7 @@ pub const editor_package_dir = "node_modules/@native-sdk/core";
551
815
  /// packages/core/test/package_manifest.test.ts pins the manifest to this
552
816
  /// shape, so copy and tarball cannot drift apart.
553
817
  const editor_package_files = [_][]const u8{ "package.json", "sdk/core.ts", "sdk/text.ts", "sdk/events.ts", "sdk/bytes_text_methods.d.ts" };
818
+ const sqlite_editor_overlay_marker = ".native/cache/sqlite/editor-overlay";
554
819
 
555
820
  /// Extract the top-level "version" of a package.json. A targeted scan, not
556
821
  /// a JSON parse: both inputs are our own manifest and npm's byte-identical
@@ -588,6 +853,8 @@ pub const EditorPackageStatus = struct {
588
853
  /// The app copy's version, or null when the copy is missing or
589
854
  /// incomplete (owned when present).
590
855
  installed: ?[]const u8,
856
+ /// The package's core.ts is the current app-specific relational overlay.
857
+ sqlite_overlay: bool,
591
858
 
592
859
  pub fn fresh(self: EditorPackageStatus) bool {
593
860
  const installed = self.installed orelse return false;
@@ -602,10 +869,13 @@ pub const EditorPackageStatus = struct {
602
869
 
603
870
  /// Compare `<app_root>/node_modules/@native-sdk/core` against the SDK's
604
871
  /// bundled package. Cheap by design (the refresh trigger runs on every
605
- /// check/dev/build): two one-field manifest reads plus two stats.
872
+ /// check/dev/build): small manifest/source reads plus file stats.
606
873
  pub fn editorPackageStatus(allocator: std.mem.Allocator, io: std.Io, framework_root: []const u8, app_root: []const u8) !EditorPackageStatus {
607
874
  const bundled = try bundledSdkVersion(allocator, io, framework_root);
608
875
  errdefer allocator.free(bundled);
876
+ const overlay_path = try std.fs.path.join(allocator, &.{ app_root, sqlite_editor_overlay_marker });
877
+ defer allocator.free(overlay_path);
878
+ const sqlite_overlay = buildgraph.fileExists(io, overlay_path);
609
879
 
610
880
  const installed: ?[]const u8 = read: {
611
881
  const manifest_path = try std.fs.path.join(allocator, &.{ app_root, editor_package_dir, "package.json" });
@@ -622,10 +892,10 @@ pub fn editorPackageStatus(allocator: std.mem.Allocator, io: std.Io, framework_r
622
892
  }
623
893
  break :read try allocator.dupe(u8, version);
624
894
  };
625
- return .{ .bundled = bundled, .installed = installed };
895
+ return .{ .bundled = bundled, .installed = installed, .sqlite_overlay = sqlite_overlay };
626
896
  }
627
897
 
628
- pub const EnsureOutcome = enum { fresh, materialized };
898
+ pub const EnsureOutcome = enum { fresh, materialized, restored_overlay };
629
899
 
630
900
  /// Make `<app_root>/node_modules/@native-sdk/core` a current copy of the
631
901
  /// SDK's bundled package: leave a version-matching copy alone (that is the
@@ -635,7 +905,10 @@ pub const EnsureOutcome = enum { fresh, materialized };
635
905
  pub fn ensureEditorPackage(allocator: std.mem.Allocator, io: std.Io, framework_root: []const u8, app_root: []const u8) !EnsureOutcome {
636
906
  const status = try editorPackageStatus(allocator, io, framework_root, app_root);
637
907
  defer status.deinit(allocator);
638
- if (status.fresh()) return .fresh;
908
+ // Restore an app-specific overlay before deciding whether sqlite still
909
+ // applies. A sqlite verb regenerates it immediately; a non-sqlite verb
910
+ // leaves the ordinary package behind.
911
+ if (status.fresh() and !status.sqlite_overlay) return .fresh;
639
912
 
640
913
  for (editor_package_files) |sub_path| {
641
914
  const source_path = try std.fs.path.join(allocator, &.{ framework_root, "packages", "core", sub_path });
@@ -650,7 +923,30 @@ pub fn ensureEditorPackage(allocator: std.mem.Allocator, io: std.Io, framework_r
650
923
  }
651
924
  try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = dest_path, .data = data });
652
925
  }
653
- return .materialized;
926
+ const overlay_path = try std.fs.path.join(allocator, &.{ app_root, sqlite_editor_overlay_marker });
927
+ defer allocator.free(overlay_path);
928
+ std.Io.Dir.cwd().deleteFile(io, overlay_path) catch {};
929
+ return if (status.sqlite_overlay) .restored_overlay else .materialized;
930
+ }
931
+
932
+ /// Install the app-specific generated relational SDK where stock editor
933
+ /// TypeScript resolves @native-sdk/core. Build truth continues to use the
934
+ /// ignored cache output; this copy is only the editor overlay.
935
+ pub fn materializeSqliteEditorSurface(
936
+ allocator: std.mem.Allocator,
937
+ io: std.Io,
938
+ app_root: []const u8,
939
+ generated_core_path: []const u8,
940
+ ) !void {
941
+ const source = try std.Io.Dir.cwd().readFileAlloc(io, generated_core_path, allocator, .limited(4 * 1024 * 1024));
942
+ defer allocator.free(source);
943
+ const overlay_path = try std.fs.path.join(allocator, &.{ app_root, sqlite_editor_overlay_marker });
944
+ defer allocator.free(overlay_path);
945
+ if (std.fs.path.dirname(overlay_path)) |parent| try std.Io.Dir.cwd().createDirPath(io, parent);
946
+ try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = overlay_path, .data = "generated relational editor surface\n" });
947
+ const destination = try std.fs.path.join(allocator, &.{ app_root, editor_package_dir, "sdk/core.ts" });
948
+ defer allocator.free(destination);
949
+ try std.Io.Dir.cwd().writeFile(io, .{ .sub_path = destination, .data = source });
654
950
  }
655
951
 
656
952
  /// The self-heal hook `native check|dev|build|test` run over a TS app (cwd
@@ -707,6 +1003,40 @@ test "a stray package.json is not a language marker: detection keys on the core
707
1003
  try std.testing.expectEqual(CoreTree.ts, detectAt(io, root));
708
1004
  }
709
1005
 
1006
+ test "window view discovery includes only direct native roots and sorts labels" {
1007
+ const io = std.testing.io;
1008
+ var cwd = std.Io.Dir.cwd();
1009
+ const root = ".zig-cache/test-ts-window-view-labels";
1010
+ cwd.deleteTree(io, root) catch {};
1011
+ defer cwd.deleteTree(io, root) catch {};
1012
+ try cwd.createDirPath(io, root ++ "/src/windows/components");
1013
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/src/windows/settings.native", .data = "<column/>" });
1014
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/src/windows/about.native", .data = "<column/>" });
1015
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/src/windows/ignored.txt", .data = "" });
1016
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/src/windows/components/shared.native", .data = "<template name=\"shared\"/>" });
1017
+
1018
+ const labels = try collectWindowViewLabels(std.testing.allocator, io, root);
1019
+ defer freeWindowViewLabels(std.testing.allocator, labels);
1020
+ try std.testing.expectEqual(@as(usize, 2), labels.len);
1021
+ try std.testing.expectEqualStrings("about", labels[0]);
1022
+ try std.testing.expectEqualStrings("settings", labels[1]);
1023
+ }
1024
+
1025
+ test "window view discovery rejects labels beyond the platform budget" {
1026
+ const io = std.testing.io;
1027
+ var cwd = std.Io.Dir.cwd();
1028
+ const root = ".zig-cache/test-ts-window-view-label-budget";
1029
+ cwd.deleteTree(io, root) catch {};
1030
+ defer cwd.deleteTree(io, root) catch {};
1031
+ try cwd.createDirPath(io, root ++ "/src/windows");
1032
+ try cwd.writeFile(io, .{
1033
+ .sub_path = root ++ "/src/windows/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.native",
1034
+ .data = "<column/>",
1035
+ });
1036
+
1037
+ try std.testing.expectError(error.InvalidWindowViewLabel, collectWindowViewLabels(std.testing.allocator, io, root));
1038
+ }
1039
+
710
1040
  test "package.json version extraction" {
711
1041
  try std.testing.expectEqualStrings("0.0.1", parsePackageVersion(
712
1042
  \\{
@@ -753,6 +1083,25 @@ test "editor package: materialize, heal, and the npm-install handoff" {
753
1083
  try std.testing.expect(buildgraph.fileExists(io, app ++ "/node_modules/@native-sdk/core/sdk/events.ts"));
754
1084
  try std.testing.expect(buildgraph.fileExists(io, app ++ "/node_modules/@native-sdk/core/sdk/bytes_text_methods.d.ts"));
755
1085
 
1086
+ // A generated relational surface overlays the editor-resolved core and
1087
+ // deliberately makes the package stale. The next verb restores the base
1088
+ // first, so removing sqlite from app.zon cannot leave q<Name> APIs behind.
1089
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/generated-core.ts", .data = "// app-specific qNotes surface" });
1090
+ try materializeSqliteEditorSurface(allocator, io, app, root ++ "/generated-core.ts");
1091
+ const generated = try cwd.readFileAlloc(io, app ++ "/node_modules/@native-sdk/core/sdk/core.ts", allocator, .limited(1024));
1092
+ defer allocator.free(generated);
1093
+ try std.testing.expectEqualStrings("// app-specific qNotes surface", generated);
1094
+ {
1095
+ const overlaid = try editorPackageStatus(allocator, io, sdk, app);
1096
+ defer overlaid.deinit(allocator);
1097
+ try std.testing.expect(overlaid.fresh());
1098
+ try std.testing.expect(overlaid.sqlite_overlay);
1099
+ }
1100
+ try std.testing.expectEqual(EnsureOutcome.restored_overlay, try ensureEditorPackage(allocator, io, sdk, app));
1101
+ const restored = try cwd.readFileAlloc(io, app ++ "/node_modules/@native-sdk/core/sdk/core.ts", allocator, .limited(1024));
1102
+ defer allocator.free(restored);
1103
+ try std.testing.expectEqualStrings("// core module", restored);
1104
+
756
1105
  // Current copy: untouched (this is also the post-publish handoff — a
757
1106
  // real `npm install` writes identical content at the same version, so
758
1107
  // 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.