@native-sdk/cli 0.8.4 → 0.9.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/build/app.zig +1178 -74
  2. package/build.zig +715 -17
  3. package/build.zig.zon +1 -0
  4. package/native-sdk.d.ts +10 -0
  5. package/package.json +12 -11
  6. package/packages/core/compile-surface/core.ts +435 -3
  7. package/packages/core/package-lock.json +11 -11
  8. package/packages/core/package.json +2 -2
  9. package/packages/core/scripts/compiler_typecheck.mjs +116 -15
  10. package/packages/core/scripts/gen_service_surface.mjs +268 -0
  11. package/packages/core/scripts/merge_static_archives.mjs +78 -0
  12. package/packages/core/scripts/npm_static_spike.mjs +64 -0
  13. package/packages/core/scripts/run_external_core_compiler.mjs +122 -6
  14. package/packages/core/scripts/run_external_service_compiler.mjs +280 -0
  15. package/packages/core/scripts/stage_external_core.mjs +9 -1
  16. package/packages/core/scripts/stage_external_services.mjs +172 -0
  17. package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
  18. package/packages/core/scripts/vendor_service_packages.mjs +189 -0
  19. package/packages/core/sdk/core.d.ts +224 -0
  20. package/packages/core/sdk/core.ts +694 -22
  21. package/packages/core/sdk/events.d.ts +89 -0
  22. package/packages/core/sdk/events.ts +128 -0
  23. package/packages/core/src/checker.ts +936 -15
  24. package/packages/core/src/cli.ts +156 -3
  25. package/packages/core/src/contract.ts +28 -5
  26. package/packages/core/src/devhost.ts +1876 -16
  27. package/packages/core/src/devhost_journal.mjs +183 -0
  28. package/packages/core/src/devhost_resolver.mjs +17 -1
  29. package/packages/core/src/devhost_service_worker.mjs +90 -0
  30. package/packages/core/src/diagnostics.ts +179 -22
  31. package/packages/core/src/frontend.ts +210 -34
  32. package/packages/core/src/infer.ts +24 -0
  33. package/packages/core/src/modules.ts +129 -80
  34. package/packages/core/src/service_contract.ts +597 -0
  35. package/packages/core/src/sqlite_cli.ts +93 -0
  36. package/packages/core/src/sqlite_codegen.ts +806 -0
  37. package/packages/core/src/sqlite_runtime_policy.ts +364 -0
  38. package/packages/core/src/typed_ast.ts +36 -8
  39. package/skill-data/automation/SKILL.md +1 -1
  40. package/skill-data/core/references/project-anatomy.md +1 -1
  41. package/skill-data/native-ui/SKILL.md +58 -5
  42. package/skill-data/ts-core/SKILL.md +123 -41
  43. package/skill-data/ts-services/SKILL.md +126 -0
  44. package/skill-data/ts-services/references/service-surface.md +604 -0
  45. package/skill-data/zig/SKILL.md +1 -1
  46. package/skills/native-sdk/SKILL.md +1 -1
  47. package/src/app_runner/no_migrations.zig +3 -0
  48. package/src/app_runner/no_services.zig +20 -0
  49. package/src/app_runner/root.zig +133 -4
  50. package/src/app_runner/ts_core_main.zig +254 -8
  51. package/src/app_runner/ts_core_mobile.zig +241 -0
  52. package/src/automation/protocol.zig +5 -1
  53. package/src/automation/snapshot.zig +31 -11
  54. package/src/embed/app_exports.zig +12 -1
  55. package/src/embed/c_api.zig +48 -2
  56. package/src/embed/conversions.zig +4 -5
  57. package/src/embed/host.zig +109 -1
  58. package/src/embed/root.zig +8 -0
  59. package/src/embed/tests.zig +241 -0
  60. package/src/embed/types.zig +51 -0
  61. package/src/embed/ui_host.zig +185 -5
  62. package/src/platform/android/NativeSdkActivity.java +131 -0
  63. package/src/platform/android/android_host.c +182 -1
  64. package/src/platform/android/native_sdk_app.h +17 -0
  65. package/src/platform/ios/native_sdk_app.h +17 -0
  66. package/src/platform/ios/uikit_host.m +115 -0
  67. package/src/platform/linux/cef_host.cpp +8 -2
  68. package/src/platform/linux/gtk_host.c +289 -22
  69. package/src/platform/linux/gtk_host.h +5 -1
  70. package/src/platform/linux/root.zig +109 -22
  71. package/src/platform/macos/appkit_host.h +24 -7
  72. package/src/platform/macos/appkit_host.m +686 -64
  73. package/src/platform/macos/cef_host.mm +400 -66
  74. package/src/platform/macos/root.zig +304 -47
  75. package/src/platform/null_platform.zig +435 -48
  76. package/src/platform/null_platform_tests.zig +113 -0
  77. package/src/platform/root.zig +19 -0
  78. package/src/platform/types.zig +281 -28
  79. package/src/platform/windows/root.zig +207 -27
  80. package/src/platform/windows/webview2_host.cpp +334 -51
  81. package/src/primitives/app_manifest/comptime_scene.zig +2 -0
  82. package/src/primitives/app_manifest/root.zig +4 -0
  83. package/src/primitives/app_manifest/tests.zig +3 -0
  84. package/src/primitives/app_manifest/types.zig +32 -0
  85. package/src/primitives/app_manifest/validation.zig +19 -1
  86. package/src/root.zig +53 -0
  87. package/src/runtime/api.zig +19 -0
  88. package/src/runtime/automation_commands.zig +35 -2
  89. package/src/runtime/automation_snapshot.zig +32 -20
  90. package/src/runtime/bridge_permission_tests.zig +58 -3
  91. package/src/runtime/bridge_responses.zig +4 -2
  92. package/src/runtime/builtin_bridge.zig +11 -1
  93. package/src/runtime/canvas_frame.zig +18 -11
  94. package/src/runtime/canvas_frame_animation_tests.zig +4 -0
  95. package/src/runtime/clock.zig +13 -1
  96. package/src/runtime/core.zig +145 -7
  97. package/src/runtime/credentials_store.zig +115 -0
  98. package/src/runtime/effects.zig +3701 -231
  99. package/src/runtime/effects_credentials_tests.zig +332 -0
  100. package/src/runtime/effects_file_tests.zig +587 -0
  101. package/src/runtime/effects_host_tests.zig +208 -1
  102. package/src/runtime/effects_notification_tests.zig +11 -0
  103. package/src/runtime/effects_relational_tests.zig +314 -0
  104. package/src/runtime/effects_store_tests.zig +211 -0
  105. package/src/runtime/file_access.zig +400 -0
  106. package/src/runtime/file_effect_crash_helper.zig +28 -0
  107. package/src/runtime/file_effect_crash_tests.zig +37 -0
  108. package/src/runtime/flow.zig +35 -10
  109. package/src/runtime/gpu_surface_events.zig +6 -1
  110. package/src/runtime/native_command_event_tests.zig +86 -2
  111. package/src/runtime/persist_store.zig +666 -0
  112. package/src/runtime/pty.zig +5 -2
  113. package/src/runtime/record_store.zig +788 -0
  114. package/src/runtime/relational_store.zig +854 -0
  115. package/src/runtime/root.zig +54 -0
  116. package/src/runtime/runtime_event_tests.zig +70 -0
  117. package/src/runtime/service_host.zig +711 -0
  118. package/src/runtime/service_pool.zig +1314 -0
  119. package/src/runtime/session_blobs.zig +4 -1
  120. package/src/runtime/session_journal.zig +158 -5
  121. package/src/runtime/session_record.zig +215 -0
  122. package/src/runtime/session_replay.zig +206 -11
  123. package/src/runtime/session_tests.zig +81 -0
  124. package/src/runtime/shell_layout.zig +1 -0
  125. package/src/runtime/shell_layout_tests.zig +120 -0
  126. package/src/runtime/sqlite_engine.zig +474 -0
  127. package/src/runtime/state.zig +16 -0
  128. package/src/runtime/system_services.zig +170 -38
  129. package/src/runtime/tests.zig +4 -0
  130. package/src/runtime/ts_core_host.zig +1067 -95
  131. package/src/runtime/ts_core_host_tests.zig +325 -11
  132. package/src/runtime/ts_ui_app.zig +953 -2
  133. package/src/runtime/ui_app.zig +434 -96
  134. package/src/runtime/ui_app_tests.zig +287 -11
  135. package/src/runtime/ui_app_window_tests.zig +61 -7
  136. package/src/runtime/validation.zig +42 -0
  137. package/src/runtime/view.zig +9 -0
  138. package/src/runtime/window_storage.zig +1 -0
  139. package/src/runtime/window_view_runtime.zig +2 -3
  140. package/src/runtime/window_views.zig +19 -0
  141. package/src/tooling/android.zig +21 -16
  142. package/src/tooling/db.zig +160 -0
  143. package/src/tooling/ios.zig +7 -1
  144. package/src/tooling/manifest.zig +214 -2
  145. package/src/tooling/package.zig +116 -0
  146. package/src/tooling/raw_manifest.zig +30 -0
  147. package/src/tooling/root.zig +1 -0
  148. package/src/tooling/templates.zig +189 -4
  149. package/src/tooling/ts_core.zig +366 -17
  150. package/src/tooling/verbs.zig +7 -0
  151. package/third_party/sqlite/README.md +13 -0
  152. package/third_party/sqlite/sqlite3.c +269649 -0
  153. package/third_party/sqlite/sqlite3.h +14349 -0
  154. package/tools/corewire/core_abi.zig +14 -2
  155. package/tools/corewire/emit.zig +98 -29
  156. package/tools/corewire/emit_facade.zig +442 -27
  157. package/tools/corewire/emit_profile.zig +6 -2
  158. package/tools/corewire/emit_service.zig +924 -0
  159. package/tools/corewire/main.zig +122 -0
  160. package/tools/corewire/service_contract.zig +250 -0
  161. package/tools/corewire/sidecar.zig +26 -15
package/build.zig CHANGED
@@ -43,6 +43,60 @@ pub const MobileLibOptions = @import("build/app.zig").MobileLibOptions;
43
43
  pub const addMobileLib = @import("build/app.zig").addMobileLib;
44
44
  const mobile_export_symbol_names = @import("build/app.zig").mobile_export_symbol_names;
45
45
 
46
+ test "service archive support matches ScriptC localized object formats" {
47
+ const app_build = @import("build/app.zig");
48
+ const host = @import("builtin").target;
49
+ const resolved = struct {
50
+ fn target(os: std.Target.Os.Tag, arch: std.Target.Cpu.Arch, abi: std.Target.Abi) std.Build.ResolvedTarget {
51
+ var result = host;
52
+ result.os.tag = os;
53
+ result.cpu.arch = arch;
54
+ result.abi = abi;
55
+ return .{
56
+ .query = .{ .os_tag = os, .cpu_arch = arch, .abi = abi },
57
+ .result = result,
58
+ };
59
+ }
60
+ }.target;
61
+
62
+ var macos_host = host;
63
+ macos_host.os.tag = .macos;
64
+ macos_host.cpu.arch = .aarch64;
65
+ macos_host.abi = .none;
66
+ try std.testing.expect(app_build.serviceArchiveSupported(macos_host, resolved(.windows, .x86_64, .gnu)));
67
+ try std.testing.expect(!app_build.serviceArchiveSupported(macos_host, resolved(.windows, .x86_64, .msvc)));
68
+ try std.testing.expect(!app_build.serviceArchiveSupported(macos_host, resolved(.windows, .aarch64, .gnu)));
69
+ try std.testing.expect(app_build.serviceArchiveSupported(macos_host, resolved(.linux, .x86_64, .musl)));
70
+ try std.testing.expect(app_build.serviceArchiveSupported(macos_host, resolved(.linux, .aarch64, .musl)));
71
+ try std.testing.expect(!app_build.serviceArchiveSupported(macos_host, resolved(.linux, .riscv64, .musl)));
72
+ try std.testing.expect(app_build.serviceArchiveSupported(macos_host, resolved(.macos, .x86_64, .none)));
73
+
74
+ var linux_host = host;
75
+ linux_host.os.tag = .linux;
76
+ linux_host.cpu.arch = .riscv64;
77
+ linux_host.abi = .musl;
78
+ try std.testing.expect(app_build.serviceArchiveSupported(linux_host, .{ .query = .{}, .result = linux_host }));
79
+ try std.testing.expect(!app_build.serviceArchiveSupported(linux_host, resolved(.macos, .aarch64, .none)));
80
+
81
+ var gnu_linux_host = host;
82
+ gnu_linux_host.os.tag = .linux;
83
+ gnu_linux_host.cpu.arch = .x86_64;
84
+ gnu_linux_host.abi = .gnu;
85
+ const explicit_same_triple_gnu = resolved(.linux, .x86_64, .gnu);
86
+ try std.testing.expect(!app_build.scriptcTargetIsCross(gnu_linux_host, explicit_same_triple_gnu));
87
+ try std.testing.expect(app_build.linuxGlibcSpellingHitsDefaultFloor(explicit_same_triple_gnu));
88
+ try std.testing.expect(!app_build.linuxGlibcSpellingHitsDefaultFloor(.{ .query = .{}, .result = gnu_linux_host }));
89
+
90
+ var windows_host = host;
91
+ windows_host.os.tag = .windows;
92
+ windows_host.cpu.arch = .x86_64;
93
+ windows_host.abi = .gnu;
94
+ const native_windows_msvc = resolved(.windows, .x86_64, .msvc);
95
+ try std.testing.expect(!app_build.scriptcTargetIsCross(windows_host, native_windows_msvc));
96
+ try std.testing.expect(app_build.scriptcCompileSupported(windows_host, native_windows_msvc));
97
+ try std.testing.expect(app_build.serviceArchiveSupported(windows_host, native_windows_msvc));
98
+ }
99
+
46
100
  pub fn build(b: *std.Build) void {
47
101
  const target = b.standardTargetOptions(.{});
48
102
  const host_target = b.graph.host;
@@ -141,8 +195,58 @@ pub fn build(b: *std.Build) void {
141
195
  desktop_mod.addImport("json", json_mod);
142
196
  desktop_mod.addImport("canvas", canvas_mod);
143
197
  desktop_mod.addImport("terminal_vt", terminalVtModule(b, target, optimize));
198
+ desktop_mod.addIncludePath(b.path("third_party/sqlite"));
199
+ desktop_mod.addCSourceFile(.{
200
+ .file = b.path("third_party/sqlite/sqlite3.c"),
201
+ // Mobile -Dtargets (the mobile e2e battery) compile the
202
+ // amalgamation against the platform SDK/NDK sysroot; desktop
203
+ // targets keep Zig's ordinary libc discovery.
204
+ .flags = if (target.result.os.tag == .ios or target.result.abi.isAndroid())
205
+ @import("build/app.zig").sqliteCFlags(b, target)
206
+ else
207
+ sqliteCompileFlags(),
208
+ });
209
+ desktop_mod.link_libc = true;
144
210
  const desktop_tests = testArtifact(b, desktop_mod);
145
211
  const desktop_test_shards = desktopTestShardArtifacts(b, desktop_mod);
212
+ // Tier-5 crash battery: a child uses the public streamed sink, signals
213
+ // after a chunk is durable only in the atomic temporary, then the parent
214
+ // kills it and verifies the destination still names the old generation.
215
+ const file_crash_helper_mod = module(b, target, optimize, "src/runtime/file_effect_crash_helper.zig");
216
+ file_crash_helper_mod.addImport("native_sdk", desktop_mod);
217
+ const file_crash_helper = b.addExecutable(.{ .name = "file-effect-crash-helper", .root_module = file_crash_helper_mod });
218
+ const file_crash_tests_mod = module(b, target, optimize, "src/runtime/file_effect_crash_tests.zig");
219
+ file_crash_tests_mod.addImport("native_sdk", desktop_mod);
220
+ const file_crash_options = b.addOptions();
221
+ file_crash_options.addOptionPath("helper_executable", file_crash_helper.getEmittedBin());
222
+ file_crash_tests_mod.addOptions("file_crash_options", file_crash_options);
223
+ const file_crash_tests = testArtifact(b, file_crash_tests_mod);
224
+ const file_crash_run = b.addRunArtifact(file_crash_tests);
225
+ const file_crash_step = b.step("test-file-effect-crash", "Kill a streamed writer before close and verify atomic destination visibility");
226
+ file_crash_step.dependOn(&file_crash_run.step);
227
+ const tier5_tests = filteredTestArtifact(b, desktop_mod, "storage-tier-5-tests", &.{
228
+ "runtime.effects_file_tests.test",
229
+ "runtime.file_access.test",
230
+ "runtime.session_record.test.recorder moves streamed file chunks",
231
+ "runtime.session_tests.test.a multi-megabyte file stream",
232
+ });
233
+ const tier5_run = b.addRunArtifact(tier5_tests);
234
+ const tier5_step = b.step("test-storage-tier-5", "Run file streaming, bounds, replay/blob, gating, and crash-atomicity batteries");
235
+ tier5_step.dependOn(&tier5_run.step);
236
+ tier5_step.dependOn(&file_crash_run.step);
237
+
238
+ // SQLite is capability-shed from ordinary app artifacts. Its focused
239
+ // engine/store suite gets a dedicated module that explicitly compiles the
240
+ // vendored amalgamation, so framework tests cover it without making every
241
+ // unrelated example carry the database object.
242
+ const record_store_mod = module(b, target, optimize, "src/runtime/record_store.zig");
243
+ record_store_mod.addIncludePath(b.path("third_party/sqlite"));
244
+ record_store_mod.addCSourceFile(.{
245
+ .file = b.path("third_party/sqlite/sqlite3.c"),
246
+ .flags = sqliteCompileFlags(),
247
+ });
248
+ record_store_mod.link_libc = true;
249
+ const record_store_tests = testArtifact(b, record_store_mod);
146
250
 
147
251
  // The embeddable static library's root module carries only the C ABI
148
252
  // exports (fixed WebView shell host); user-app canvas libraries are
@@ -188,6 +292,13 @@ pub fn build(b: *std.Build) void {
188
292
  tooling_mod.addImport("app_icon", app_icon_mod);
189
293
  tooling_mod.addImport("ios_host", ios_host_mod);
190
294
  tooling_mod.addImport("android_host", android_host_mod);
295
+ tooling_mod.addImport("sqlite_engine", module(b, target, optimize, "src/runtime/sqlite_engine.zig"));
296
+ tooling_mod.addIncludePath(b.path("third_party/sqlite"));
297
+ tooling_mod.addCSourceFile(.{
298
+ .file = b.path("third_party/sqlite/sqlite3.c"),
299
+ .flags = sqliteCompileFlags(),
300
+ });
301
+ tooling_mod.link_libc = true;
191
302
  const tooling_tests = testArtifact(b, tooling_mod);
192
303
 
193
304
  // Ejected-component identity proofs: a separate test module because
@@ -209,6 +320,8 @@ pub fn build(b: *std.Build) void {
209
320
  const corewire_emit_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/emit.zig"));
210
321
  const corewire_facade_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/emit_facade.zig"));
211
322
  const corewire_profile_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/emit_profile.zig"));
323
+ const corewire_service_contract_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/service_contract.zig"));
324
+ const corewire_service_emit_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/emit_service.zig"));
212
325
  const corewire_shim_rt_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/shim_rt.zig"));
213
326
 
214
327
  // TypeScript-core end-to-end suite: each fixture core is compiled
@@ -245,6 +358,7 @@ pub fn build(b: *std.Build) void {
245
358
  // where the failure reads as the graded app's, not the tooling's.
246
359
  const evals_cmdview_mod = module(b, target, optimize, "evals/harness-lib/cmdview.zig");
247
360
  const evals_cmdview_tests = testArtifact(b, evals_cmdview_mod);
361
+ const build_graph_tests = testArtifact(b, module(b, host_target, optimize, "build.zig"));
248
362
 
249
363
  // `native version` names the commit the binary was built from, so
250
364
  // binary/framework skew ("your native binary may be stale") is a
@@ -298,6 +412,13 @@ pub fn build(b: *std.Build) void {
298
412
  host_tooling_mod.addImport("app_icon", host_app_icon_mod);
299
413
  host_tooling_mod.addImport("ios_host", host_ios_host_mod);
300
414
  host_tooling_mod.addImport("android_host", host_android_host_mod);
415
+ host_tooling_mod.addImport("sqlite_engine", module(b, host_target, optimize, "src/runtime/sqlite_engine.zig"));
416
+ host_tooling_mod.addIncludePath(b.path("third_party/sqlite"));
417
+ host_tooling_mod.addCSourceFile(.{
418
+ .file = b.path("third_party/sqlite/sqlite3.c"),
419
+ .flags = sqliteCompileFlags(),
420
+ });
421
+ host_tooling_mod.link_libc = true;
301
422
  const host_ui_markup_mod = module(b, host_target, optimize, "src/primitives/canvas/ui_markup.zig");
302
423
  const host_markup_lsp_mod = module(b, host_target, optimize, "tools/native-sdk/markup_lsp.zig");
303
424
  host_markup_lsp_mod.addImport("ui_markup", host_ui_markup_mod);
@@ -462,6 +583,7 @@ pub fn build(b: *std.Build) void {
462
583
  };
463
584
 
464
585
  const test_step = b.step("test", "Run package and framework tests");
586
+ test_step.dependOn(&b.addRunArtifact(build_graph_tests).step);
465
587
  test_step.dependOn(&b.addRunArtifact(geometry_tests).step);
466
588
  test_step.dependOn(&b.addRunArtifact(assets_tests).step);
467
589
  test_step.dependOn(&b.addRunArtifact(app_dirs_tests).step);
@@ -472,6 +594,8 @@ pub fn build(b: *std.Build) void {
472
594
  test_step.dependOn(&b.addRunArtifact(json_tests).step);
473
595
  test_step.dependOn(&b.addRunArtifact(app_runner_assets_tests).step);
474
596
  test_step.dependOn(&b.addRunArtifact(canvas_tests).step);
597
+ test_step.dependOn(&b.addRunArtifact(record_store_tests).step);
598
+ test_step.dependOn(&file_crash_run.step);
475
599
  for (desktop_test_shards) |shard_tests| {
476
600
  test_step.dependOn(&b.addRunArtifact(shard_tests).step);
477
601
  }
@@ -482,10 +606,14 @@ pub fn build(b: *std.Build) void {
482
606
  test_step.dependOn(&b.addRunArtifact(corewire_emit_tests).step);
483
607
  test_step.dependOn(&b.addRunArtifact(corewire_facade_tests).step);
484
608
  test_step.dependOn(&b.addRunArtifact(corewire_profile_tests).step);
609
+ test_step.dependOn(&b.addRunArtifact(corewire_service_contract_tests).step);
610
+ test_step.dependOn(&b.addRunArtifact(corewire_service_emit_tests).step);
485
611
  test_step.dependOn(&b.addRunArtifact(corewire_shim_rt_tests).step);
612
+ const ts_services_e2e_step = b.step("test-ts-services-e2e", "Run both TypeScript service carriers end to end: the out-of-process child (crash recovery, timeout, replay) and the in-process pool (parallel keys, FIFO, trap isolation, replay)");
486
613
  if (ts_core_e2e_tests) |ts_core_artifacts| {
487
614
  const ts_core_e2e_step = b.step("test-ts-core-e2e", "Run the TypeScript-core end-to-end suites over externally compiled fixture cores (requires node and `npm ci` in packages/core)");
488
615
  const host_e2e_run = b.addRunArtifact(ts_core_artifacts.host);
616
+ const persist_e2e_run = b.addRunArtifact(ts_core_artifacts.persist);
489
617
  const markup_e2e_run = b.addRunArtifact(ts_core_artifacts.markup);
490
618
  const kanban_e2e_run = b.addRunArtifact(ts_core_artifacts.kanban);
491
619
  const soundboard_e2e_run = b.addRunArtifact(ts_core_artifacts.soundboard);
@@ -495,16 +623,65 @@ pub fn build(b: *std.Build) void {
495
623
  // no build inputs/outputs to hash, so always run it.
496
624
  scaffold_ide_e2e_run.has_side_effects = true;
497
625
  const ai_chat_e2e_run = b.addRunArtifact(ts_core_artifacts.ai_chat);
626
+ const feed_reader_e2e_run = b.addRunArtifact(ts_core_artifacts.feed_reader);
627
+ const services_e2e_run = b.addRunArtifact(ts_core_artifacts.services);
628
+ ts_services_e2e_step.dependOn(&feed_reader_e2e_run.step);
629
+ ts_services_e2e_step.dependOn(&services_e2e_run.step);
630
+ // The same fixture through the in-process carrier (ServicePool over
631
+ // the linked service archive): parallel keys, per-key FIFO,
632
+ // cooperative cancellation/deadlines, trap isolation, streaming,
633
+ // and replay without initializing the archive.
634
+ const services_pool_e2e_run: ?*std.Build.Step.Run = if (ts_core_artifacts.services_pool) |pool_tests| pool: {
635
+ const run = b.addRunArtifact(pool_tests);
636
+ ts_services_e2e_step.dependOn(&run.step);
637
+ break :pool run;
638
+ } else null;
639
+ // Service carrier benchmark: cold start, warm round-trip latency
640
+ // for small and large payloads, and queued throughput, through the
641
+ // production carrier bindings of BOTH carriers — the out-of-process
642
+ // child and the in-process pool — against one bytes-echo service
643
+ // (see tools/bench_service_host.zig).
644
+ const bench_service_host_run = b.addRunArtifact(ts_core_artifacts.service_host_bench);
645
+ bench_service_host_run.has_side_effects = true;
646
+ // Repo root as cwd so the generated service executable path and the
647
+ // benchmark's scratch directory resolve regardless of where
648
+ // `zig build` ran from.
649
+ bench_service_host_run.setCwd(b.path("."));
650
+ const bench_service_host_step = b.step("bench-service-host", "Run the service carrier benchmark over both carriers (cold start, round-trip latency, queued throughput; requires node and `npm ci` in packages/core; pass -Doptimize=ReleaseFast for baselines)");
651
+ bench_service_host_step.dependOn(&bench_service_host_run.step);
498
652
  const sidecar_conformance_run = b.addRunArtifact(ts_core_artifacts.sidecar_conformance);
499
653
  const sidecar_conformance_step = b.step("sidecar-conformance", "Validate corewire-generated mirrors over every fixture's frontend-emitted contract (requires node)");
500
654
  sidecar_conformance_step.dependOn(&sidecar_conformance_run.step);
501
- // ABI-law suite over a real compiled core: the markup fixture's
502
- // archive driven directly through the C ABI (collect invariant,
503
- // deterministic re-init, channel envelopes, integer classes).
655
+ // ABI-law suites over real compiled cores: the broad markup fixture
656
+ // plus the focused mixed bare-Model/[Model, Cmd] return regression.
504
657
  const abi_laws_run = b.addRunArtifact(ts_core_artifacts.external_core_abi_laws);
505
- const abi_laws_step = b.step("test-external-core-abi", "Run the compiled-core ABI-law suite over the markup fixture's archive (requires node and `npm ci` in packages/core)");
658
+ const mixed_return_abi_run = b.addRunArtifact(ts_core_artifacts.mixed_return_abi_laws);
659
+ const abi_laws_step = b.step("test-external-core-abi", "Run the compiled-core ABI-law suites, including mixed update returns (requires node and `npm ci` in packages/core)");
506
660
  abi_laws_step.dependOn(&abi_laws_run.step);
661
+ abi_laws_step.dependOn(&mixed_return_abi_run.step);
507
662
  test_step.dependOn(&abi_laws_run.step);
663
+ test_step.dependOn(&mixed_return_abi_run.step);
664
+ // The cross-execution battery staging: the host-fixture and
665
+ // markup batteries (update/snapshot/effects and the markup view
666
+ // over genuinely compiled cores) plus, where the target admits
667
+ // the in-process archive, the service pool battery, installed
668
+ // under <prefix>/e2e for execution on the target machine. Pair
669
+ // with -Dtarget and -p; scripts/cross-e2e.sh is the driver.
670
+ const cross_e2e_step = b.step("stage-cross-e2e", "Install the TS-core e2e batteries under <prefix>/e2e for execution on the build target (pair with -Dtarget and -p; see scripts/cross-e2e.sh)");
671
+ const e2e_dir: std.Build.Step.InstallArtifact.Options.Dir = .{ .override = .{ .custom = "e2e" } };
672
+ cross_e2e_step.dependOn(&b.addInstallArtifact(ts_core_artifacts.host, .{ .dest_dir = e2e_dir }).step);
673
+ cross_e2e_step.dependOn(&b.addInstallArtifact(ts_core_artifacts.markup, .{ .dest_dir = e2e_dir }).step);
674
+ if (ts_core_artifacts.services_pool) |pool_tests| {
675
+ cross_e2e_step.dependOn(&b.addInstallArtifact(pool_tests, .{ .dest_dir = e2e_dir }).step);
676
+ }
677
+ // The mobile execution battery staging: one static library the
678
+ // platform toolchain (xcrun clang / NDK clang) links around a tiny
679
+ // harness for execution on the simulator or emulator. Registered
680
+ // only for a mobile -Dtarget; scripts/mobile-e2e.sh is the driver.
681
+ if (ts_core_artifacts.mobile_battery) |battery| {
682
+ const mobile_e2e_step = b.step("stage-mobile-e2e", "Install the TS mobile e2e battery archive under <prefix>/e2e (pair with -Dtarget=aarch64-ios-simulator or aarch64-linux-android and -p; see scripts/mobile-e2e.sh)");
683
+ mobile_e2e_step.dependOn(&b.addInstallFileWithDir(battery, .{ .custom = "e2e" }, "libts-mobile-e2e.a").step);
684
+ }
508
685
  // The corpus contract artifacts an external core toolchain
509
686
  // consumes: per fixture, the frontend-emitted contract sidecar
510
687
  // (after projection), the generated entry module, and the
@@ -517,19 +694,27 @@ pub fn build(b: *std.Build) void {
517
694
  contracts_step.dependOn(&b.addInstallFileWithDir(contract.profile, dir, "core_profile.json").step);
518
695
  }
519
696
  ts_core_e2e_step.dependOn(&host_e2e_run.step);
697
+ ts_core_e2e_step.dependOn(&persist_e2e_run.step);
520
698
  ts_core_e2e_step.dependOn(&markup_e2e_run.step);
521
699
  ts_core_e2e_step.dependOn(&kanban_e2e_run.step);
522
700
  ts_core_e2e_step.dependOn(&soundboard_e2e_run.step);
523
701
  ts_core_e2e_step.dependOn(&monitor_e2e_run.step);
524
702
  ts_core_e2e_step.dependOn(&scaffold_ide_e2e_run.step);
525
703
  ts_core_e2e_step.dependOn(&ai_chat_e2e_run.step);
704
+ ts_core_e2e_step.dependOn(&feed_reader_e2e_run.step);
705
+ ts_core_e2e_step.dependOn(&services_e2e_run.step);
706
+ if (services_pool_e2e_run) |run| ts_core_e2e_step.dependOn(&run.step);
526
707
  test_step.dependOn(&host_e2e_run.step);
708
+ test_step.dependOn(&persist_e2e_run.step);
527
709
  test_step.dependOn(&markup_e2e_run.step);
528
710
  test_step.dependOn(&kanban_e2e_run.step);
529
711
  test_step.dependOn(&soundboard_e2e_run.step);
530
712
  test_step.dependOn(&monitor_e2e_run.step);
531
713
  test_step.dependOn(&scaffold_ide_e2e_run.step);
532
714
  test_step.dependOn(&ai_chat_e2e_run.step);
715
+ test_step.dependOn(&feed_reader_e2e_run.step);
716
+ test_step.dependOn(&services_e2e_run.step);
717
+ if (services_pool_e2e_run) |run| test_step.dependOn(&run.step);
533
718
  test_step.dependOn(&sidecar_conformance_run.step);
534
719
  }
535
720
  test_step.dependOn(&b.addRunArtifact(markup_lsp_tests).step);
@@ -604,6 +789,34 @@ pub fn build(b: *std.Build) void {
604
789
  .{ .path = "build/app.zig", .pattern = "npm ci --include=dev" },
605
790
  .{ .path = "build/app.zig", .pattern = "cannot resolve its TypeScript toolchain" },
606
791
  .{ .path = "build/app.zig", .pattern = "std.process.exit(1);" },
792
+ // SQLite schema generation shares node/toolchain resolution but
793
+ // never the TS-core-only src/app.native shape assertion: Zig cores
794
+ // may own their view in code while still embedding migrations.
795
+ .{ .path = "build/app.zig", .pattern = "return tsToolingPreflight(b, dep, .app_core);" },
796
+ .{ .path = "build/app.zig", .pattern = "const node = tsToolingPreflight(b, dep, .sqlite_schema);" },
797
+ });
798
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-scriptc-pin-cache-inputs", "Verify both TypeScript service build graphs invalidate frontend contracts when the exact scriptc pin changes", &.{
799
+ .{ .path = "build.zig", .pattern = "if (spec.emit_services) check.addFileInput(b.path(\"packages/core/package.json\"));" },
800
+ .{ .path = "build/app.zig", .pattern = "if (has_services) check.addFileInput(dep.path(\"packages/core/package.json\"));" },
801
+ });
802
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-scriptc-cross-target-plumbing", "Verify core and service archives share the target-aware ScriptC lane, and every direct Windows archive consumer links its runtime import libraries", &.{
803
+ .{ .path = "build/app.zig", .pattern = ".linux => !cross or target.result.cpu.arch == .x86_64 or target.result.cpu.arch == .aarch64" },
804
+ .{ .path = "build/app.zig", .pattern = ".windows => !cross or target.result.abi == .gnu" },
805
+ .{ .path = "build/app.zig", .pattern = ".windows => target.result.cpu.arch == .x86_64" },
806
+ .{ .path = "build/app.zig", .pattern = "if (linuxGlibcSpellingHitsDefaultFloor(target)) {" },
807
+ .{ .path = "build.zig", .pattern = "if (!app_build.linuxGlibcSpellingHitsDefaultFloor(target)) return;" },
808
+ .{ .path = "build/app.zig", .pattern = "scriptcPlatformTriple(b, target),\n // Keep the core and service archives on the same cross compiler" },
809
+ .{ .path = "build.zig", .pattern = "app_build.scriptcPlatformTriple(b, target),\n \"--zig-exe\",\n b.graph.zig_exe," },
810
+ .{ .path = "build.zig", .pattern = "compile.addArgs(&.{ \"--host-platform\", host_platform, \"--target-platform\", app_build.scriptcPlatformTriple(b, target), \"--zig-exe\", b.graph.zig_exe });\n app_build.addScriptcAndroidNdk(b, compile, target);\n addScriptcGlibcFloorTeaching(b, target, &compile.step);" },
811
+ .{ .path = "build.zig", .pattern = "app_build.scriptcPlatformTriple(b, target),\n \"--zig-exe\",\n b.graph.zig_exe,\n });\n app_build.addScriptcAndroidNdk(b, compile, target);\n addScriptcGlibcFloorTeaching(b, target, &compile.step);" },
812
+ .{ .path = "build.zig", .pattern = "abi_laws_mod.addObjectFile(markup_fixture.archive);\n addScriptcArchiveSystemLibs(abi_laws_mod, target);" },
813
+ // Both drivers map the build graph's Zig triple onto the compiler's
814
+ // own mobile spellings and thread the NDK like --zig-exe.
815
+ .{ .path = "packages/core/scripts/run_external_core_compiler.mjs", .pattern = "SCRIPTC_TARGET: scriptcTarget" },
816
+ .{ .path = "packages/core/scripts/run_external_service_compiler.mjs", .pattern = "SCRIPTC_TARGET: scriptcTarget" },
817
+ .{ .path = "packages/core/scripts/run_external_core_compiler.mjs", .pattern = "ANDROID_NDK_ROOT: args[\"android-ndk\"]" },
818
+ .{ .path = "packages/core/scripts/run_external_service_compiler.mjs", .pattern = "ANDROID_NDK_ROOT: args[\"android-ndk\"]" },
819
+ .{ .path = "build/app.zig", .pattern = ".ios => host.os.tag == .macos and target.result.cpu.arch == .aarch64" },
607
820
  });
608
821
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-app-test-entry-analysis", "Verify the managed app test step force-analyzes the entry point (UiApp.create's Model-defaults rule must teach at `native test`, not ambush at `native build`)", &.{
609
822
  .{ .path = "build/app.zig", .pattern = "app_analysis.zig" },
@@ -1415,6 +1628,8 @@ pub fn build(b: *std.Build) void {
1415
1628
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-gpu-surface", "Run GPU surface example tests", "examples/gpu-surface", .managed),
1416
1629
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-gpu-dashboard", "Run GPU dashboard example tests", "examples/gpu-dashboard", .managed),
1417
1630
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-gpu-components", "Run GPU components example tests", "examples/gpu-components", .managed),
1631
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-record-store", "Run record-store example tests", "examples/record-store", .managed),
1632
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-relational-notes", "Run relational notes example tests", "examples/relational-notes", .managed),
1418
1633
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-ui-inbox", "Run ui builder inbox example tests", "examples/ui-inbox", .owned),
1419
1634
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-kanban", "Run ui builder kanban example tests", "examples/kanban", .managed),
1420
1635
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-habits", "Run markup habits example tests", "examples/habits", .managed),
@@ -1436,6 +1651,7 @@ pub fn build(b: *std.Build) void {
1436
1651
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-channel-monitor", "Run channel monitor example tests", "examples/channel-monitor", .managed),
1437
1652
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-menu-bar", "Run menu-bar lifecycle example tests", "examples/menu-bar", .managed),
1438
1653
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-feed", "Run feed example tests", "examples/feed", .managed),
1654
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-service-feed-reader", "Run TypeScript service feed-reader example tests", "examples/service-feed-reader", .managed),
1439
1655
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-canvas-preview", "Run canvas preview example tests", "examples/canvas-preview", .managed),
1440
1656
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-capabilities", "Run capabilities example tests", "examples/capabilities", .owned),
1441
1657
  };
@@ -1622,14 +1838,63 @@ pub fn build(b: *std.Build) void {
1622
1838
  mobile_canvas_lib_step.dependOn(&build_mobile_canvas_lib.step);
1623
1839
  mobile_examples_step.dependOn(&build_mobile_canvas_lib.step);
1624
1840
 
1625
- // Android cross-compile proof: pure Zig (no NDK sysroot — the static
1626
- // lib links no libc), PIC so the objects can land in the shim's .so.
1841
+ const build_mobile_canvas_store_lib = b.addSystemCommand(&.{ "zig", "build", "lib", "-Dstore=true" });
1842
+ build_mobile_canvas_store_lib.setCwd(b.path("examples/mobile-canvas"));
1843
+ const mobile_canvas_store_lib_step = b.step("test-example-mobile-canvas-lib-store", "Build a record-store-capable mobile embed static library");
1844
+ mobile_canvas_store_lib_step.dependOn(&build_mobile_canvas_store_lib.step);
1845
+ mobile_examples_step.dependOn(&build_mobile_canvas_store_lib.step);
1846
+
1847
+ const build_mobile_canvas_relational_lib = b.addSystemCommand(&.{ "zig", "build", "lib", "-Dsqlite=true", "--prefix", "zig-out/test-relational" });
1848
+ build_mobile_canvas_relational_lib.setCwd(b.path("examples/mobile-canvas"));
1849
+ const mobile_canvas_relational_lib_step = b.step("test-example-mobile-canvas-lib-sqlite", "Build a relational-SQLite-capable mobile embed static library");
1850
+ mobile_canvas_relational_lib_step.dependOn(&build_mobile_canvas_relational_lib.step);
1851
+ mobile_examples_step.dependOn(&build_mobile_canvas_relational_lib.step);
1852
+
1853
+ const build_mobile_canvas_both_storage_lib = b.addSystemCommand(&.{ "zig", "build", "lib", "-Dstore=true", "-Dsqlite=true", "--prefix", "zig-out/test-both-storage" });
1854
+ build_mobile_canvas_both_storage_lib.setCwd(b.path("examples/mobile-canvas"));
1855
+ const mobile_canvas_both_storage_lib_step = b.step("test-example-mobile-canvas-lib-storage", "Build both SQLite-backed mobile tiers with one vendored engine object");
1856
+ mobile_canvas_both_storage_lib_step.dependOn(&build_mobile_canvas_both_storage_lib.step);
1857
+ mobile_examples_step.dependOn(&build_mobile_canvas_both_storage_lib.step);
1858
+
1859
+ // Android cross-compile proofs: the capability-free archive remains pure
1860
+ // Zig, while the store variant must discover the NDK sysroot and compile
1861
+ // the vendored SQLite amalgamation for bionic. Keeping both catches a
1862
+ // capability branch that a host-only store build cannot exercise.
1627
1863
  const build_mobile_canvas_lib_android = b.addSystemCommand(&.{ "zig", "build", "lib", "-Dtarget=aarch64-linux-android" });
1628
1864
  build_mobile_canvas_lib_android.setCwd(b.path("examples/mobile-canvas"));
1629
1865
  const mobile_canvas_lib_android_step = b.step("test-example-mobile-canvas-lib-android", "Cross-compile the mobile-canvas embed static library for aarch64-linux-android");
1630
1866
  mobile_canvas_lib_android_step.dependOn(&build_mobile_canvas_lib_android.step);
1631
1867
  mobile_examples_step.dependOn(&build_mobile_canvas_lib_android.step);
1632
1868
 
1869
+ const build_mobile_canvas_store_lib_android = b.addSystemCommand(&.{
1870
+ "zig", "build", "lib", "-Dstore=true", "-Dtarget=aarch64-linux-android",
1871
+ "--prefix", "zig-out/test-android-store",
1872
+ });
1873
+ build_mobile_canvas_store_lib_android.setCwd(b.path("examples/mobile-canvas"));
1874
+ const mobile_canvas_store_lib_android_step = b.step("test-example-mobile-canvas-lib-android-store", "Cross-compile SQLite-backed mobile storage for aarch64-linux-android");
1875
+ mobile_canvas_store_lib_android_step.dependOn(&build_mobile_canvas_store_lib_android.step);
1876
+ mobile_examples_step.dependOn(&build_mobile_canvas_store_lib_android.step);
1877
+
1878
+ // Apple SDK headers only exist on macOS. This is still part of the local
1879
+ // mobile aggregate there, and CI invokes the named step on its macOS tier.
1880
+ if (b.graph.host.result.os.tag == .macos) {
1881
+ const build_mobile_canvas_store_lib_ios = b.addSystemCommand(&.{
1882
+ "zig", "build", "lib", "-Dstore=true", "-Dtarget=aarch64-ios-simulator",
1883
+ "--prefix", "zig-out/test-ios-store",
1884
+ });
1885
+ build_mobile_canvas_store_lib_ios.setCwd(b.path("examples/mobile-canvas"));
1886
+ const build_mobile_canvas_store_lib_ios_device = b.addSystemCommand(&.{
1887
+ "zig", "build", "lib", "-Dstore=true", "-Dtarget=aarch64-ios",
1888
+ "--prefix", "zig-out/test-ios-device-store",
1889
+ });
1890
+ build_mobile_canvas_store_lib_ios_device.setCwd(b.path("examples/mobile-canvas"));
1891
+ const mobile_canvas_store_lib_ios_step = b.step("test-example-mobile-canvas-lib-ios-store", "Cross-compile SQLite-backed mobile storage for iOS simulator and device");
1892
+ mobile_canvas_store_lib_ios_step.dependOn(&build_mobile_canvas_store_lib_ios.step);
1893
+ mobile_canvas_store_lib_ios_step.dependOn(&build_mobile_canvas_store_lib_ios_device.step);
1894
+ mobile_examples_step.dependOn(&build_mobile_canvas_store_lib_ios.step);
1895
+ mobile_examples_step.dependOn(&build_mobile_canvas_store_lib_ios_device.step);
1896
+ }
1897
+
1633
1898
  const examples_step = b.step("test-examples", "Run all example tests and layout checks");
1634
1899
  examples_step.dependOn(frontend_examples_step);
1635
1900
  examples_step.dependOn(native_examples_step);
@@ -2234,7 +2499,8 @@ pub fn build(b: *std.Build) void {
2234
2499
  // numbers only mean something on a controlled machine. Runs via
2235
2500
  // `scripts/gate.sh full --perf` locally and a dedicated macos-14 CI job.
2236
2501
  // Knobs: NATIVE_SDK_PERF_LAUNCHES, NATIVE_SDK_PERF_INTERACTIONS, NATIVE_SDK_PERF_BUDGET_MS,
2237
- // NATIVE_SDK_PERF_INPUT_BUDGET_MS — see scripts/perf-gpu-dashboard.sh.
2502
+ // NATIVE_SDK_PERF_INPUT_BUDGET_MS, and NATIVE_SDK_PERF_ANIMATION_* — see
2503
+ // scripts/perf-gpu-dashboard.sh.
2238
2504
  const gpu_dashboard_perf_step = b.step("test-gpu-dashboard-perf", "Run macOS GPU dashboard percentile performance check (N launches; slow)");
2239
2505
  const gpu_dashboard_perf_build = managedExampleRun(b, cli_exe, &.{ "build", "-Dplatform=macos", "-Dweb-engine=system", "-Dautomation=true", "-Doptimize=Debug" });
2240
2506
  gpu_dashboard_perf_build.setCwd(b.path("examples/gpu-dashboard"));
@@ -2705,6 +2971,19 @@ pub fn build(b: *std.Build) void {
2705
2971
  cef_bundle_step.dependOn(&cef_bundle_script.step);
2706
2972
  }
2707
2973
 
2974
+ fn sqliteCompileFlags() []const []const u8 {
2975
+ return &.{
2976
+ "-DSQLITE_THREADSAFE=2",
2977
+ "-DSQLITE_OMIT_LOAD_EXTENSION",
2978
+ "-DSQLITE_DQS=0",
2979
+ "-DSQLITE_ENABLE_FTS5",
2980
+ "-DSQLITE_ENABLE_JSON1",
2981
+ "-DSQLITE_ENABLE_UPDATE_HOOK",
2982
+ "-DSQLITE_DEFAULT_WAL_SYNCHRONOUS=1",
2983
+ "-DSQLITE_DEFAULT_MEMSTATUS=0",
2984
+ };
2985
+ }
2986
+
2708
2987
  fn module(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode, path: []const u8) *std.Build.Module {
2709
2988
  return b.createModule(.{
2710
2989
  .root_source_file = b.path(path),
@@ -2752,6 +3031,7 @@ fn testArtifact(b: *std.Build, mod: *std.Build.Module) *std.Build.Step.Compile {
2752
3031
  /// installed dependency (`npm ci` in packages/core) is missing.
2753
3032
  const TsCoreE2eArtifacts = struct {
2754
3033
  host: *std.Build.Step.Compile,
3034
+ persist: *std.Build.Step.Compile,
2755
3035
  /// The markup battery is its own binary: the compiled-core symbol
2756
3036
  /// set is a fixed-prefix C ABI, so one process carries ONE archive
2757
3037
  /// — every fixture battery links exactly its own core.
@@ -2764,6 +3044,31 @@ const TsCoreE2eArtifacts = struct {
2764
3044
  /// paths, and builds keep working with node_modules deleted.
2765
3045
  scaffold_ide: *std.Build.Step.Compile,
2766
3046
  ai_chat: *std.Build.Step.Compile,
3047
+ /// The complete services loop over examples/service-feed-reader: a real
3048
+ /// loopback Cmd.fetch, the generated typed client into a real service
3049
+ /// child, the shipping markup, and record→replay without either.
3050
+ feed_reader: *std.Build.Step.Compile,
3051
+ /// The phase-1 service seam: a real compiled core plus a real plain-scriptc
3052
+ /// service executable driven through the out-of-process carrier.
3053
+ services: *std.Build.Step.Compile,
3054
+ /// The in-process service carrier: the same fixture compiled as a
3055
+ /// thread-instanced library archive, linked into this battery and driven
3056
+ /// through ServicePool (parallel keys, per-key FIFO, cooperative
3057
+ /// cancellation/deadlines, trap isolation, streaming, replay). Null when
3058
+ /// the target cannot carry the archive (cross or non-desktop builds).
3059
+ services_pool: ?*std.Build.Step.Compile,
3060
+ /// The mobile execution battery: the pool fixture's core and service
3061
+ /// archives linked into one static library exporting `nsme_run`, so
3062
+ /// the platform toolchain links a runnable harness for the simulator
3063
+ /// or emulator (scripts/mobile-e2e.sh). Present only for a mobile
3064
+ /// -Dtarget; the Android archive is flattened to plain objects (Zig's
3065
+ /// ELF static-library emission nests archive inputs).
3066
+ mobile_battery: ?std.Build.LazyPath,
3067
+ /// The service-host carrier benchmark: a bytes-echo service compiled
3068
+ /// through the same lane, driven directly through the production
3069
+ /// carrier bindings of BOTH carriers (cold start, round-trip latency,
3070
+ /// queued throughput).
3071
+ service_host_bench: *std.Build.Step.Compile,
2767
3072
  /// Sidecar-shim conformance (tests/sidecar): every fixture's
2768
3073
  /// generated mirror validated over its frontend-emitted contract
2769
3074
  /// (plus the hand-written ground-truth sidecars), and every shim
@@ -2774,6 +3079,9 @@ const TsCoreE2eArtifacts = struct {
2774
3079
  /// (boot fence, collect invariant, deterministic re-init, channel
2775
3080
  /// envelopes, integer classes).
2776
3081
  external_core_abi_laws: *std.Build.Step.Compile,
3082
+ /// The mixed-return ABI regression: a real compiled core whose update
3083
+ /// returns both bare Model and [Model, Cmd] through the generated facade.
3084
+ mixed_return_abi_laws: *std.Build.Step.Compile,
2777
3085
  /// Per-fixture contract artifacts for an external core toolchain:
2778
3086
  /// the effective contract sidecar and its TypeScript facade/profile
2779
3087
  /// projections, installed by the stage-core-contracts step.
@@ -2814,16 +3122,17 @@ fn tsCoreE2eArtifact(
2814
3122
 
2815
3123
  // corewire (the contract-sidecar mirror/facade/profile generator),
2816
3124
  // compiled for the build host: the fixture compiles and the
2817
- // conformance shims all run it.
3125
+ // conformance shims all run it, including under a cross -Dtarget
3126
+ // (the batteries compile for the target; this tool never does).
2818
3127
  const corewire_mod = b.createModule(.{
2819
3128
  .root_source_file = b.path("tools/corewire/main.zig"),
2820
- .target = target,
3129
+ .target = b.graph.host,
2821
3130
  .optimize = optimize,
2822
3131
  });
2823
3132
  const corewire_exe = b.addExecutable(.{
2824
3133
  .name = "corewire",
2825
3134
  .root_module = corewire_mod,
2826
- .use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
3135
+ .use_llvm = @import("build/app.zig").useLlvmWorkaround(b.graph.host),
2827
3136
  });
2828
3137
 
2829
3138
  // Each fixture core compiles through the external core compiler at
@@ -2839,12 +3148,26 @@ fn tsCoreE2eArtifact(
2839
3148
  .entry = "tests/ts-core/fixture.ts",
2840
3149
  .src_dir = host_src.getDirectory(),
2841
3150
  .name = "host_fixture_core",
3151
+ .store_capability = true,
3152
+ .relational_capability = true,
3153
+ .credentials_capability = true,
2842
3154
  // The fixture drives pastBytes to the f64-exact boundary (2^53):
2843
3155
  // no honest i64 declaration exists there, so the compiled
2844
3156
  // projection carries the slot as f64.
2845
3157
  .f64_slots = &.{"Model.pastBytes"},
2846
3158
  });
2847
3159
  const fixture_mod = host_fixture.module;
3160
+ const persist_src = b.addWriteFiles();
3161
+ _ = persist_src.addCopyFile(b.path("tests/ts-core/persist_fixture.ts"), "persist_fixture.ts");
3162
+ const persist_fixture = externalCoreFixtureModule(b, target, optimize, node, corewire_exe, .{
3163
+ .entry = "tests/ts-core/persist_fixture.ts",
3164
+ .src_dir = persist_src.getDirectory(),
3165
+ .name = "persist_fixture_core",
3166
+ .persist_capability = true,
3167
+ });
3168
+ const persist_mod = module(b, target, optimize, "tests/ts-core/persist_e2e_tests.zig");
3169
+ persist_mod.addImport("native_sdk", desktop_mod);
3170
+ persist_mod.addImport("ts_persist_core", persist_fixture.module);
2848
3171
  const markup_src = b.addWriteFiles();
2849
3172
  _ = markup_src.addCopyFile(b.path("tests/ts-core/markup_fixture.ts"), "markup_fixture.ts");
2850
3173
  const markup_fixture = externalCoreFixtureModule(b, target, optimize, node, corewire_exe, .{
@@ -2853,6 +3176,13 @@ fn tsCoreE2eArtifact(
2853
3176
  .name = "markup_core",
2854
3177
  });
2855
3178
  const markup_fixture_mod = markup_fixture.module;
3179
+ const mixed_return_src = b.addWriteFiles();
3180
+ _ = mixed_return_src.addCopyFile(b.path("tests/ts-core/mixed_return_fixture.ts"), "mixed_return_fixture.ts");
3181
+ const mixed_return_fixture = externalCoreFixtureModule(b, target, optimize, node, corewire_exe, .{
3182
+ .entry = "tests/ts-core/mixed_return_fixture.ts",
3183
+ .src_dir = mixed_return_src.getDirectory(),
3184
+ .name = "mixed_return_core",
3185
+ });
2856
3186
 
2857
3187
  const e2e_mod = module(b, target, optimize, "tests/ts-core/host_e2e_tests.zig");
2858
3188
  e2e_mod.addImport("native_sdk", desktop_mod);
@@ -2917,6 +3247,8 @@ fn tsCoreE2eArtifact(
2917
3247
  const monitor_stage = b.addWriteFiles();
2918
3248
  const monitor_root = monitor_stage.addCopyFile(b.path("tests/ts-core/system_monitor_e2e_tests.zig"), "system_monitor_e2e_tests.zig");
2919
3249
  _ = monitor_stage.addCopyFile(b.path("examples/system-monitor-ts/src/app.native"), "app.native");
3250
+ _ = monitor_stage.addCopyFile(b.path("examples/system-monitor-ts/src/windows/settings.native"), "settings.native");
3251
+ _ = monitor_stage.addCopyFile(b.path("examples/system-monitor-ts/src/windows/components/sampling.native"), "components/sampling.native");
2920
3252
  _ = monitor_stage.addCopyFile(b.path("examples/system-monitor/src/fixtures/sysctl.txt"), "fixtures/sysctl.txt");
2921
3253
  _ = monitor_stage.addCopyFile(b.path("examples/system-monitor/src/fixtures/ps.txt"), "fixtures/ps.txt");
2922
3254
  _ = monitor_stage.addCopyFile(b.path("examples/system-monitor/src/fixtures/vm_stat.txt"), "fixtures/vm_stat.txt");
@@ -2954,6 +3286,169 @@ fn tsCoreE2eArtifact(
2954
3286
  ai_chat_mod.addImport("native_sdk", desktop_mod);
2955
3287
  ai_chat_mod.addImport("ts_ai_chat_core", ai_chat_core_mod);
2956
3288
 
3289
+ // The service-feed-reader example's core, service child, and shipping
3290
+ // markup, tested as one app: a real buffered Cmd.fetch against a
3291
+ // loopback fixture, the generated typed client into the real child,
3292
+ // and record→replay with neither the service nor the network present.
3293
+ const feed_reader_fixture = externalCoreFixtureModule(b, target, optimize, node, corewire_exe, .{
3294
+ .entry = "examples/service-feed-reader/src/core.ts",
3295
+ .src_dir = b.path("examples/service-feed-reader/src"),
3296
+ .name = "feed_reader_core",
3297
+ .emit_services = true,
3298
+ });
3299
+ const feed_reader_service = externalServiceFixture(
3300
+ b,
3301
+ target,
3302
+ optimize,
3303
+ node,
3304
+ corewire_exe,
3305
+ b.path("examples/service-feed-reader/src"),
3306
+ feed_reader_fixture.services_contract.?,
3307
+ "feed_reader_services",
3308
+ );
3309
+ const feed_reader_stage = b.addWriteFiles();
3310
+ const feed_reader_root = feed_reader_stage.addCopyFile(b.path("tests/ts-services/feed_reader_e2e_tests.zig"), "feed_reader_e2e_tests.zig");
3311
+ _ = feed_reader_stage.addCopyFile(b.path("examples/service-feed-reader/src/app.native"), "app.native");
3312
+ _ = feed_reader_stage.addCopyFile(b.path("examples/service-feed-reader/fixtures/feed.xml"), "fixture_feed.xml");
3313
+ const feed_reader_mod = b.createModule(.{
3314
+ .root_source_file = feed_reader_root,
3315
+ .target = target,
3316
+ .optimize = optimize,
3317
+ });
3318
+ feed_reader_mod.addImport("native_sdk", desktop_mod);
3319
+ feed_reader_mod.addImport("ts_feed_reader_core", feed_reader_fixture.module);
3320
+ feed_reader_mod.addImport("ts_feed_reader_registry", feed_reader_service.registry);
3321
+ const feed_reader_options = b.addOptions();
3322
+ feed_reader_options.addOptionPath("service_executable", feed_reader_service.executable);
3323
+ feed_reader_mod.addOptions("ts_feed_reader_options", feed_reader_options);
3324
+
3325
+ // Phase-1 TypeScript services, end to end: the frontend emits BOTH
3326
+ // sidecars from one checked two-class program; corewire derives the
3327
+ // registry/host only from the service sidecar; plain scriptc compiles the
3328
+ // child executable; and the Zig battery drives that executable through
3329
+ // the production ServiceHost + effects/session boundary.
3330
+ const services_fixture = externalCoreFixtureModule(b, target, optimize, node, corewire_exe, .{
3331
+ .entry = "tests/ts-services/ok/src/core.ts",
3332
+ .src_dir = b.path("tests/ts-services/ok/src"),
3333
+ .name = "services_fixture_core",
3334
+ .emit_services = true,
3335
+ .service_packages = &.{"escape-string-regexp|5.0.0|705f4bb4b92fd3469e264a93f2a2e4b24cf7e663d73a5318abaf29ee72674f6d"},
3336
+ });
3337
+ const service_host_fixture = externalServiceFixture(
3338
+ b,
3339
+ target,
3340
+ optimize,
3341
+ node,
3342
+ corewire_exe,
3343
+ b.path("tests/ts-services/ok/src"),
3344
+ services_fixture.services_contract.?,
3345
+ "ts_services_fixture_services",
3346
+ );
3347
+ const services_e2e_mod = module(b, target, optimize, "tests/ts-services/service_e2e_tests.zig");
3348
+ services_e2e_mod.addImport("native_sdk", desktop_mod);
3349
+ services_e2e_mod.addImport("ts_services_core", services_fixture.module);
3350
+ services_e2e_mod.addImport("ts_services_registry", service_host_fixture.registry);
3351
+ const service_test_options = b.addOptions();
3352
+ service_test_options.addOptionPath("service_executable", service_host_fixture.executable);
3353
+ service_test_options.addOption([]const u8, "node_executable", node);
3354
+ services_e2e_mod.addOptions("ts_services_options", service_test_options);
3355
+
3356
+ // The same fixture against the in-process carrier: the service archive
3357
+ // links into the battery beside the fixture core's archive (distinct
3358
+ // symbol prefixes), and ServicePool drives it through the identical
3359
+ // TsUiApp/Effects seam.
3360
+ const services_pool_mod: ?*std.Build.Module = if (service_host_fixture.archive) |service_archive| pool: {
3361
+ const pool_mod = module(b, target, optimize, "tests/ts-services/service_pool_e2e_tests.zig");
3362
+ pool_mod.addImport("native_sdk", desktop_mod);
3363
+ pool_mod.addImport("ts_services_core", services_fixture.module);
3364
+ pool_mod.addImport("ts_services_registry", service_host_fixture.registry);
3365
+ pool_mod.link_libc = true;
3366
+ pool_mod.addObjectFile(service_archive);
3367
+ addScriptcArchiveSystemLibs(pool_mod, target);
3368
+ break :pool pool_mod;
3369
+ } else null;
3370
+
3371
+ // The mobile execution battery: a static library over the same pool
3372
+ // fixture, linked into a runnable harness by the platform toolchain —
3373
+ // the same link pattern embedding apps use for the embed library. The
3374
+ // Android objects are PIC like the embed library's (the harness there
3375
+ // is a bionic executable; a future .so embedding needs it regardless).
3376
+ const battery_target_is_mobile = target.result.os.tag == .ios or target.result.abi.isAndroid();
3377
+ const mobile_battery: ?std.Build.LazyPath = if (battery_target_is_mobile and service_host_fixture.archive != null) battery: {
3378
+ const battery_mod = b.createModule(.{
3379
+ .root_source_file = b.path("tests/ts-services/mobile_e2e_battery.zig"),
3380
+ .target = target,
3381
+ .optimize = optimize,
3382
+ .pic = if (target.result.abi.isAndroid()) true else null,
3383
+ });
3384
+ battery_mod.addImport("native_sdk", desktop_mod);
3385
+ battery_mod.addImport("ts_services_core", services_fixture.module);
3386
+ battery_mod.addImport("ts_services_registry", service_host_fixture.registry);
3387
+ battery_mod.link_libc = true;
3388
+ battery_mod.addObjectFile(service_host_fixture.archive.?);
3389
+ const battery_lib = b.addLibrary(.{
3390
+ .linkage = .static,
3391
+ .name = "ts-mobile-e2e",
3392
+ .root_module = battery_mod,
3393
+ .use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
3394
+ });
3395
+ if (target.result.abi.isAndroid()) {
3396
+ // Flatten the nested TypeScript archives (Zig's ELF static-lib
3397
+ // emission stores .a inputs as members) so the NDK link consumes
3398
+ // plain objects — the same normalization the app lane applies.
3399
+ const merge = b.addSystemCommand(&.{node});
3400
+ merge.addFileArg(b.path("packages/core/scripts/merge_static_archives.mjs"));
3401
+ merge.addArgs(&.{ "--zig", b.graph.zig_exe, "--format", "gnu" });
3402
+ merge.addArg("--out");
3403
+ const merged = merge.addOutputFileArg("libts-mobile-e2e.a");
3404
+ merge.addArg("--in");
3405
+ merge.addFileArg(battery_lib.getEmittedBin());
3406
+ break :battery merged;
3407
+ }
3408
+ break :battery battery_lib.getEmittedBin();
3409
+ } else null;
3410
+
3411
+ // Service-host carrier benchmark: the same production service lane
3412
+ // (frontend contract -> corewire host/registry -> exact-pinned
3413
+ // plain-scriptc executable) over a bytes-echo operation that returns
3414
+ // its request unchanged, so tools/bench_service_host.zig measures the
3415
+ // carrier — lazy spawn, framing, pipes, worker queueing — and never a
3416
+ // workload.
3417
+ const service_bench_core = externalCoreFixtureModule(b, target, optimize, node, corewire_exe, .{
3418
+ .entry = "tools/service-host-bench/src/core.ts",
3419
+ .src_dir = b.path("tools/service-host-bench/src"),
3420
+ .name = "service_host_bench_core",
3421
+ .emit_services = true,
3422
+ });
3423
+ const service_bench_fixture = externalServiceFixture(
3424
+ b,
3425
+ target,
3426
+ optimize,
3427
+ node,
3428
+ corewire_exe,
3429
+ b.path("tools/service-host-bench/src"),
3430
+ service_bench_core.services_contract.?,
3431
+ "service_host_bench_services",
3432
+ );
3433
+ const service_bench_mod = module(b, target, optimize, "tools/bench_service_host.zig");
3434
+ service_bench_mod.addImport("native_sdk", desktop_mod);
3435
+ service_bench_mod.addImport("service_registry", service_bench_fixture.registry);
3436
+ const service_bench_options = b.addOptions();
3437
+ service_bench_options.addOptionPath("service_executable", service_bench_fixture.executable);
3438
+ service_bench_options.addOption(bool, "has_archive", service_bench_fixture.archive != null);
3439
+ service_bench_mod.addOptions("bench_options", service_bench_options);
3440
+ if (service_bench_fixture.archive) |bench_archive| {
3441
+ // The in-process carrier's half of the benchmark: the same echo
3442
+ // service as a linked archive, driven through ServicePool.
3443
+ service_bench_mod.link_libc = true;
3444
+ service_bench_mod.addObjectFile(bench_archive);
3445
+ addScriptcArchiveSystemLibs(service_bench_mod, target);
3446
+ }
3447
+ const service_bench_exe = b.addExecutable(.{
3448
+ .name = "bench-service-host",
3449
+ .root_module = service_bench_mod,
3450
+ });
3451
+
2957
3452
  // Sidecar-shim conformance: a corewire-generated mirror per corpus
2958
3453
  // fixture. The markup fixture's sidecar is the committed
2959
3454
  // hand-written one (independent ground truth for the schema); the
@@ -3023,21 +3518,167 @@ fn tsCoreE2eArtifact(
3023
3518
  abi_laws_mod.addImport("core_abi", module(b, target, optimize, "tools/corewire/core_abi.zig"));
3024
3519
  abi_laws_mod.addImport("shim_core", sidecarShimModule(b, target, optimize, corewire_exe, markup_fixture.sidecar));
3025
3520
  abi_laws_mod.addObjectFile(markup_fixture.archive);
3521
+ addScriptcArchiveSystemLibs(abi_laws_mod, target);
3522
+
3523
+ const mixed_return_abi_mod = module(b, target, optimize, "tests/sidecar/mixed_return_abi_tests.zig");
3524
+ mixed_return_abi_mod.addImport("mixed_return_core", mixed_return_fixture.module);
3026
3525
 
3027
3526
  return .{
3028
3527
  .host = filteredTestArtifact(b, e2e_mod, "ts-core-e2e-tests", &.{}),
3528
+ .persist = filteredTestArtifact(b, persist_mod, "ts-persist-e2e-tests", &.{}),
3029
3529
  .markup = filteredTestArtifact(b, markup_e2e_mod, "ts-markup-e2e-tests", &.{}),
3030
3530
  .kanban = filteredTestArtifact(b, kanban_mod, "ts-kanban-e2e-tests", &.{}),
3031
3531
  .soundboard = filteredTestArtifact(b, soundboard_mod, "ts-soundboard-e2e-tests", &.{}),
3032
3532
  .system_monitor = filteredTestArtifact(b, monitor_mod, "ts-system-monitor-e2e-tests", &.{}),
3033
3533
  .scaffold_ide = filteredTestArtifact(b, scaffold_ide_mod, "ts-scaffold-ide-e2e-tests", &.{}),
3034
3534
  .ai_chat = filteredTestArtifact(b, ai_chat_mod, "ts-ai-chat-e2e-tests", &.{}),
3535
+ .feed_reader = filteredTestArtifact(b, feed_reader_mod, "ts-feed-reader-e2e-tests", &.{}),
3536
+ .services = filteredTestArtifact(b, services_e2e_mod, "ts-services-e2e-tests", &.{}),
3537
+ .services_pool = if (services_pool_mod) |pool_mod| filteredTestArtifact(b, pool_mod, "ts-services-pool-e2e-tests", &.{}) else null,
3538
+ .mobile_battery = mobile_battery,
3539
+ .service_host_bench = service_bench_exe,
3035
3540
  .sidecar_conformance = filteredTestArtifact(b, conformance_mod, "sidecar-conformance-tests", &.{}),
3036
3541
  .external_core_abi_laws = filteredTestArtifact(b, abi_laws_mod, "external-core-abi-tests", &.{}),
3542
+ .mixed_return_abi_laws = filteredTestArtifact(b, mixed_return_abi_mod, "mixed-return-abi-tests", &.{}),
3037
3543
  .core_contracts = core_contracts.toOwnedSlice(b.allocator) catch @panic("OOM"),
3038
3544
  };
3039
3545
  }
3040
3546
 
3547
+ /// System import libraries scriptc's compiled-archive runtime reaches on
3548
+ /// Windows targets — core and service archives alike (Winsock, adapter
3549
+ /// enumeration, and crypto-backed randomness). No-op elsewhere; the
3550
+ /// archives' other dependencies are libc's. The app lane's twin is the
3551
+ /// Windows platform block in build/app.zig.
3552
+ fn addScriptcArchiveSystemLibs(mod: *std.Build.Module, target: std.Build.ResolvedTarget) void {
3553
+ if (target.result.os.tag != .windows) return;
3554
+ mod.linkSystemLibrary("ws2_32", .{});
3555
+ mod.linkSystemLibrary("iphlpapi", .{});
3556
+ mod.linkSystemLibrary("advapi32", .{});
3557
+ }
3558
+
3559
+ /// Attach ScriptC's explicit-Linux-target glibc-floor teaching to an actual
3560
+ /// compile step. A target can match the host triple and still need the teaching
3561
+ /// because Zig's explicitly spelled `-gnu` target uses its default glibc floor.
3562
+ /// The root graph constructs fixture lanes even for unrelated selections such
3563
+ /// as the release pipeline's cross-compiled `zig build cli`; making the
3564
+ /// teaching a dependency preserves those CLI-only builds while still refusing
3565
+ /// the unsupported target before a selected ScriptC compile does any work.
3566
+ fn addScriptcGlibcFloorTeaching(b: *std.Build, target: std.Build.ResolvedTarget, step: *std.Build.Step) void {
3567
+ const app_build = @import("build/app.zig");
3568
+ if (!app_build.linuxGlibcSpellingHitsDefaultFloor(target)) return;
3569
+ step.dependOn(&b.addFail(app_build.scriptcLinuxGlibcSpellingTeaching(b, target)).step);
3570
+ }
3571
+
3572
+ const ExternalServiceFixture = struct {
3573
+ executable: std.Build.LazyPath,
3574
+ /// The in-process carrier's library archive (thread-instanced,
3575
+ /// runtime-localized), compiled from the same staged tree. Present
3576
+ /// wherever the pinned compiler's localized-archive matrix covers the
3577
+ /// pairing (native Linux, cross-Linux x86_64/aarch64, Windows x86_64,
3578
+ /// or macOS from a macOS host — see build/app.zig
3579
+ /// serviceArchiveSupported); null elsewhere, and for explicitly spelled
3580
+ /// linux-gnu targets below the glibc 2.36 runtime floor.
3581
+ archive: ?std.Build.LazyPath,
3582
+ registry: *std.Build.Module,
3583
+ };
3584
+
3585
+ /// Compile one fixture's service class through the production phase-1 lane:
3586
+ /// service sidecar -> corewire host/registry -> ordinary source stage (plus
3587
+ /// the pinned compiler's tagged-throw compatibility lowering) -> exact pinned
3588
+ /// scriptc outputs (the child executable, plus the in-process library archive
3589
+ /// wherever the compiler's localized-archive matrix covers the host/target
3590
+ /// pairing). No author source is re-read for dispatch facts after the sidecar
3591
+ /// emission.
3592
+ fn externalServiceFixture(
3593
+ b: *std.Build,
3594
+ target: std.Build.ResolvedTarget,
3595
+ optimize: std.builtin.OptimizeMode,
3596
+ node: []const u8,
3597
+ corewire_exe: *std.Build.Step.Compile,
3598
+ src_dir: std.Build.LazyPath,
3599
+ contract: std.Build.LazyPath,
3600
+ name: []const u8,
3601
+ ) ExternalServiceFixture {
3602
+ const app_build = @import("build/app.zig");
3603
+ const emit_archive = app_build.serviceArchiveSupported(b.graph.host.result, target);
3604
+ const project = b.addRunArtifact(corewire_exe);
3605
+ project.addArg("--services-sidecar");
3606
+ project.addFileArg(contract);
3607
+ project.addArg("--service-host-main");
3608
+ const host_main = project.addOutputFileArg("service_host_main.ts");
3609
+ project.addArg("--service-registry");
3610
+ const registry_source = project.addOutputFileArg("services.zig");
3611
+ project.addArg("--service-inproc-main");
3612
+ const inproc_main = project.addOutputFileArg("service_inproc_main.ts");
3613
+ project.addArg("--service-inproc-profile");
3614
+ const inproc_profile = project.addOutputFileArg("service_profile.json");
3615
+
3616
+ const stage = b.addSystemCommand(&.{node});
3617
+ stage.addFileArg(b.path("packages/core/scripts/stage_external_services.mjs"));
3618
+ stage.addArg("--src");
3619
+ stage.addDirectoryArg(src_dir);
3620
+ stage.addArg("--host-main");
3621
+ stage.addFileArg(host_main);
3622
+ stage.addArg("--inproc-main");
3623
+ stage.addFileArg(inproc_main);
3624
+ stage.addArg("--inproc-profile");
3625
+ stage.addFileArg(inproc_profile);
3626
+ stage.addArg("--contract");
3627
+ stage.addFileArg(contract);
3628
+ stage.addArg("--out");
3629
+ const stage_dir = stage.addOutputDirectoryArg("services-stage");
3630
+ // A LazyPath directory records only its producer dependency; source-tree
3631
+ // content does not otherwise participate in Run's cache key. Service
3632
+ // files are discovered recursively by the staging script, so rerun this
3633
+ // cheap copy step whenever the lane is requested rather than risk a stale
3634
+ // compiled host after an author edits a nested service module.
3635
+ stage.has_side_effects = true;
3636
+
3637
+ const compile = b.addSystemCommand(&.{node});
3638
+ compile.addFileArg(b.path("packages/core/scripts/run_external_service_compiler.mjs"));
3639
+ compile.addArg("--stage");
3640
+ compile.addDirectoryArg(stage_dir);
3641
+ compile.addArg("--manifest");
3642
+ compile.addFileArg(b.path("packages/core/package.json"));
3643
+ compile.addArg("--contract");
3644
+ compile.addFileArg(contract);
3645
+ // Mobile targets are archive-only (no child process exists there): the
3646
+ // driver refuses --out-exe, so the child-carrier batteries get a stub
3647
+ // path they never execute for those targets.
3648
+ const mobile_target = target.result.os.tag == .ios or target.result.abi.isAndroid();
3649
+ const executable: std.Build.LazyPath = if (mobile_target)
3650
+ b.addWriteFiles().add(b.fmt("{s}-unavailable-on-mobile", .{name}), "")
3651
+ else exe: {
3652
+ compile.addArg("--out-exe");
3653
+ const suffix = if (target.result.os.tag == .windows) ".exe" else "";
3654
+ break :exe compile.addOutputFileArg(b.fmt("{s}{s}", .{ name, suffix }));
3655
+ };
3656
+ const archive: ?std.Build.LazyPath = if (emit_archive) archive: {
3657
+ compile.addArg("--out-archive");
3658
+ break :archive compile.addOutputFileArg(b.fmt("lib{s}.a", .{name}));
3659
+ } else null;
3660
+ const host_platform = b.fmt("{t}-{t}-{t}", .{ b.graph.host.result.cpu.arch, b.graph.host.result.os.tag, b.graph.host.result.abi });
3661
+ compile.addArgs(&.{ "--host-platform", host_platform, "--target-platform", app_build.scriptcPlatformTriple(b, target), "--zig-exe", b.graph.zig_exe });
3662
+ app_build.addScriptcAndroidNdk(b, compile, target);
3663
+ addScriptcGlibcFloorTeaching(b, target, &compile.step);
3664
+ if (b.graph.environ_map.get("NATIVE_SDK_CORE_COMPILER")) |override| {
3665
+ compile.addArgs(&.{ "--compiler", override });
3666
+ } else {
3667
+ compile.addArg("--compiler-js");
3668
+ compile.addFileArg(b.path("packages/core/node_modules/scriptc/dist/main.js"));
3669
+ }
3670
+
3671
+ return .{
3672
+ .executable = executable,
3673
+ .archive = archive,
3674
+ .registry = b.createModule(.{
3675
+ .root_source_file = registry_source,
3676
+ .target = target,
3677
+ .optimize = optimize,
3678
+ }),
3679
+ };
3680
+ }
3681
+
3041
3682
  const FacadeProjections = struct {
3042
3683
  sidecar: std.Build.LazyPath,
3043
3684
  facade: std.Build.LazyPath,
@@ -3114,6 +3755,9 @@ const ExternalCoreFixture = struct {
3114
3755
  /// The archive's OWN co-emitted contract sidecar — the document its
3115
3756
  /// mirror must generate from (the boot identity fence pairs them).
3116
3757
  sidecar: std.Build.LazyPath,
3758
+ /// Present only for a two-class fixture that asks the frontend to emit the
3759
+ /// service registry sidecar from the same checked program.
3760
+ services_contract: ?std.Build.LazyPath,
3117
3761
  };
3118
3762
 
3119
3763
  const ExternalCoreFixtureSpec = struct {
@@ -3125,11 +3769,22 @@ const ExternalCoreFixtureSpec = struct {
3125
3769
  src_dir: std.Build.LazyPath,
3126
3770
  /// The archive's symbol-safe stem (`lib<name>.a`).
3127
3771
  name: []const u8,
3772
+ /// The fixture stands in for an app whose manifest declares Tier 1.
3773
+ persist_capability: bool = false,
3774
+ /// The fixture stands in for an app whose manifest declares Tier 2.
3775
+ store_capability: bool = false,
3776
+ /// The fixture stands in for an app whose manifest declares Tier 3.
3777
+ relational_capability: bool = false,
3778
+ /// The fixture stands in for an app whose manifest declares the Tier-4
3779
+ /// build capability and its matching core-effect permission.
3780
+ credentials_capability: bool = false,
3128
3781
  /// Attested integer slots the compiled projection carries as f64
3129
3782
  /// (values that reach the f64-exact boundary have no honest i64
3130
3783
  /// declaration on that side) — corewire's --f64-slot demotions,
3131
3784
  /// applied to the compile profile and every downstream projection.
3132
3785
  f64_slots: []const []const u8 = &.{},
3786
+ emit_services: bool = false,
3787
+ service_packages: []const []const u8 = &.{},
3133
3788
  };
3134
3789
 
3135
3790
  /// Compile one TS fixture core through the external core compiler at
@@ -3145,6 +3800,7 @@ fn externalCoreFixtureModule(
3145
3800
  corewire_exe: *std.Build.Step.Compile,
3146
3801
  spec: ExternalCoreFixtureSpec,
3147
3802
  ) ExternalCoreFixture {
3803
+ const app_build = @import("build/app.zig");
3148
3804
  // The frontend, in check-only mode: the subset checker gates the
3149
3805
  // compile, and the contract sidecar states the build-root-relative
3150
3806
  // entry spelling. The frontend reads its own sources, the SDK
@@ -3159,14 +3815,35 @@ fn externalCoreFixtureModule(
3159
3815
  const contract = check.addOutputFileArg("core.contract.json");
3160
3816
  check.addArg("--contract-entry");
3161
3817
  check.addArg(spec.entry);
3818
+ const services_contract: ?std.Build.LazyPath = if (spec.emit_services) services: {
3819
+ check.addArg("--services-contract");
3820
+ break :services check.addOutputFileArg("services.contract.json");
3821
+ } else null;
3822
+ for (spec.service_packages) |package_entry| check.addArgs(&.{ "--service-package", package_entry });
3823
+ const services_client: ?std.Build.LazyPath = if (services_contract) |service_contract| client: {
3824
+ const service_project = b.addRunArtifact(corewire_exe);
3825
+ service_project.addArg("--services-sidecar");
3826
+ service_project.addFileArg(service_contract);
3827
+ service_project.addArg("--service-client");
3828
+ break :client service_project.addOutputFileArg("services.gen.ts");
3829
+ } else null;
3830
+ if (spec.persist_capability) check.addArgs(&.{ "--capability", "persist" });
3831
+ if (spec.store_capability) check.addArgs(&.{ "--capability", "store" });
3832
+ if (spec.relational_capability) check.addArgs(&.{ "--capability", "sqlite" });
3833
+ if (spec.credentials_capability) check.addArgs(&.{ "--capability", "credentials", "--permission", "credentials" });
3834
+ if (std.mem.eql(u8, spec.entry, "tests/ts-core/fixture.ts")) check.addArgs(&.{ "--permission", "filesystem" });
3162
3835
  tsCoreAddDirInputs(b, check, "packages/core/sdk");
3163
3836
  tsCoreAddDirInputs(b, check, std.fs.path.dirname(spec.entry) orelse ".");
3164
3837
  const frontend_sources = [_][]const u8{
3165
- "checker.ts", "cli.ts", "contract.ts", "diagnostics.ts", "frontend.ts", "infer.ts", "modules.ts", "typed_ast.ts", "types.ts", "wyhash.ts",
3838
+ "checker.ts", "cli.ts", "contract.ts", "diagnostics.ts", "frontend.ts", "infer.ts", "modules.ts", "service_contract.ts", "sqlite_codegen.ts", "sqlite_cli.ts", "sqlite_runtime_policy.ts", "typed_ast.ts", "types.ts", "wyhash.ts",
3166
3839
  };
3167
3840
  for (frontend_sources) |source| {
3168
3841
  check.addFileInput(b.path(b.fmt("packages/core/src/{s}", .{source})));
3169
3842
  }
3843
+ // Service contracts echo the exact scriptc pin read from this manifest.
3844
+ // Declare that runtime read explicitly so a compiler bump invalidates a
3845
+ // warm build cache before the compile lane checks the echoed version.
3846
+ if (spec.emit_services) check.addFileInput(b.path("packages/core/package.json"));
3170
3847
 
3171
3848
  // corewire projects the generated compile entry and its profile in
3172
3849
  // one invocation, so the profile's entry spelling and the facade
@@ -3197,6 +3874,10 @@ fn externalCoreFixtureModule(
3197
3874
  stage_run.addFileArg(facade);
3198
3875
  stage_run.addArg("--profile");
3199
3876
  stage_run.addFileArg(profile);
3877
+ if (services_client) |client| {
3878
+ stage_run.addArg("--services-client");
3879
+ stage_run.addFileArg(client);
3880
+ }
3200
3881
  stage_run.addArg("--out");
3201
3882
  const stage_dir = stage_run.addOutputDirectoryArg("stage");
3202
3883
 
@@ -3209,10 +3890,22 @@ fn externalCoreFixtureModule(
3209
3890
  compile.addArgs(&.{ "--name", spec.name });
3210
3891
  compile.addArg("--manifest");
3211
3892
  compile.addFileArg(b.path("packages/core/package.json"));
3893
+ compile.addArg("--frontend-sidecar");
3894
+ compile.addFileArg(contract);
3212
3895
  compile.addArg("--out-archive");
3213
3896
  const archive = compile.addOutputFileArg(b.fmt("lib{s}.a", .{spec.name}));
3214
3897
  compile.addArg("--out-sidecar");
3215
3898
  const compiled_sidecar = compile.addOutputFileArg("core.contract.json");
3899
+ compile.addArgs(&.{
3900
+ "--host-platform",
3901
+ b.fmt("{t}-{t}-{t}", .{ b.graph.host.result.cpu.arch, b.graph.host.result.os.tag, b.graph.host.result.abi }),
3902
+ "--target-platform",
3903
+ app_build.scriptcPlatformTriple(b, target),
3904
+ "--zig-exe",
3905
+ b.graph.zig_exe,
3906
+ });
3907
+ app_build.addScriptcAndroidNdk(b, compile, target);
3908
+ addScriptcGlibcFloorTeaching(b, target, &compile.step);
3216
3909
  if (b.graph.environ_map.get("NATIVE_SDK_CORE_COMPILER")) |override| {
3217
3910
  // The development override: point at any toolchain command; the
3218
3911
  // driver still refuses a release other than the SDK's pin.
@@ -3241,24 +3934,29 @@ fn externalCoreFixtureModule(
3241
3934
  });
3242
3935
  mod.link_libc = true;
3243
3936
  mod.addObjectFile(archive);
3937
+ addScriptcArchiveSystemLibs(mod, target);
3244
3938
  return .{
3245
3939
  .module = mod,
3246
3940
  .contract = contract,
3247
3941
  .archive = archive,
3248
3942
  .sidecar = compiled_sidecar,
3943
+ .services_contract = services_contract,
3249
3944
  };
3250
3945
  }
3251
3946
 
3252
- /// Declare every .ts file in `dir_path` (relative to the build root) as a
3253
- /// file input of the transpile step — the multi-file staleness set.
3947
+ /// Declare every .ts file under `dir_path` (relative to the build root) as a
3948
+ /// file input of the transpile step — the recursive multi-file staleness set.
3949
+ /// Service modules live below src/services/, so a flat scan would let their
3950
+ /// generated contract stay stale in a warm fixture build.
3254
3951
  fn tsCoreAddDirInputs(b: *std.Build, transpile: *std.Build.Step.Run, dir_path: []const u8) void {
3255
3952
  var dir = b.build_root.handle.openDir(b.graph.io, dir_path, .{ .iterate = true }) catch return;
3256
3953
  defer dir.close(b.graph.io);
3257
- var it = dir.iterate();
3258
- while (it.next(b.graph.io) catch null) |entry| {
3954
+ var walker = dir.walk(b.allocator) catch return;
3955
+ defer walker.deinit();
3956
+ while (walker.next(b.graph.io) catch null) |entry| {
3259
3957
  if (entry.kind != .file) continue;
3260
- if (!std.mem.endsWith(u8, entry.name, ".ts")) continue;
3261
- transpile.addFileInput(b.path(b.fmt("{s}/{s}", .{ dir_path, entry.name })));
3958
+ if (!std.mem.endsWith(u8, entry.basename, ".ts")) continue;
3959
+ transpile.addFileInput(b.path(b.fmt("{s}/{s}", .{ dir_path, entry.path })));
3262
3960
  }
3263
3961
  }
3264
3962