@native-sdk/cli 0.5.4 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/build/app.zig +50 -1
  2. package/build.zig +534 -3
  3. package/build.zig.zon +7 -0
  4. package/native-sdk.d.ts +3 -1
  5. package/package.json +9 -9
  6. package/packages/core/package-lock.json +2 -2
  7. package/packages/core/package.json +1 -1
  8. package/packages/core/rt/rt.zig +280 -8
  9. package/packages/core/sdk/core.ts +481 -2
  10. package/packages/core/sdk/events.ts +17 -8
  11. package/packages/core/src/checker.ts +305 -2
  12. package/packages/core/src/diagnostics.ts +12 -0
  13. package/packages/core/src/emitter.ts +599 -3
  14. package/packages/core/src/typed_ast.ts +51 -4
  15. package/packages/core/src/types.ts +34 -1
  16. package/skill-data/native-ui/SKILL.md +39 -2
  17. package/skill-data/ts-core/SKILL.md +4 -2
  18. package/src/app_runner/root.zig +32 -10
  19. package/src/automation/layout_fingerprint.zig +160 -0
  20. package/src/automation/protocol.zig +82 -33
  21. package/src/automation/root.zig +1 -0
  22. package/src/automation/server.zig +1 -1
  23. package/src/automation/snapshot.zig +68 -9
  24. package/src/automation/watcher.zig +1 -1
  25. package/src/embed/host.zig +5 -0
  26. package/src/embed/ui_host.zig +13 -0
  27. package/src/platform/linux/gtk_host.c +527 -13
  28. package/src/platform/linux/gtk_host.h +25 -0
  29. package/src/platform/linux/root.zig +280 -7
  30. package/src/platform/macos/appkit_host.h +104 -6
  31. package/src/platform/macos/appkit_host.m +1283 -66
  32. package/src/platform/macos/cef_host.mm +110 -1
  33. package/src/platform/macos/root.zig +287 -7
  34. package/src/platform/null_platform.zig +398 -4
  35. package/src/platform/null_platform_tests.zig +35 -0
  36. package/src/platform/root.zig +9 -0
  37. package/src/platform/types.zig +386 -14
  38. package/src/platform/windows/root.zig +298 -9
  39. package/src/platform/windows/webview2_host.cpp +330 -5
  40. package/src/primitives/app_manifest/validation.zig +18 -0
  41. package/src/primitives/canvas/a11y_audit.zig +33 -11
  42. package/src/primitives/canvas/a11y_audit_tests.zig +20 -0
  43. package/src/primitives/canvas/drawing.zig +25 -0
  44. package/src/primitives/canvas/equality.zig +8 -0
  45. package/src/primitives/canvas/events.zig +103 -16
  46. package/src/primitives/canvas/frame.zig +125 -1
  47. package/src/primitives/canvas/layout_audit.zig +22 -5
  48. package/src/primitives/canvas/markdown_hostile_tests.zig +8 -4
  49. package/src/primitives/canvas/render_tests.zig +13 -10
  50. package/src/primitives/canvas/root.zig +48 -0
  51. package/src/primitives/canvas/terminal_box.zig +471 -0
  52. package/src/primitives/canvas/terminal_grid.zig +978 -0
  53. package/src/primitives/canvas/terminal_grid_tests.zig +1093 -0
  54. package/src/primitives/canvas/test_support.zig +1 -0
  55. package/src/primitives/canvas/tests.zig +1 -0
  56. package/src/primitives/canvas/text_tests.zig +39 -4
  57. package/src/primitives/canvas/tokens.zig +115 -12
  58. package/src/primitives/canvas/ui.zig +524 -5
  59. package/src/primitives/canvas/ui_markup.zig +195 -2
  60. package/src/primitives/canvas/ui_markup_compiled.zig +172 -1
  61. package/src/primitives/canvas/ui_markup_compiled_tests.zig +133 -8
  62. package/src/primitives/canvas/ui_markup_contract.zig +88 -5
  63. package/src/primitives/canvas/ui_markup_contract_tests.zig +39 -1
  64. package/src/primitives/canvas/ui_markup_huge_model_tests.zig +1 -0
  65. package/src/primitives/canvas/ui_markup_reflect.zig +75 -24
  66. package/src/primitives/canvas/ui_markup_tests.zig +149 -0
  67. package/src/primitives/canvas/ui_markup_view.zig +191 -0
  68. package/src/primitives/canvas/ui_markup_view_tests.zig +403 -19
  69. package/src/primitives/canvas/ui_schema.zig +97 -17
  70. package/src/primitives/canvas/ui_schema_tests.zig +18 -11
  71. package/src/primitives/canvas/ui_tests.zig +141 -9
  72. package/src/primitives/canvas/widget_access.zig +28 -2
  73. package/src/primitives/canvas/widget_anchored_tests.zig +48 -0
  74. package/src/primitives/canvas/widget_invalidation.zig +81 -1
  75. package/src/primitives/canvas/widget_layout.zig +59 -11
  76. package/src/primitives/canvas/widget_layout_tests.zig +125 -4
  77. package/src/primitives/canvas/widget_render.zig +272 -18
  78. package/src/primitives/canvas/widget_render_scroll.zig +108 -27
  79. package/src/primitives/canvas/widget_routing.zig +59 -7
  80. package/src/primitives/canvas/widget_runtime.zig +23 -0
  81. package/src/primitives/canvas/widget_runtime_tests.zig +149 -0
  82. package/src/primitives/canvas/widget_semantics.zig +119 -11
  83. package/src/primitives/canvas/widget_semantics_tests.zig +409 -0
  84. package/src/primitives/canvas/widget_tree.zig +17 -0
  85. package/src/primitives/canvas/widgets.zig +132 -0
  86. package/src/root.zig +16 -0
  87. package/src/runtime/api.zig +70 -1
  88. package/src/runtime/automation_commands.zig +20 -1
  89. package/src/runtime/automation_snapshot.zig +25 -1
  90. package/src/runtime/automation_widget_dispatch.zig +73 -8
  91. package/src/runtime/bridge_payload.zig +1 -0
  92. package/src/runtime/canvas_frame.zig +62 -7
  93. package/src/runtime/canvas_frame_animation_tests.zig +5 -4
  94. package/src/runtime/canvas_frame_helpers.zig +190 -1
  95. package/src/runtime/canvas_frame_invalidation_tests.zig +531 -0
  96. package/src/runtime/canvas_frame_patch_tests.zig +161 -10
  97. package/src/runtime/canvas_frame_retained_tests.zig +5 -2
  98. package/src/runtime/canvas_widget_accessibility_tests.zig +1 -1
  99. package/src/runtime/canvas_widget_clipboard_tests.zig +40 -0
  100. package/src/runtime/canvas_widget_context_menu.zig +269 -32
  101. package/src/runtime/canvas_widget_context_menu_tests.zig +640 -14
  102. package/src/runtime/canvas_widget_display.zig +1 -1
  103. package/src/runtime/canvas_widget_event_tests.zig +1823 -0
  104. package/src/runtime/canvas_widget_events.zig +240 -24
  105. package/src/runtime/canvas_widget_runtime.zig +213 -29
  106. package/src/runtime/canvas_widget_scroll_driver_tests.zig +170 -7
  107. package/src/runtime/canvas_widget_scroll_drivers.zig +151 -17
  108. package/src/runtime/canvas_widget_scroll_tests.zig +435 -23
  109. package/src/runtime/canvas_widget_state.zig +6 -0
  110. package/src/runtime/canvas_widget_text_tests.zig +1 -1
  111. package/src/runtime/core.zig +73 -2
  112. package/src/runtime/effects.zig +6389 -54
  113. package/src/runtime/effects_channel_tests.zig +3519 -0
  114. package/src/runtime/effects_pty_tests.zig +1362 -0
  115. package/src/runtime/effects_tests.zig +14 -9
  116. package/src/runtime/effects_video_tests.zig +3609 -0
  117. package/src/runtime/flow.zig +25 -4
  118. package/src/runtime/gpu_surface_events.zig +473 -13
  119. package/src/runtime/media_surface.zig +116 -11
  120. package/src/runtime/media_surface_tests.zig +61 -0
  121. package/src/runtime/pty.zig +1252 -0
  122. package/src/runtime/pty_windows.zig +1780 -0
  123. package/src/runtime/root.zig +25 -0
  124. package/src/runtime/runtime_event_tests.zig +20 -1
  125. package/src/runtime/session_journal.zig +367 -61
  126. package/src/runtime/session_record.zig +16 -0
  127. package/src/runtime/session_replay.zig +395 -11
  128. package/src/runtime/session_tests.zig +109 -15
  129. package/src/runtime/terminal_session.zig +1569 -0
  130. package/src/runtime/terminal_session_tests.zig +450 -0
  131. package/src/runtime/terminal_vt_ghostty.zig +15 -0
  132. package/src/runtime/terminal_vt_stub.zig +13 -0
  133. package/src/runtime/tests.zig +6 -0
  134. package/src/runtime/ts_core_host.zig +980 -140
  135. package/src/runtime/ts_core_host_tests.zig +1059 -1
  136. package/src/runtime/ts_ui_app.zig +16 -5
  137. package/src/runtime/ui_app.zig +2333 -63
  138. package/src/runtime/ui_app_tests.zig +3171 -744
  139. package/src/runtime/ui_app_virtual_variable_tests.zig +4 -2
  140. package/src/runtime/ui_app_window_tests.zig +268 -0
  141. package/src/runtime/view.zig +190 -2
  142. package/src/runtime/view_widget_scroll.zig +218 -68
  143. package/src/runtime/view_widget_text.zig +11 -2
  144. package/src/runtime/view_widget_tree.zig +111 -3
  145. package/src/runtime/window_storage.zig +45 -2
  146. package/src/runtime/window_view_runtime.zig +34 -2
  147. package/src/runtime/window_views.zig +1 -0
  148. package/src/terminal_session_tests_root.zig +15 -0
  149. package/src/tooling/templates.zig +25 -7
package/build.zig CHANGED
@@ -138,6 +138,7 @@ pub fn build(b: *std.Build) void {
138
138
  desktop_mod.addImport("platform_info", platform_info_mod);
139
139
  desktop_mod.addImport("json", json_mod);
140
140
  desktop_mod.addImport("canvas", canvas_mod);
141
+ desktop_mod.addImport("terminal_vt", terminalVtModule(b, target, optimize));
141
142
  const desktop_tests = testArtifact(b, desktop_mod);
142
143
  const desktop_test_shards = desktopTestShardArtifacts(b, desktop_mod);
143
144
 
@@ -195,6 +196,24 @@ pub fn build(b: *std.Build) void {
195
196
  eject_components_mod.addImport("native_sdk", desktop_mod);
196
197
  const eject_components_tests = testArtifact(b, eject_components_mod);
197
198
 
199
+ // corewire, the contract-sidecar shim generator (tools/corewire):
200
+ // std-only unit suites, one test root per source file (tests live
201
+ // in the file they cover, and imported files' tests do not run
202
+ // under an importer's root). The conformance suite — both lanes per
203
+ // ts-core fixture, compared by layout fingerprint and
204
+ // model-contract artifact — rides the ts-core e2e block, since it
205
+ // needs node and the transpiler toolchain.
206
+ const corewire_sidecar_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/sidecar.zig"));
207
+ const corewire_emit_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/emit.zig"));
208
+ const corewire_facade_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/emit_facade.zig"));
209
+ const corewire_profile_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/emit_profile.zig"));
210
+ const corewire_extract_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/extract.zig"));
211
+ const corewire_shim_rt_tests = testArtifact(b, module(b, target, optimize, "tools/corewire/shim_rt.zig"));
212
+ // The paired-core root generator (tests/compiled-core): its emitted
213
+ // surface rules are pinned here so the env-gated batteries cannot
214
+ // drift silently between supplied-archive runs.
215
+ const gen_paired_tests = testArtifact(b, module(b, target, optimize, "tests/compiled-core/gen_paired.zig"));
216
+
198
217
  // Transpiled-core end-to-end suite: tests/ts-core/fixture.ts is
199
218
  // emitted by the repo's own transpiler AT BUILD TIME (never a
200
219
  // committed Zig snapshot) and driven through the real runtime via
@@ -359,6 +378,10 @@ pub fn build(b: *std.Build) void {
359
378
  wasm_native_mod.addImport("app_manifest", module(b, wasm_target, wasm_optimize, "src/primitives/app_manifest/root.zig"));
360
379
  wasm_native_mod.addImport("diagnostics", module(b, wasm_target, wasm_optimize, "src/primitives/diagnostics/root.zig"));
361
380
  wasm_native_mod.addImport("platform_info", module(b, wasm_target, wasm_optimize, "src/primitives/platform_info/root.zig"));
381
+ // The docs preview never runs an emulator: the stub keeps the wasm
382
+ // module free of the ghostty graph (and of pty transports it could
383
+ // not use anyway).
384
+ wasm_native_mod.addImport("terminal_vt", module(b, wasm_target, wasm_optimize, "src/runtime/terminal_vt_stub.zig"));
362
385
  const docs_wasm_preview_mod = module(b, wasm_target, wasm_optimize, "tools/docs_wasm_preview.zig");
363
386
  docs_wasm_preview_mod.addImport("native_sdk", wasm_native_mod);
364
387
  docs_wasm_preview_mod.strip = true;
@@ -386,9 +409,41 @@ pub fn build(b: *std.Build) void {
386
409
  // Registry pin printer: emits the ui_schema table counts and
387
410
  // fingerprints in the exact form ui_schema_tests.zig pins, plus the
388
411
  // next free code per table for reserving codes ahead of parallel
389
- // work. `zig build print-pins` after registry additions.
412
+ // work, plus this build's layout fingerprints (session journal
413
+ // format, automation protocol). `zig build print-pins` after
414
+ // registry additions. The journal fingerprint lives in the full
415
+ // framework module, and the tool runs on the build HOST by
416
+ // construction (addRunArtifact), so it builds against a host clone
417
+ // of the framework module — cross-compiled `-Dtarget` builds keep a
418
+ // runnable print-pins, and the fingerprints are layout identities
419
+ // (type shapes, never target-sized values), identical either way.
420
+ const pins_json_mod = module(b, host_target, optimize, "src/primitives/json/root.zig");
421
+ const pins_canvas_mod = module(b, host_target, optimize, "src/primitives/canvas/root.zig");
422
+ pins_canvas_mod.addImport("geometry", host_geometry_mod);
423
+ pins_canvas_mod.addImport("json", pins_json_mod);
424
+ if (host_target.result.os.tag == .macos) {
425
+ // Same CoreText linkage the target canvas module carries (see
426
+ // canvas_mod above): the shaping path calls it on macOS hosts.
427
+ pins_canvas_mod.linkFramework("CoreFoundation", .{});
428
+ pins_canvas_mod.linkFramework("CoreGraphics", .{});
429
+ pins_canvas_mod.linkFramework("CoreText", .{});
430
+ pins_canvas_mod.linkSystemLibrary("c", .{});
431
+ }
432
+ const pins_native_mod = module(b, host_target, optimize, "src/root.zig");
433
+ pins_native_mod.addImport("geometry", host_geometry_mod);
434
+ pins_native_mod.addImport("app_dirs", host_app_dirs_mod);
435
+ pins_native_mod.addImport("assets", host_assets_mod);
436
+ pins_native_mod.addImport("trace", host_trace_mod);
437
+ pins_native_mod.addImport("app_manifest", host_app_manifest_mod);
438
+ pins_native_mod.addImport("diagnostics", host_diagnostics_mod);
439
+ pins_native_mod.addImport("platform_info", host_platform_info_mod);
440
+ pins_native_mod.addImport("json", pins_json_mod);
441
+ pins_native_mod.addImport("canvas", pins_canvas_mod);
442
+ // The pin printer reflects registry tables and layout fingerprints —
443
+ // type shapes, never emulator state — so the stub keeps it light.
444
+ pins_native_mod.addImport("terminal_vt", module(b, host_target, optimize, "src/runtime/terminal_vt_stub.zig"));
390
445
  const print_pins_mod = module(b, host_target, optimize, "tools/print_pins.zig");
391
- print_pins_mod.addImport("ui_schema", module(b, host_target, optimize, "src/primitives/canvas/ui_schema.zig"));
446
+ print_pins_mod.addImport("native_sdk", pins_native_mod);
392
447
  const print_pins_exe = b.addExecutable(.{
393
448
  .name = "print-pins",
394
449
  .root_module = print_pins_mod,
@@ -422,6 +477,13 @@ pub fn build(b: *std.Build) void {
422
477
  test_step.dependOn(&b.addRunArtifact(automation_protocol_tests).step);
423
478
  test_step.dependOn(&b.addRunArtifact(tooling_tests).step);
424
479
  test_step.dependOn(&b.addRunArtifact(eject_components_tests).step);
480
+ test_step.dependOn(&b.addRunArtifact(corewire_sidecar_tests).step);
481
+ test_step.dependOn(&b.addRunArtifact(corewire_emit_tests).step);
482
+ test_step.dependOn(&b.addRunArtifact(corewire_facade_tests).step);
483
+ test_step.dependOn(&b.addRunArtifact(corewire_profile_tests).step);
484
+ test_step.dependOn(&b.addRunArtifact(corewire_extract_tests).step);
485
+ test_step.dependOn(&b.addRunArtifact(corewire_shim_rt_tests).step);
486
+ test_step.dependOn(&b.addRunArtifact(gen_paired_tests).step);
425
487
  if (ts_core_e2e_tests) |ts_core_artifacts| {
426
488
  const ts_core_e2e_step = b.step("test-ts-core-e2e", "Run the transpiled-core end-to-end suites (requires node)");
427
489
  const host_e2e_run = b.addRunArtifact(ts_core_artifacts.host);
@@ -432,6 +494,37 @@ pub fn build(b: *std.Build) void {
432
494
  // no build inputs/outputs to hash, so always run it.
433
495
  scaffold_ide_e2e_run.has_side_effects = true;
434
496
  const ai_chat_e2e_run = b.addRunArtifact(ts_core_artifacts.ai_chat);
497
+ const sidecar_conformance_run = b.addRunArtifact(ts_core_artifacts.sidecar_conformance);
498
+ const sidecar_conformance_step = b.step("sidecar-conformance", "Prove corewire-generated mirrors fingerprint-identical to transpiler output (requires node)");
499
+ sidecar_conformance_step.dependOn(&sidecar_conformance_run.step);
500
+ // Skipped unless the caller supplies a compiled-core archive:
501
+ // the repo builds none, so the step gates on the env var and
502
+ // `zig build test` stays green without it.
503
+ const parity_step = b.step("test-external-core-parity", "Run the compiled-core behavior-parity suite (requires node and NATIVE_SDK_EXTERNAL_CORE_ARCHIVE=<link input[" ++ [_]u8{std.fs.path.delimiter} ++ "link input...]>; skipped when unset)");
504
+ if (ts_core_artifacts.external_core_parity) |parity_tests| {
505
+ const parity_run = b.addRunArtifact(parity_tests);
506
+ parity_step.dependOn(&parity_run.step);
507
+ test_step.dependOn(&parity_run.step);
508
+ }
509
+ // The full-corpus twin: each fixture app's e2e battery over a
510
+ // paired core, gated per fixture on its archive/sidecar env
511
+ // pair; with none supplied the step is a clean no-op and
512
+ // `zig build test` is untouched.
513
+ const compiled_parity_step = b.step("test-compiled-core-parity", "Run each fixture app's e2e battery over a paired core — transpiled lane vs a caller-supplied compiled-core archive (requires node and NATIVE_SDK_EXTERNAL_CORE_ARCHIVE_<FIXTURE> + NATIVE_SDK_EXTERNAL_CORE_SIDECAR_<FIXTURE>; fixtures without both are skipped)");
514
+ for (ts_core_artifacts.compiled_core_parity) |battery| {
515
+ const battery_run = b.addRunArtifact(battery.tests);
516
+ compiled_parity_step.dependOn(&battery_run.step);
517
+ test_step.dependOn(&battery_run.step);
518
+ }
519
+ // The corpus contract artifacts an external core toolchain
520
+ // consumes: per fixture, the extracted contract sidecar and its
521
+ // TypeScript facade projection under zig-out/core-contracts.
522
+ const contracts_step = b.step("stage-core-contracts", "Install each ts-core fixture's contract sidecar and TypeScript facade projection under zig-out/core-contracts (requires node)");
523
+ for (ts_core_artifacts.core_contracts) |contract| {
524
+ const dir: std.Build.InstallDir = .{ .custom = b.fmt("core-contracts/{s}", .{contract.name}) };
525
+ contracts_step.dependOn(&b.addInstallFileWithDir(contract.sidecar, dir, "core.contract.json").step);
526
+ contracts_step.dependOn(&b.addInstallFileWithDir(contract.facade, dir, "core_facade.ts").step);
527
+ }
435
528
  ts_core_e2e_step.dependOn(&host_e2e_run.step);
436
529
  ts_core_e2e_step.dependOn(&soundboard_e2e_run.step);
437
530
  ts_core_e2e_step.dependOn(&monitor_e2e_run.step);
@@ -442,6 +535,7 @@ pub fn build(b: *std.Build) void {
442
535
  test_step.dependOn(&monitor_e2e_run.step);
443
536
  test_step.dependOn(&scaffold_ide_e2e_run.step);
444
537
  test_step.dependOn(&ai_chat_e2e_run.step);
538
+ test_step.dependOn(&sidecar_conformance_run.step);
445
539
  }
446
540
  test_step.dependOn(&b.addRunArtifact(markup_lsp_tests).step);
447
541
  test_step.dependOn(&b.addRunArtifact(automation_cli_tests).step);
@@ -550,7 +644,7 @@ pub fn build(b: *std.Build) void {
550
644
  .{ .path = "src/runtime/media_surface_tests.zig", .pattern = "producer: media.MediaSurfaceProducer" },
551
645
  });
552
646
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-session-replay-image-codec", "Verify the replay runner installs the host image codec headlessly (the desktop arms cannot link in unit tests; the null-fallback arm is covered in session_tests.zig)", &.{
553
- .{ .path = "src/app_runner/root.zig", .pattern = "native_sdk.platform.installHeadlessImageCodec(build_options.platform, &null_platform, &replay_platform.services);" },
647
+ .{ .path = "src/app_runner/root.zig", .pattern = "native_sdk.platform.installHeadlessImageCodec(build_options.platform, null_platform, &replay_platform.services);" },
554
648
  .{ .path = "src/platform/macos/root.zig", .pattern = "pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {\n services.decode_image_fn = decodeImage;\n}" },
555
649
  .{ .path = "src/platform/linux/root.zig", .pattern = "pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {\n services.decode_image_fn = decodeImage;\n}" },
556
650
  .{ .path = "src/platform/windows/root.zig", .pattern = "pub fn installHeadlessImageCodec(services: *platform_mod.PlatformServices) void {\n services.decode_image_fn = decodeImage;\n}" },
@@ -1097,6 +1191,11 @@ pub fn build(b: *std.Build) void {
1097
1191
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "- (void)selectAll:(id)sender" },
1098
1192
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "@selector(selectAll:)" },
1099
1193
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "emitSyntheticKeyDownWithKey:@\"a\" modifiers:(NativeSdkShortcutModifierPrimary | NativeSdkShortcutModifierCommand)" },
1194
+ // Modified horizontal navigation must bypass AppKit's selector
1195
+ // rewrite: the shared editor consumes the raw modifiers, and a
1196
+ // terminal translates them to its shell/protocol bindings.
1197
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkTextNavigationNeedsRawKeyEvent(event)" },
1198
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NSEventModifierFlagCommand | NSEventModifierFlagOption" },
1100
1199
  });
1101
1200
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-appearance-bridge", "Verify AppKit reports system light and dark appearance changes", &.{
1102
1201
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "effectiveAppearance" },
@@ -1259,6 +1358,7 @@ pub fn build(b: *std.Build) void {
1259
1358
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-kanban", "Run ui builder kanban example tests", "examples/kanban", .managed);
1260
1359
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-habits", "Run markup habits example tests", "examples/habits", .managed);
1261
1360
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard", "Run soundboard example tests", "examples/soundboard", .managed);
1361
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-video-player", "Run video player example tests", "examples/video-player", .managed);
1262
1362
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard-ts", "Run soundboard-ts example tests", "examples/soundboard-ts", .managed);
1263
1363
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-deck", "Run deck example tests", "examples/deck", .managed);
1264
1364
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-markdown-viewer", "Run markdown viewer example tests", "examples/markdown-viewer", .managed);
@@ -1266,8 +1366,11 @@ pub fn build(b: *std.Build) void {
1266
1366
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-notes", "Run notes example tests", "examples/notes", .managed);
1267
1367
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-split-collapse", "Run split collapse example tests", "examples/split-collapse", .managed);
1268
1368
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor", "Run system monitor example tests", "examples/system-monitor", .managed);
1369
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-terminal", "Run terminal example tests", "examples/terminal", .owned);
1370
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-workbench", "Run workbench example tests", "examples/workbench", .owned);
1269
1371
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-system-monitor-ts", "Run system-monitor-ts example tests", "examples/system-monitor-ts", .managed);
1270
1372
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-effects-probe", "Run effects probe example tests", "examples/effects-probe", .managed);
1373
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-channel-monitor", "Run channel monitor example tests", "examples/channel-monitor", .managed);
1271
1374
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-menu-bar", "Run menu-bar lifecycle example tests", "examples/menu-bar", .managed);
1272
1375
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-feed", "Run feed example tests", "examples/feed", .managed);
1273
1376
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-canvas-preview", "Run canvas preview example tests", "examples/canvas-preview", .managed);
@@ -2768,6 +2871,19 @@ fn module(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin
2768
2871
  });
2769
2872
  }
2770
2873
 
2874
+ /// The framework module's `terminal_vt` import for THIS repository's own
2875
+ /// builds: always the stub. The emulator (libghostty-vt) is pinned by
2876
+ /// the APPS that want live `<terminal>` sessions, never by this package
2877
+ /// — a pin in `build.zig.zon` is materialized into every consumer's
2878
+ /// package directory even when lazy and unused, and ghostty's own graph
2879
+ /// walks translate_c/wuffs and pulls harfbuzz, which is exactly what a
2880
+ /// scaffolded app must never carry. `AppOptions.terminal_sessions`
2881
+ /// resolves the app's own pin (see build/app.zig), and the terminal
2882
+ /// examples own the enabled path's test coverage.
2883
+ fn terminalVtModule(b: *std.Build, target: std.Build.ResolvedTarget, optimize: std.builtin.OptimizeMode) *std.Build.Module {
2884
+ return module(b, target, optimize, "src/runtime/terminal_vt_stub.zig");
2885
+ }
2886
+
2771
2887
  /// The short commit hash of the framework checkout the CLI is built
2772
2888
  /// from, for `native version` staleness checks. "unknown" when
2773
2889
  /// git is unavailable (e.g. building from a package tarball).
@@ -2801,8 +2917,71 @@ const TsCoreE2eArtifacts = struct {
2801
2917
  /// paths, and builds keep working with node_modules deleted.
2802
2918
  scaffold_ide: *std.Build.Step.Compile,
2803
2919
  ai_chat: *std.Build.Step.Compile,
2920
+ /// Sidecar-shim conformance (tests/sidecar): every fixture built
2921
+ /// through BOTH lanes — the transpiler and corewire's generated
2922
+ /// mirror — and compared by layout fingerprint and model-contract
2923
+ /// artifact.
2924
+ sidecar_conformance: *std.Build.Step.Compile,
2925
+ /// Behavior parity against a REAL compiled core: built only when
2926
+ /// NATIVE_SDK_EXTERNAL_CORE_ARCHIVE names the archive(s) to link
2927
+ /// (path-delimiter-separated link inputs exporting the markup
2928
+ /// fixture's attested symbol set); null — the suite is skipped —
2929
+ /// otherwise.
2930
+ external_core_parity: ?*std.Build.Step.Compile,
2931
+ /// The full-corpus compiled-core batteries: each entry is one
2932
+ /// fixture app's OWN e2e suite compiled over a paired core — the
2933
+ /// transpiled lane plus a generated mirror dispatching into a
2934
+ /// caller-supplied compiled-core archive, byte-compared at every
2935
+ /// seam. Built per fixture only when its archive/sidecar env pair
2936
+ /// (NATIVE_SDK_EXTERNAL_CORE_ARCHIVE_<FIXTURE> and
2937
+ /// NATIVE_SDK_EXTERNAL_CORE_SIDECAR_<FIXTURE>) is supplied; empty
2938
+ /// — every battery skipped — otherwise.
2939
+ compiled_core_parity: []const CompiledCoreParity,
2940
+ /// Per-fixture contract artifacts for an external core toolchain:
2941
+ /// the extracted contract sidecar and its TypeScript facade
2942
+ /// projection, installed by the stage-core-contracts step.
2943
+ core_contracts: []const CoreContract,
2944
+ };
2945
+
2946
+ const CompiledCoreParity = struct {
2947
+ name: []const u8,
2948
+ tests: *std.Build.Step.Compile,
2949
+ };
2950
+
2951
+ const CoreContract = struct {
2952
+ name: []const u8,
2953
+ sidecar: std.Build.LazyPath,
2954
+ facade: std.Build.LazyPath,
2804
2955
  };
2805
2956
 
2957
+ /// One fixture's compiled-core supply: the archive link input(s) and
2958
+ /// the archive's own emitted contract sidecar. Both come as a pair —
2959
+ /// a real archive's build_id can only match its co-emitted sidecar, so
2960
+ /// one without the other is a misconfiguration, refused with a
2961
+ /// teaching rather than skipped into silence.
2962
+ const CompiledCoreSupply = struct {
2963
+ archives: []const u8,
2964
+ sidecar: std.Build.LazyPath,
2965
+ };
2966
+
2967
+ fn compiledCoreEnv(b: *std.Build, comptime suffix: []const u8) ?CompiledCoreSupply {
2968
+ const archive_var = "NATIVE_SDK_EXTERNAL_CORE_ARCHIVE_" ++ suffix;
2969
+ const sidecar_var = "NATIVE_SDK_EXTERNAL_CORE_SIDECAR_" ++ suffix;
2970
+ const archives = b.graph.environ_map.get(archive_var);
2971
+ const sidecar = b.graph.environ_map.get(sidecar_var);
2972
+ if (archives == null and sidecar == null) return null;
2973
+ if (archives == null or sidecar == null) {
2974
+ std.debug.panic(
2975
+ "{s} and {s} come as a pair: a compiled-core fixture needs both its archive link input(s) and the archive's own emitted contract sidecar",
2976
+ .{ archive_var, sidecar_var },
2977
+ );
2978
+ }
2979
+ return .{
2980
+ .archives = b.dupe(archives.?),
2981
+ .sidecar = .{ .cwd_relative = b.dupe(sidecar.?) },
2982
+ };
2983
+ }
2984
+
2806
2985
  fn tsCoreE2eArtifact(
2807
2986
  b: *std.Build,
2808
2987
  target: std.Build.ResolvedTarget,
@@ -2883,13 +3062,365 @@ fn tsCoreE2eArtifact(
2883
3062
  ai_chat_mod.addImport("native_sdk", desktop_mod);
2884
3063
  ai_chat_mod.addImport("ts_ai_chat_core", ai_chat_core_mod);
2885
3064
 
3065
+ // Sidecar-shim conformance: pair every fixture's transpiled module
3066
+ // with a corewire-generated mirror. The markup fixture's sidecar is
3067
+ // the committed hand-written one (independent ground truth for the
3068
+ // schema); the rest are extracted from the transpiled modules at
3069
+ // build time, so corpus fixtures cannot go stale against their
3070
+ // sidecars.
3071
+ const corewire_mod = b.createModule(.{
3072
+ .root_source_file = b.path("tools/corewire/main.zig"),
3073
+ .target = target,
3074
+ .optimize = optimize,
3075
+ });
3076
+ const corewire_exe = b.addExecutable(.{
3077
+ .name = "corewire",
3078
+ .root_module = corewire_mod,
3079
+ .use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
3080
+ });
3081
+ const extract_mod = module(b, target, optimize, "tools/corewire/extract.zig");
3082
+
3083
+ const conformance_mod = module(b, target, optimize, "tests/sidecar/conformance_tests.zig");
3084
+ conformance_mod.addImport("native_sdk", desktop_mod);
3085
+ // The canonical value encoder the facade parity axis compares
3086
+ // against (the same module the generated shims stage).
3087
+ conformance_mod.addImport("corewire_rt", module(b, target, optimize, "tools/corewire/shim_rt.zig"));
3088
+ conformance_mod.addImport("ts_markup_core", markup_fixture_mod);
3089
+ conformance_mod.addImport("shim_markup_core", sidecarShimModule(b, target, optimize, corewire_exe, b.path("tests/sidecar/markup_fixture.contract.json")));
3090
+ conformance_mod.addImport("facade_markup_core", facadeCoreModule(b, target, optimize, node, corewire_exe, b.path("tests/sidecar/markup_fixture.contract.json")));
3091
+ // The integer-class fixture: a hand-written sidecar attesting mixed
3092
+ // i64/u64 slot classes, so the suite drives boundary and full-range
3093
+ // integer values through a generated mirror's decode paths and
3094
+ // holds the compiled facade's integer encoders to the same bytes.
3095
+ conformance_mod.addImport("shim_integer_core", sidecarShimModule(b, target, optimize, corewire_exe, b.path("tests/sidecar/integer_fixture.contract.json")));
3096
+ conformance_mod.addImport("facade_integer_core", facadeCoreModule(b, target, optimize, node, corewire_exe, b.path("tests/sidecar/integer_fixture.contract.json")));
3097
+ const conformance_fixtures = [_]struct {
3098
+ ts_import: []const u8,
3099
+ shim_import: []const u8,
3100
+ facade_import: []const u8,
3101
+ contract_name: []const u8,
3102
+ core_mod: *std.Build.Module,
3103
+ entry: []const u8,
3104
+ }{
3105
+ .{ .ts_import = "ts_host_core", .shim_import = "shim_host_core", .facade_import = "facade_host_core", .contract_name = "host-fixture", .core_mod = fixture_mod, .entry = "tests/ts-core/fixture.ts" },
3106
+ .{ .ts_import = "ts_soundboard_core", .shim_import = "shim_soundboard_core", .facade_import = "facade_soundboard_core", .contract_name = "soundboard", .core_mod = soundboard_core_mod, .entry = "examples/soundboard-ts/src/core.ts" },
3107
+ .{ .ts_import = "ts_monitor_core", .shim_import = "shim_monitor_core", .facade_import = "facade_monitor_core", .contract_name = "system-monitor", .core_mod = monitor_core_mod, .entry = "examples/system-monitor-ts/src/core.ts" },
3108
+ .{ .ts_import = "ts_ai_chat_core", .shim_import = "shim_ai_chat_core", .facade_import = "facade_ai_chat_core", .contract_name = "ai-chat", .core_mod = ai_chat_core_mod, .entry = "examples/ai-chat-ts/src/core.ts" },
3109
+ };
3110
+ // The corpus contract artifacts an external core toolchain consumes
3111
+ // (stage-core-contracts): the extracted sidecar plus its facade
3112
+ // projection, per fixture.
3113
+ var core_contracts: std.ArrayList(CoreContract) = .empty;
3114
+ {
3115
+ const markup_sidecar = sidecarExtractJson(b, target, optimize, extract_mod, markup_fixture_mod, "tests/ts-core/markup_fixture.ts");
3116
+ core_contracts.append(b.allocator, .{
3117
+ .name = "markup-fixture",
3118
+ .sidecar = markup_sidecar,
3119
+ .facade = facadeTsFile(b, corewire_exe, markup_sidecar),
3120
+ }) catch @panic("OOM");
3121
+ }
3122
+ for (conformance_fixtures) |fixture| {
3123
+ const sidecar_json = sidecarExtractJson(b, target, optimize, extract_mod, fixture.core_mod, fixture.entry);
3124
+ conformance_mod.addImport(fixture.ts_import, fixture.core_mod);
3125
+ conformance_mod.addImport(fixture.shim_import, sidecarShimModule(b, target, optimize, corewire_exe, sidecar_json));
3126
+ conformance_mod.addImport(fixture.facade_import, facadeCoreModule(b, target, optimize, node, corewire_exe, sidecar_json));
3127
+ core_contracts.append(b.allocator, .{
3128
+ .name = fixture.contract_name,
3129
+ .sidecar = sidecar_json,
3130
+ .facade = facadeTsFile(b, corewire_exe, sidecar_json),
3131
+ }) catch @panic("OOM");
3132
+ }
3133
+
3134
+ // Compiled-core behavior parity (tests/sidecar/
3135
+ // external_core_parity_tests.zig): the executable half of the
3136
+ // conformance story, gated on a caller-supplied compiled-core
3137
+ // archive because the repo builds none itself. The env var carries
3138
+ // one or more link inputs (path-delimiter-separated) that together
3139
+ // export the markup fixture's attested symbol set; the binary pairs
3140
+ // a FRESH generated mirror with them (the conformance binary's
3141
+ // mirror links the stub core's exports — one process cannot carry
3142
+ // both symbol sets). A real archive's sidecar carries the compile's
3143
+ // own build_id, which the mirror's boot fence checks against the
3144
+ // identity getters — so the caller supplies the archive's OWN
3145
+ // emitted sidecar through NATIVE_SDK_EXTERNAL_CORE_SIDECAR (the
3146
+ // committed fixture sidecar stays the default for stub-shaped
3147
+ // callers that restate its identity).
3148
+ const external_core_parity: ?*std.Build.Step.Compile = if (b.graph.environ_map.get("NATIVE_SDK_EXTERNAL_CORE_ARCHIVE")) |archives| blk: {
3149
+ const parity_mod = module(b, target, optimize, "tests/sidecar/external_core_parity_tests.zig");
3150
+ parity_mod.link_libc = true;
3151
+ parity_mod.addImport("corewire_rt", module(b, target, optimize, "tools/corewire/shim_rt.zig"));
3152
+ parity_mod.addImport("core_abi", module(b, target, optimize, "tools/corewire/core_abi.zig"));
3153
+ parity_mod.addImport("ts_core", markup_fixture_mod);
3154
+ const parity_sidecar: std.Build.LazyPath = if (b.graph.environ_map.get("NATIVE_SDK_EXTERNAL_CORE_SIDECAR")) |sidecar|
3155
+ .{ .cwd_relative = b.dupe(sidecar) }
3156
+ else
3157
+ b.path("tests/sidecar/markup_fixture.contract.json");
3158
+ parity_mod.addImport("shim_core", sidecarShimModule(b, target, optimize, corewire_exe, parity_sidecar));
3159
+ var inputs = std.mem.tokenizeScalar(u8, archives, std.fs.path.delimiter);
3160
+ while (inputs.next()) |input| {
3161
+ parity_mod.addObjectFile(.{ .cwd_relative = b.dupe(input) });
3162
+ }
3163
+ const parity_tests = filteredTestArtifact(b, parity_mod, "external-core-parity-tests", &.{});
3164
+ // Run the checker over the supplied sidecar explicitly (the
3165
+ // shim generation above validates too, but the checker tier —
3166
+ // both projections, integer_slots structural rules included —
3167
+ // is the surface an external compile is verified against).
3168
+ const check_sidecar = b.addRunArtifact(corewire_exe);
3169
+ check_sidecar.addArg("--sidecar");
3170
+ check_sidecar.addFileArg(parity_sidecar);
3171
+ check_sidecar.addArg("--check");
3172
+ parity_tests.step.dependOn(&check_sidecar.step);
3173
+ break :blk parity_tests;
3174
+ } else null;
3175
+
3176
+ // The full-corpus compiled-core batteries: each supplied fixture's
3177
+ // OWN e2e test root recompiled over a paired core (the transpiled
3178
+ // lane plus a fresh generated mirror linked against the caller's
3179
+ // archive), so every behavioral assertion the fixture app carries
3180
+ // runs through the compiled core with byte parity checked at every
3181
+ // seam (commands, snapshots, subscriptions, channels, helpers).
3182
+ // Env-gated per fixture like the markup parity suite: unset means
3183
+ // the battery is never built and `zig build test` stays green.
3184
+ var compiled_core_parity: std.ArrayList(CompiledCoreParity) = .empty;
3185
+ const compiled_core_fixtures = [_]struct {
3186
+ name: []const u8,
3187
+ supply: ?CompiledCoreSupply,
3188
+ ts_mod: *std.Build.Module,
3189
+ root: std.Build.LazyPath,
3190
+ core_import: []const u8,
3191
+ /// The host suite's second lane (the markup fixture) rides the
3192
+ /// same binary, transpiler-only: one archive per process is the
3193
+ /// compiled-core contract.
3194
+ second_import: ?[]const u8 = null,
3195
+ second_mod: ?*std.Build.Module = null,
3196
+ }{
3197
+ .{ .name = "host", .supply = compiledCoreEnv(b, "HOST"), .ts_mod = fixture_mod, .root = b.path("tests/ts-core/host_e2e_tests.zig"), .core_import = "ts_core_fixture", .second_import = "ts_markup_fixture", .second_mod = markup_fixture_mod },
3198
+ // The markup battery is the mirror image of the host one: the
3199
+ // markup fixture's core pairs, and the host fixture rides along
3200
+ // transpiler-only as the second lane.
3201
+ .{ .name = "markup", .supply = compiledCoreEnv(b, "MARKUP"), .ts_mod = markup_fixture_mod, .root = b.path("tests/ts-core/markup_e2e_tests.zig"), .core_import = "ts_markup_fixture", .second_import = "ts_core_fixture", .second_mod = fixture_mod },
3202
+ .{ .name = "soundboard", .supply = compiledCoreEnv(b, "SOUNDBOARD"), .ts_mod = soundboard_core_mod, .root = soundboard_root, .core_import = "ts_soundboard_core" },
3203
+ .{ .name = "system-monitor", .supply = compiledCoreEnv(b, "SYSTEM_MONITOR"), .ts_mod = monitor_core_mod, .root = monitor_root, .core_import = "ts_system_monitor_core" },
3204
+ .{ .name = "ai-chat", .supply = compiledCoreEnv(b, "AI_CHAT"), .ts_mod = ai_chat_core_mod, .root = ai_chat_root, .core_import = "ts_ai_chat_core" },
3205
+ };
3206
+ for (compiled_core_fixtures) |entry| {
3207
+ const supply = entry.supply orelse continue;
3208
+ const paired_mod = pairedCoreModule(b, target, optimize, corewire_exe, entry.ts_mod, supply);
3209
+ const battery_mod = b.createModule(.{
3210
+ .root_source_file = entry.root,
3211
+ .target = target,
3212
+ .optimize = optimize,
3213
+ });
3214
+ battery_mod.addImport("native_sdk", desktop_mod);
3215
+ battery_mod.addImport(entry.core_import, paired_mod);
3216
+ if (entry.second_import) |second| battery_mod.addImport(second, entry.second_mod.?);
3217
+ const battery = filteredTestArtifact(b, battery_mod, b.fmt("compiled-core-{s}-tests", .{entry.name}), &.{});
3218
+ // Run the checker tier over the supplied sidecar explicitly —
3219
+ // the same surface an external compile is verified against in
3220
+ // the markup parity suite.
3221
+ const check_sidecar = b.addRunArtifact(corewire_exe);
3222
+ check_sidecar.addArg("--sidecar");
3223
+ check_sidecar.addFileArg(supply.sidecar);
3224
+ check_sidecar.addArg("--check");
3225
+ battery.step.dependOn(&check_sidecar.step);
3226
+ compiled_core_parity.append(b.allocator, .{ .name = b.dupe(entry.name), .tests = battery }) catch @panic("OOM");
3227
+ }
3228
+
2886
3229
  return .{
2887
3230
  .host = filteredTestArtifact(b, e2e_mod, "ts-core-e2e-tests", &.{}),
2888
3231
  .soundboard = filteredTestArtifact(b, soundboard_mod, "ts-soundboard-e2e-tests", &.{}),
2889
3232
  .system_monitor = filteredTestArtifact(b, monitor_mod, "ts-system-monitor-e2e-tests", &.{}),
2890
3233
  .scaffold_ide = filteredTestArtifact(b, scaffold_ide_mod, "ts-scaffold-ide-e2e-tests", &.{}),
2891
3234
  .ai_chat = filteredTestArtifact(b, ai_chat_mod, "ts-ai-chat-e2e-tests", &.{}),
3235
+ .sidecar_conformance = filteredTestArtifact(b, conformance_mod, "sidecar-conformance-tests", &.{}),
3236
+ .external_core_parity = external_core_parity,
3237
+ .compiled_core_parity = compiled_core_parity.toOwnedSlice(b.allocator) catch @panic("OOM"),
3238
+ .core_contracts = core_contracts.toOwnedSlice(b.allocator) catch @panic("OOM"),
3239
+ };
3240
+ }
3241
+
3242
+ /// One fixture's paired-core module (tests/compiled-core): generate
3243
+ /// the lockstep root from the transpiled module's own export surface,
3244
+ /// stage it beside the pairing library and the mirror-value converter,
3245
+ /// bind the transpiled lane and a mirror generated from the supplied
3246
+ /// contract sidecar, and link the caller's compiled-core archive(s).
3247
+ fn pairedCoreModule(
3248
+ b: *std.Build,
3249
+ target: std.Build.ResolvedTarget,
3250
+ optimize: std.builtin.OptimizeMode,
3251
+ corewire_exe: *std.Build.Step.Compile,
3252
+ ts_mod: *std.Build.Module,
3253
+ supply: CompiledCoreSupply,
3254
+ ) *std.Build.Module {
3255
+ const gen_root = b.addWriteFiles().add("gen_paired_main.zig",
3256
+ \\//! Generated by the build: emit a fixture's paired-core root
3257
+ \\//! from its transpiled module (tests/compiled-core/gen_paired.zig).
3258
+ \\const std = @import("std");
3259
+ \\const gen = @import("gen_paired");
3260
+ \\const core = @import("ts_core");
3261
+ \\pub fn main(init: std.process.Init) !void {
3262
+ \\ try gen.emitMain(core, init);
3263
+ \\}
3264
+ \\
3265
+ );
3266
+ const gen_mod = b.createModule(.{
3267
+ .root_source_file = gen_root,
3268
+ .target = target,
3269
+ .optimize = optimize,
3270
+ });
3271
+ gen_mod.addImport("gen_paired", module(b, target, optimize, "tests/compiled-core/gen_paired.zig"));
3272
+ gen_mod.addImport("ts_core", ts_mod);
3273
+ const gen_exe = b.addExecutable(.{
3274
+ .name = "gen-paired",
3275
+ .root_module = gen_mod,
3276
+ .use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
3277
+ });
3278
+ const gen_run = b.addRunArtifact(gen_exe);
3279
+ const paired_src = gen_run.addOutputFileArg("paired.zig");
3280
+
3281
+ const staged = b.addWriteFiles();
3282
+ const paired_root = staged.addCopyFile(paired_src, "paired.zig");
3283
+ _ = staged.addCopyFile(b.path("tests/compiled-core/paired_core.zig"), "paired_core.zig");
3284
+ _ = staged.addCopyFile(b.path("tests/sidecar/mirror_value.zig"), "mirror_value.zig");
3285
+ const mod = b.createModule(.{
3286
+ .root_source_file = paired_root,
3287
+ .target = target,
3288
+ .optimize = optimize,
3289
+ });
3290
+ mod.link_libc = true;
3291
+ mod.addImport("ts_lane", ts_mod);
3292
+ mod.addImport("shim_lane", sidecarShimModule(b, target, optimize, corewire_exe, supply.sidecar));
3293
+ mod.addImport("corewire_rt", module(b, target, optimize, "tools/corewire/shim_rt.zig"));
3294
+ mod.addImport("core_abi", module(b, target, optimize, "tools/corewire/core_abi.zig"));
3295
+ var inputs = std.mem.tokenizeScalar(u8, supply.archives, std.fs.path.delimiter);
3296
+ while (inputs.next()) |input| {
3297
+ mod.addObjectFile(.{ .cwd_relative = b.dupe(input) });
3298
+ }
3299
+ return mod;
3300
+ }
3301
+
3302
+ /// A sidecar's TypeScript facade projection alone (core_facade.ts) —
3303
+ /// the contract module an external core toolchain compiles.
3304
+ fn facadeTsFile(
3305
+ b: *std.Build,
3306
+ corewire_exe: *std.Build.Step.Compile,
3307
+ sidecar_json: std.Build.LazyPath,
3308
+ ) std.Build.LazyPath {
3309
+ const generate = b.addRunArtifact(corewire_exe);
3310
+ generate.addArg("--sidecar");
3311
+ generate.addFileArg(sidecar_json);
3312
+ generate.addArg("--facade");
3313
+ return generate.addOutputFileArg("core_facade.ts");
3314
+ }
3315
+
3316
+ /// One fixture's generated-mirror module: run corewire over the
3317
+ /// sidecar, stage the emitted core_shim.zig as core.zig beside its two
3318
+ /// staged runtime files (shim_rt.zig, core_abi.zig) — the same staging
3319
+ /// shape the transpiler lane gives its emitted core and rt.zig.
3320
+ fn sidecarShimModule(
3321
+ b: *std.Build,
3322
+ target: std.Build.ResolvedTarget,
3323
+ optimize: std.builtin.OptimizeMode,
3324
+ corewire_exe: *std.Build.Step.Compile,
3325
+ sidecar_json: std.Build.LazyPath,
3326
+ ) *std.Build.Module {
3327
+ const generate = b.addRunArtifact(corewire_exe);
3328
+ generate.addArg("--sidecar");
3329
+ generate.addFileArg(sidecar_json);
3330
+ generate.addArg("--out");
3331
+ const generated = generate.addOutputFileArg("core_shim.zig");
3332
+ const staged = b.addWriteFiles();
3333
+ const shim_root = staged.addCopyFile(generated, "core.zig");
3334
+ _ = staged.addCopyFile(b.path("tools/corewire/shim_rt.zig"), "shim_rt.zig");
3335
+ _ = staged.addCopyFile(b.path("tools/corewire/core_abi.zig"), "core_abi.zig");
3336
+ return b.createModule(.{
3337
+ .root_source_file = shim_root,
3338
+ .target = target,
3339
+ .optimize = optimize,
3340
+ });
3341
+ }
3342
+
3343
+ /// One fixture's compiled-facade module: run corewire over the sidecar
3344
+ /// for its TypeScript projection (core_facade.ts), then compile that
3345
+ /// projection through the shipped transpiler — the checker/emitter tier
3346
+ /// is the compile, so this step IS the subset-acceptance proof — and
3347
+ /// stage the emitted Zig beside its rt kernel like any fixture core.
3348
+ fn facadeCoreModule(
3349
+ b: *std.Build,
3350
+ target: std.Build.ResolvedTarget,
3351
+ optimize: std.builtin.OptimizeMode,
3352
+ node: []const u8,
3353
+ corewire_exe: *std.Build.Step.Compile,
3354
+ sidecar_json: std.Build.LazyPath,
3355
+ ) *std.Build.Module {
3356
+ const generate = b.addRunArtifact(corewire_exe);
3357
+ generate.addArg("--sidecar");
3358
+ generate.addFileArg(sidecar_json);
3359
+ generate.addArg("--facade");
3360
+ const facade_ts = generate.addOutputFileArg("core_facade.ts");
3361
+ const staged_ts = b.addWriteFiles();
3362
+ const facade_entry = staged_ts.addCopyFile(facade_ts, "core.ts");
3363
+
3364
+ const transpile = b.addSystemCommand(&.{node});
3365
+ transpile.addFileArg(b.path("packages/core/src/cli.ts"));
3366
+ transpile.addFileArg(facade_entry);
3367
+ transpile.addArg("-o");
3368
+ const emitted_core = transpile.addOutputFileArg("core.zig");
3369
+ tsCoreAddDirInputs(b, transpile, "packages/core/sdk");
3370
+ const transpiler_sources = [_][]const u8{
3371
+ "checker.ts", "cli.ts", "diagnostics.ts", "emitter.ts", "infer.ts", "modules.ts", "transpile.ts", "typed_ast.ts", "types.ts",
2892
3372
  };
3373
+ for (transpiler_sources) |source| {
3374
+ transpile.addFileInput(b.path(b.fmt("packages/core/src/{s}", .{source})));
3375
+ }
3376
+
3377
+ const staged = b.addWriteFiles();
3378
+ const core_root = staged.addCopyFile(emitted_core, "core.zig");
3379
+ _ = staged.addCopyFile(b.path("packages/core/rt/rt.zig"), "rt.zig");
3380
+ return b.createModule(.{
3381
+ .root_source_file = core_root,
3382
+ .target = target,
3383
+ .optimize = optimize,
3384
+ });
3385
+ }
3386
+
3387
+ /// Extract a fixture's contract sidecar from its transpiled module
3388
+ /// (tools/corewire/extract.zig) — a generated one-line main per
3389
+ /// fixture, so corpus sidecars regenerate whenever the fixture or the
3390
+ /// transpiler changes.
3391
+ fn sidecarExtractJson(
3392
+ b: *std.Build,
3393
+ target: std.Build.ResolvedTarget,
3394
+ optimize: std.builtin.OptimizeMode,
3395
+ extract_mod: *std.Build.Module,
3396
+ core_mod: *std.Build.Module,
3397
+ entry: []const u8,
3398
+ ) std.Build.LazyPath {
3399
+ const root = b.addWriteFiles().add("extract_main.zig", b.fmt(
3400
+ \\//! Generated by the build: extract the contract sidecar from a
3401
+ \\//! transpiled fixture core (see tools/corewire/extract.zig).
3402
+ \\const std = @import("std");
3403
+ \\const extract = @import("extract");
3404
+ \\const core = @import("ts_core");
3405
+ \\pub fn main(init: std.process.Init) !void {{
3406
+ \\ try extract.emitMain(core, "{s}", init);
3407
+ \\}}
3408
+ \\
3409
+ , .{entry}));
3410
+ const mod = b.createModule(.{
3411
+ .root_source_file = root,
3412
+ .target = target,
3413
+ .optimize = optimize,
3414
+ });
3415
+ mod.addImport("extract", extract_mod);
3416
+ mod.addImport("ts_core", core_mod);
3417
+ const exe = b.addExecutable(.{
3418
+ .name = "sidecar-extract",
3419
+ .root_module = mod,
3420
+ .use_llvm = @import("build/app.zig").useLlvmWorkaround(target),
3421
+ });
3422
+ const run = b.addRunArtifact(exe);
3423
+ return run.addOutputFileArg("core.contract.json");
2893
3424
  }
2894
3425
 
2895
3426
  /// Transpile one TS fixture core at build time and pair the emitted