@native-sdk/cli 0.7.0 → 0.7.2

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 (81) hide show
  1. package/build/app.zig +8 -0
  2. package/build.zig +114 -103
  3. package/native-sdk.d.ts +6 -3
  4. package/package.json +9 -9
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/sdk/text.ts +25 -14
  8. package/packages/core/src/checker.ts +39 -0
  9. package/packages/core/src/emitter.ts +125 -1
  10. package/skill-data/native-ui/SKILL.md +11 -7
  11. package/src/platform/macos/appkit_host.m +76 -4
  12. package/src/platform/macos/cef_host.mm +24 -2
  13. package/src/platform/macos/root.zig +13 -0
  14. package/src/platform/types.zig +4 -0
  15. package/src/platform/windows/gpu_surface_renderer.cpp +2280 -0
  16. package/src/platform/windows/gpu_surface_renderer.h +86 -0
  17. package/src/platform/windows/root.zig +298 -20
  18. package/src/platform/windows/webview2_host.cpp +343 -33
  19. package/src/primitives/canvas/code.zig +501 -33
  20. package/src/primitives/canvas/code_tests.zig +1029 -6
  21. package/src/primitives/canvas/events.zig +111 -1
  22. package/src/primitives/canvas/frame.zig +45 -1
  23. package/src/primitives/canvas/gpu.zig +6 -0
  24. package/src/primitives/canvas/markdown_tests.zig +17 -18
  25. package/src/primitives/canvas/render_tests.zig +93 -0
  26. package/src/primitives/canvas/root.zig +6 -0
  27. package/src/primitives/canvas/serialization.zig +150 -21
  28. package/src/primitives/canvas/text.zig +6 -0
  29. package/src/primitives/canvas/themes/geist.zig +51 -5
  30. package/src/primitives/canvas/tokens.zig +33 -4
  31. package/src/primitives/canvas/ui.zig +160 -36
  32. package/src/primitives/canvas/ui_markup.zig +60 -9
  33. package/src/primitives/canvas/ui_markup_compiled.zig +41 -0
  34. package/src/primitives/canvas/ui_markup_compiled_tests.zig +12 -0
  35. package/src/primitives/canvas/ui_markup_contract.zig +17 -1
  36. package/src/primitives/canvas/ui_markup_view.zig +44 -0
  37. package/src/primitives/canvas/ui_markup_view_tests.zig +80 -6
  38. package/src/primitives/canvas/ui_schema.zig +18 -0
  39. package/src/primitives/canvas/ui_schema_tests.zig +10 -7
  40. package/src/primitives/canvas/ui_tests.zig +40 -0
  41. package/src/primitives/canvas/widget_builtin_tests.zig +513 -13
  42. package/src/primitives/canvas/widget_invalidation.zig +12 -1
  43. package/src/primitives/canvas/widget_layout.zig +260 -21
  44. package/src/primitives/canvas/widget_metrics.zig +47 -6
  45. package/src/primitives/canvas/widget_render.zig +849 -78
  46. package/src/primitives/canvas/widget_render_controls.zig +83 -25
  47. package/src/primitives/canvas/widget_render_style.zig +52 -8
  48. package/src/primitives/canvas/widget_runtime.zig +2 -0
  49. package/src/primitives/canvas/widget_text_input.zig +167 -8
  50. package/src/primitives/canvas/widget_tree.zig +6 -5
  51. package/src/primitives/canvas/widgets.zig +78 -2
  52. package/src/runtime/canvas_budget_edge_tests.zig +3 -2
  53. package/src/runtime/canvas_frame.zig +60 -7
  54. package/src/runtime/canvas_frame_invalidation_tests.zig +80 -0
  55. package/src/runtime/canvas_frame_packet_tests.zig +83 -9
  56. package/src/runtime/canvas_frame_patch_tests.zig +16 -0
  57. package/src/runtime/canvas_images.zig +8 -2
  58. package/src/runtime/canvas_limits.zig +13 -6
  59. package/src/runtime/canvas_widget_clipboard_tests.zig +8 -5
  60. package/src/runtime/canvas_widget_context_menu.zig +7 -2
  61. package/src/runtime/canvas_widget_event_tests.zig +18 -14
  62. package/src/runtime/canvas_widget_events.zig +51 -20
  63. package/src/runtime/canvas_widget_runtime.zig +108 -4
  64. package/src/runtime/canvas_widget_scroll_driver_tests.zig +59 -0
  65. package/src/runtime/canvas_widget_split_tree_tests.zig +100 -0
  66. package/src/runtime/canvas_widget_state.zig +27 -0
  67. package/src/runtime/canvas_widget_text_tests.zig +326 -0
  68. package/src/runtime/core.zig +15 -5
  69. package/src/runtime/effects.zig +6 -0
  70. package/src/runtime/effects_tests.zig +30 -0
  71. package/src/runtime/gpu_surface_events.zig +50 -19
  72. package/src/runtime/media_surface_tests.zig +1 -1
  73. package/src/runtime/runtime_event_tests.zig +74 -0
  74. package/src/runtime/ui_app.zig +10 -8
  75. package/src/runtime/ui_app_tests.zig +67 -0
  76. package/src/runtime/view.zig +60 -16
  77. package/src/runtime/view_canvas.zig +15 -0
  78. package/src/runtime/view_widget_scroll.zig +48 -18
  79. package/src/runtime/view_widget_text.zig +59 -16
  80. package/src/runtime/window_view_runtime.zig +10 -0
  81. package/src/tooling/templates.zig +9 -6
package/build/app.zig CHANGED
@@ -1040,6 +1040,7 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
1040
1040
  // fails the compile by design if it cannot be found.
1041
1041
  app_mod.addIncludePath(dep.path("third_party/webview2/include"));
1042
1042
  app_mod.addCSourceFile(.{ .file = dep.path("src/platform/windows/webview2_host.cpp"), .flags = &.{"-std=c++17"} });
1043
+ app_mod.addCSourceFile(.{ .file = dep.path("src/platform/windows/gpu_surface_renderer.cpp"), .flags = &.{"-std=c++17"} });
1043
1044
  // WebView2Loader.dll rides next to the installed app
1044
1045
  // executable: the host loads it at runtime to discover
1045
1046
  // the machine's WebView2 runtime. Canvas apps never
@@ -1064,6 +1065,7 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
1064
1065
  // WebViewNotFound the moment an app actually uses a
1065
1066
  // WebView.
1066
1067
  app_mod.addCSourceFile(.{ .file = dep.path("src/platform/windows/webview2_host.cpp"), .flags = &.{ "-std=c++17", "-DNATIVE_SDK_ALLOW_WEBVIEW2_STUB" } });
1068
+ app_mod.addCSourceFile(.{ .file = dep.path("src/platform/windows/gpu_surface_renderer.cpp"), .flags = &.{"-std=c++17"} });
1067
1069
  },
1068
1070
  .chromium => {
1069
1071
  const cef_check = addCefCheck(b, target, cef_dir);
@@ -1075,6 +1077,7 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
1075
1077
  const include_arg = b.fmt("-I{s}", .{cef_dir});
1076
1078
  const define_arg = b.fmt("-DNATIVE_SDK_CEF_DIR=\"{s}\"", .{cef_dir});
1077
1079
  app_mod.addCSourceFile(.{ .file = dep.path("src/platform/windows/cef_host.cpp"), .flags = &.{ "-std=c++17", include_arg, define_arg } });
1080
+ app_mod.addCSourceFile(.{ .file = dep.path("src/platform/windows/gpu_surface_renderer.cpp"), .flags = &.{"-std=c++17"} });
1078
1081
  app_mod.addObjectFile(b.path(b.fmt("{s}/libcef_dll_wrapper/libcef_dll_wrapper.lib", .{cef_dir})));
1079
1082
  app_mod.addLibraryPath(b.path(b.fmt("{s}/Release", .{cef_dir})));
1080
1083
  },
@@ -1083,6 +1086,11 @@ fn linkPlatform(b: *std.Build, dep: *std.Build.Dependency, target: std.Build.Res
1083
1086
  app_mod.linkSystemLibrary("c++", .{});
1084
1087
  app_mod.linkSystemLibrary("user32", .{});
1085
1088
  app_mod.linkSystemLibrary("gdi32", .{});
1089
+ // Retained gpu_surface packets are composited into a hardware
1090
+ // Direct2D target; DirectWrite draws the engine-measured text
1091
+ // runs (including registered in-memory fonts) on that target.
1092
+ app_mod.linkSystemLibrary("d2d1", .{});
1093
+ app_mod.linkSystemLibrary("dwrite", .{});
1086
1094
  app_mod.linkSystemLibrary("imm32", .{});
1087
1095
  app_mod.linkSystemLibrary("comctl32", .{});
1088
1096
  app_mod.linkSystemLibrary("ole32", .{});
package/build.zig CHANGED
@@ -517,13 +517,15 @@ pub fn build(b: *std.Build) void {
517
517
  test_step.dependOn(&battery_run.step);
518
518
  }
519
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)");
520
+ // consumes: per fixture, the extracted contract sidecar, the
521
+ // generated entry module, and the compiler profile that builds
522
+ // it, under zig-out/core-contracts.
523
+ const contracts_step = b.step("stage-core-contracts", "Install each ts-core fixture's contract sidecar, generated entry module, and compiler profile under zig-out/core-contracts (requires node)");
523
524
  for (ts_core_artifacts.core_contracts) |contract| {
524
525
  const dir: std.Build.InstallDir = .{ .custom = b.fmt("core-contracts/{s}", .{contract.name}) };
525
526
  contracts_step.dependOn(&b.addInstallFileWithDir(contract.sidecar, dir, "core.contract.json").step);
526
527
  contracts_step.dependOn(&b.addInstallFileWithDir(contract.facade, dir, "core_facade.ts").step);
528
+ contracts_step.dependOn(&b.addInstallFileWithDir(contract.profile, dir, "core_profile.json").step);
527
529
  }
528
530
  ts_core_e2e_step.dependOn(&host_e2e_run.step);
529
531
  ts_core_e2e_step.dependOn(&soundboard_e2e_run.step);
@@ -564,6 +566,9 @@ pub fn build(b: *std.Build) void {
564
566
  .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"gpu_surfaces\"" },
565
567
  .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "\"gpuSurfaces\"" },
566
568
  .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "gpuFirstFrameLatencyNs: number" },
569
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "gpuBackend: NativeSdkGpuSurfaceBackend;" },
570
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "export type NativeSdkGpuSurfaceBackendRequest = \"metal\" | \"software\";" },
571
+ .{ .path = "packages/native-sdk/native-sdk.d.ts", .pattern = "gpuBackend?: NativeSdkGpuSurfaceBackendRequest;" },
567
572
  });
568
573
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-ts-toolchain-twins", "Verify the CLI's toolchain-resolution gate and its direct-`zig build` twin stay in lockstep (both resolve the aliased real compiler @typescript/old from packages/core — the same origin runtime imports it from — hold its resolved version against the manifest-read pin, never probe the unused @typescript/typescript6 wrapper, and teach instead of panicking)", &.{
569
574
  // The resolution twins probe the aliased REAL compiler
@@ -628,19 +633,19 @@ pub fn build(b: *std.Build) void {
628
633
  .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "close:function(options){return invoke('native-sdk.view.close',viewSelectorPayload(options))" },
629
634
  });
630
635
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-command-contracts", "Verify command docs match native view update contracts", &.{
631
- .{ .path = "docs/src/app/commands/page.mdx", .pattern = ".text = \"Refreshed\"" },
632
- .{ .path = "docs/src/app/commands/page.mdx", .pattern = "const commands = await window.zero.commands.list();" },
636
+ .{ .path = "docs/src/app/docs/commands/page.mdx", .pattern = ".text = \"Refreshed\"" },
637
+ .{ .path = "docs/src/app/docs/commands/page.mdx", .pattern = "const commands = await window.zero.commands.list();" },
633
638
  });
634
639
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-native-view-contracts", "Verify native surface docs describe view identity", &.{
635
- .{ .path = "docs/src/app/native-surfaces/page.mdx", .pattern = "ViewInfo.id" },
636
- .{ .path = "docs/src/app/native-surfaces/page.mdx", .pattern = "window.zero.views.update(\"status\"" },
637
- .{ .path = "docs/src/app/native-surfaces/page.mdx", .pattern = "first-frame latency budget" },
640
+ .{ .path = "docs/src/app/docs/native-surfaces/page.mdx", .pattern = "ViewInfo.id" },
641
+ .{ .path = "docs/src/app/docs/native-surfaces/page.mdx", .pattern = "window.zero.views.update(\"status\"" },
642
+ .{ .path = "docs/src/app/docs/native-surfaces/page.mdx", .pattern = "first-frame latency budget" },
638
643
  });
639
644
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-shell-manifest-contracts", "Verify app.zon docs describe shell compatibility window labels", &.{
640
- .{ .path = "docs/src/app/app-zon/page.mdx", .pattern = "labels must stay unique across both lists" },
645
+ .{ .path = "docs/src/app/docs/app-zon/page.mdx", .pattern = "labels must stay unique across both lists" },
641
646
  });
642
647
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-media-producer-contracts", "Verify the media producer docs' typed callback stays mirrored by the compile-shaped pin in media_surface_tests.zig", &.{
643
- .{ .path = "docs/src/app/media-producers/page.mdx", .pattern = "producer: media.MediaSurfaceProducer" },
648
+ .{ .path = "docs/src/app/docs/media-producers/page.mdx", .pattern = "producer: media.MediaSurfaceProducer" },
644
649
  .{ .path = "src/runtime/media_surface_tests.zig", .pattern = "producer: media.MediaSurfaceProducer" },
645
650
  });
646
651
  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)", &.{
@@ -984,9 +989,37 @@ pub fn build(b: *std.Build) void {
984
989
  // this step until the encoder comment, the host decoder comment, and
985
990
  // the patterns below move with it.
986
991
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-wire-format-version-prose", "Verify wire-format version prose matches the packet version constant", &.{
987
- .{ .path = "src/primitives/canvas/serialization.zig", .pattern = "pub const binary_packet_version: u8 = 4;" },
988
- .{ .path = "src/primitives/canvas/serialization.zig", .pattern = "Compact binary gpu-surface packet encoding (wire format v4)." },
989
- .{ .path = "src/platform/macos/appkit_host.m", .pattern = "Compact binary gpu-surface packet decoding (wire format v4)." },
992
+ .{ .path = "src/primitives/canvas/serialization.zig", .pattern = "pub const binary_packet_version: u8 = 5;" },
993
+ .{ .path = "src/primitives/canvas/serialization.zig", .pattern = "Compact binary gpu-surface packet encoding (wire format v5)." },
994
+ .{ .path = "src/platform/macos/appkit_host.m", .pattern = "Compact binary gpu-surface packet decoding (wire format v5)." },
995
+ .{ .path = "src/platform/windows/gpu_surface_renderer.cpp", .pattern = "Compact binary gpu-surface packet decoding (wire format v5)." },
996
+ });
997
+ addFileContainsCheckStep(b, file_contains_checker, test_step, "test-windows-gpu-packet-presenter", "Verify Windows uses retained Direct2D packets with recovery, bounded resources, and dirty-region pixel fallback", &.{
998
+ .{ .path = "src/platform/windows/root.zig", .pattern = ".present_gpu_surface_packet_binary_fn = presentGpuSurfacePacketBinary" },
999
+ .{ .path = "src/platform/windows/root.zig", .pattern = ".backend = if (event.gpu_backend == 1) .direct2d else .software" },
1000
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "view.gpu_surface->present(request, &info)" },
1001
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "InvalidateRect(view.hwnd, &info.dirty_rects[index], FALSE)" },
1002
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "for (size_t y_index = y0; y_index < y1; ++y_index)" },
1003
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "InvalidateRect(view.hwnd, partial_update ? &dirty_pixels : nullptr, FALSE)" },
1004
+ .{ .path = "src/platform/windows/gpu_surface_renderer.cpp", .pattern = "D2D1_RENDER_TARGET_TYPE_HARDWARE" },
1005
+ .{ .path = "src/platform/windows/gpu_surface_renderer.cpp", .pattern = "retained_commands_ = std::move(next_retained)" },
1006
+ .{ .path = "src/platform/windows/gpu_surface_renderer.cpp", .pattern = "PushAxisAlignedClip(d2dRect(requested)" },
1007
+ .{ .path = "src/platform/windows/gpu_surface_renderer.cpp", .pattern = "const float expansion = effect.spread + blur" },
1008
+ .{ .path = "src/platform/windows/gpu_surface_renderer.cpp", .pattern = "releaseImageBitmap(action.id)" },
1009
+ .{ .path = "src/platform/windows/gpu_surface_renderer.cpp", .pattern = "resumeAndDrawBlur" },
1010
+ .{ .path = "src/platform/windows/gpu_surface_renderer.cpp", .pattern = "const Rect target = blurTarget(*command, outer_clip)" },
1011
+ .{ .path = "src/platform/windows/gpu_surface_renderer.cpp", .pattern = "blur_snapshot_->CopyFromBitmap" },
1012
+ .{ .path = "src/platform/windows/gpu_surface_renderer.cpp", .pattern = "command.effect.blur * transformScale(command.transform)" },
1013
+ .{ .path = "src/platform/windows/gpu_surface_renderer.cpp", .pattern = "D2D1_EXTEND_MODE_CLAMP" },
1014
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "!GetClientRect(view.hwnd, &client) || !PtInRect(&client, sample)" },
1015
+ .{ .path = "src/platform/windows/gpu_surface_renderer.cpp", .pattern = "draw_line(text.text, text.origin.x, text.origin.y)" },
1016
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "gpuSurfaceUpdateRegionRects" },
1017
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "info.dirty_rect_count > 0" },
1018
+ .{ .path = "src/platform/windows/webview2_host.cpp", .pattern = "view->gpu_force_full_repaint_pending = true" },
1019
+ .{ .path = "src/platform/windows/root.zig", .pattern = ".canvas_frame_full_repaint = event.force_full_repaint != 0" },
1020
+ .{ .path = ".github/scripts/windows-canvas-smoke.sh", .pattern = "gpu_backend=direct2d" },
1021
+ .{ .path = ".github/scripts/windows-effects-smoke.sh", .pattern = "gpu_backend=direct2d" },
1022
+ .{ .path = "build/app.zig", .pattern = "app_mod.linkSystemLibrary(\"d2d1\", .{})" },
990
1023
  });
991
1024
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-appkit-gpu-packet-blur-effects", "Verify AppKit GPU packet presenter applies blur effects", &.{
992
1025
  .{ .path = "src/platform/macos/appkit_host.m", .pattern = "NativeSdkPacketApplyBlur" },
@@ -1222,8 +1255,8 @@ pub fn build(b: *std.Build) void {
1222
1255
  .{ .path = "src/platform/macos/root.zig", .pattern = ".appearance_changed => state.emit" },
1223
1256
  });
1224
1257
  addFileContainsCheckStep(b, file_contains_checker, test_step, "test-docs-builtin-bridge-policy", "Verify bridge policy docs include guarded dialog commands", &.{
1225
- .{ .path = "docs/src/app/security/page.mdx", .pattern = ".{ .name = \"native-sdk.dialog.saveFile\"" },
1226
- .{ .path = "docs/src/app/bridge/builtin-commands/page.mdx", .pattern = ".{ .name = \"native-sdk.dialog.saveFile\"" },
1258
+ .{ .path = "docs/src/app/docs/security/page.mdx", .pattern = ".{ .name = \"native-sdk.dialog.saveFile\"" },
1259
+ .{ .path = "docs/src/app/docs/bridge/builtin-commands/page.mdx", .pattern = ".{ .name = \"native-sdk.dialog.saveFile\"" },
1227
1260
  });
1228
1261
 
1229
1262
  addTestStep(b, "test-geometry", "Run geometry module tests", geometry_tests);
@@ -1248,6 +1281,12 @@ pub fn build(b: *std.Build) void {
1248
1281
  // on a Windows runner makes that a Windows-native receipt. The same
1249
1282
  // tests also run inside `zig build test` via the canvas-frame shard.
1250
1283
  addTestStep(b, "test-canvas-fonts", "Run the runtime font-registry tests (includes the registered-CJK Chinese receipt)", filteredTestArtifact(b, desktop_mod, "canvas-fonts-tests", &.{"runtime.canvas_font_tests.test"}));
1284
+ // The console-attachment regression is Windows-only, so the general
1285
+ // Linux `zig build test` lane can only compile and skip it. Expose the
1286
+ // exact test as a focused step for the real-Windows CI runner; this
1287
+ // keeps CREATE_NO_WINDOW behavior covered without making that runner
1288
+ // execute the entire framework runtime suite.
1289
+ addTestStep(b, "test-windows-effects-no-console", "Verify Windows effect spawns run without an attached console", filteredTestArtifact(b, desktop_mod, "windows-effects-no-console-tests", &.{"runtime.effects_tests.test.Windows background spawns run without an attached console"}));
1251
1290
  addTestStep(b, "test-automation-protocol", "Run automation protocol tests", automation_protocol_tests);
1252
1291
  addTestStep(b, "test-automation-cli", "Run native automate CLI tests", automation_cli_tests);
1253
1292
  addTestStep(b, "test-markup-cli", "Run native markup CLI tests", markup_cli_tests);
@@ -1384,6 +1423,7 @@ pub fn build(b: *std.Build) void {
1384
1423
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-soundboard-ts", "Run soundboard-ts example tests", "examples/soundboard-ts", .managed),
1385
1424
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-deck", "Run deck example tests", "examples/deck", .managed),
1386
1425
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-markdown-viewer", "Run markdown viewer example tests", "examples/markdown-viewer", .managed),
1426
+ addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-code-editor", "Run code editor example tests", "examples/code-editor", .managed),
1387
1427
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-calculator", "Run calculator example tests", "examples/calculator", .managed),
1388
1428
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-notes", "Run notes example tests", "examples/notes", .managed),
1389
1429
  addExampleTestStep(b, host_cli_exe, native_examples_step, "test-example-split-collapse", "Run split collapse example tests", "examples/split-collapse", .managed),
@@ -2009,7 +2049,13 @@ pub fn build(b: *std.Build) void {
2009
2049
  \\ ready_uptime="$(printf '%s\n' "$ready" | sed -n 's/.*runtime_uptime_ns=\([0-9][0-9]*\).*/\1/p')"
2010
2050
  \\ case "$ready_uptime" in ''|*[!0-9]*) echo "gpu-dashboard automation ready uptime was missing" >&2; exit 1 ;; esac
2011
2051
  \\ if [ "$ready_uptime" -le 0 ] || [ "$ready_uptime" -gt "$ready_budget_ns" ]; then echo "gpu-dashboard automation ready exceeded $ready_budget_ms ms: $ready_uptime ns" >&2; exit 1; fi
2012
- \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
2052
+ \\ attempts=0
2053
+ \\ while [ "$attempts" -lt 50 ]; do
2054
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
2055
+ \\ case "$snapshot" in *'window @w1 "Native SDK GPU Dashboard"'*'view @w1/dashboard-canvas kind=gpu_surface'*'accessibility_label="Native-rendered product dashboard canvas"'*) break ;; esac
2056
+ \\ attempts=$((attempts + 1))
2057
+ \\ sleep 0.1
2058
+ \\ done
2013
2059
  \\ case "$snapshot" in *'window @w1 "Native SDK GPU Dashboard"'*) ;; *) echo "gpu-dashboard window was missing from snapshot" >&2; exit 1 ;; esac
2014
2060
  \\ case "$snapshot" in *'view @w1/main kind=webview'*) echo "dashboard should not create an implicit main WebView" >&2; exit 1 ;; *) ;; esac
2015
2061
  \\ case "$snapshot" in *'source kind=html bytes=0'*) echo "dashboard should not publish an empty default WebView source" >&2; exit 1 ;; *) ;; esac
@@ -2970,8 +3016,8 @@ const TsCoreE2eArtifacts = struct {
2970
3016
  /// — every battery skipped — otherwise.
2971
3017
  compiled_core_parity: []const CompiledCoreParity,
2972
3018
  /// Per-fixture contract artifacts for an external core toolchain:
2973
- /// the extracted contract sidecar and its TypeScript facade
2974
- /// projection, installed by the stage-core-contracts step.
3019
+ /// the effective contract sidecar and its TypeScript facade/profile
3020
+ /// projections, installed by the stage-core-contracts step.
2975
3021
  core_contracts: []const CoreContract,
2976
3022
  };
2977
3023
 
@@ -2984,6 +3030,7 @@ const CoreContract = struct {
2984
3030
  name: []const u8,
2985
3031
  sidecar: std.Build.LazyPath,
2986
3032
  facade: std.Build.LazyPath,
3033
+ profile: std.Build.LazyPath,
2987
3034
  };
2988
3035
 
2989
3036
  /// One fixture's compiled-core supply: the archive link input(s) and
@@ -3114,52 +3161,55 @@ fn tsCoreE2eArtifact(
3114
3161
 
3115
3162
  const conformance_mod = module(b, target, optimize, "tests/sidecar/conformance_tests.zig");
3116
3163
  conformance_mod.addImport("native_sdk", desktop_mod);
3117
- // The canonical value encoder the facade parity axis compares
3164
+ // The canonical value encoder the envelope and snapshot axes compare
3118
3165
  // against (the same module the generated shims stage).
3119
3166
  conformance_mod.addImport("corewire_rt", module(b, target, optimize, "tools/corewire/shim_rt.zig"));
3120
3167
  conformance_mod.addImport("ts_markup_core", markup_fixture_mod);
3121
3168
  conformance_mod.addImport("shim_markup_core", sidecarShimModule(b, target, optimize, corewire_exe, b.path("tests/sidecar/markup_fixture.contract.json")));
3122
- conformance_mod.addImport("facade_markup_core", facadeCoreModule(b, target, optimize, node, corewire_exe, b.path("tests/sidecar/markup_fixture.contract.json")));
3123
3169
  // The integer-class fixture: a hand-written sidecar attesting mixed
3124
3170
  // i64/u64 slot classes, so the suite drives boundary and full-range
3125
- // integer values through a generated mirror's decode paths and
3126
- // holds the compiled facade's integer encoders to the same bytes.
3171
+ // integer values through a generated mirror's decode paths.
3127
3172
  conformance_mod.addImport("shim_integer_core", sidecarShimModule(b, target, optimize, corewire_exe, b.path("tests/sidecar/integer_fixture.contract.json")));
3128
- conformance_mod.addImport("facade_integer_core", facadeCoreModule(b, target, optimize, node, corewire_exe, b.path("tests/sidecar/integer_fixture.contract.json")));
3129
3173
  const conformance_fixtures = [_]struct {
3130
3174
  ts_import: []const u8,
3131
3175
  shim_import: []const u8,
3132
- facade_import: []const u8,
3133
3176
  contract_name: []const u8,
3134
3177
  core_mod: *std.Build.Module,
3135
3178
  entry: []const u8,
3179
+ /// Attested integer slots the compiled projection carries as f64
3180
+ /// (values that reach the f64-exact boundary have no honest i64
3181
+ /// declaration on that side).
3182
+ f64_slots: []const []const u8 = &.{},
3136
3183
  }{
3137
- .{ .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" },
3138
- .{ .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" },
3139
- .{ .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" },
3140
- .{ .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" },
3184
+ .{ .ts_import = "ts_host_core", .shim_import = "shim_host_core", .contract_name = "host-fixture", .core_mod = fixture_mod, .entry = "tests/ts-core/fixture.ts", .f64_slots = &.{"Model.pastBytes"} },
3185
+ .{ .ts_import = "ts_soundboard_core", .shim_import = "shim_soundboard_core", .contract_name = "soundboard", .core_mod = soundboard_core_mod, .entry = "examples/soundboard-ts/src/core.ts" },
3186
+ .{ .ts_import = "ts_monitor_core", .shim_import = "shim_monitor_core", .contract_name = "system-monitor", .core_mod = monitor_core_mod, .entry = "examples/system-monitor-ts/src/core.ts" },
3187
+ .{ .ts_import = "ts_ai_chat_core", .shim_import = "shim_ai_chat_core", .contract_name = "ai-chat", .core_mod = ai_chat_core_mod, .entry = "examples/ai-chat-ts/src/core.ts" },
3141
3188
  };
3142
3189
  // The corpus contract artifacts an external core toolchain consumes
3143
- // (stage-core-contracts): the extracted sidecar plus its facade
3144
- // projection, per fixture.
3190
+ // (stage-core-contracts): the effective sidecar plus its generated
3191
+ // entry module and compiler profile, per fixture.
3145
3192
  var core_contracts: std.ArrayList(CoreContract) = .empty;
3146
3193
  {
3147
3194
  const markup_sidecar = sidecarExtractJson(b, target, optimize, extract_mod, markup_fixture_mod, "tests/ts-core/markup_fixture.ts");
3195
+ const projections = facadeProjections(b, corewire_exe, markup_sidecar, &.{});
3148
3196
  core_contracts.append(b.allocator, .{
3149
3197
  .name = "markup-fixture",
3150
- .sidecar = markup_sidecar,
3151
- .facade = facadeTsFile(b, corewire_exe, markup_sidecar),
3198
+ .sidecar = projections.sidecar,
3199
+ .facade = projections.facade,
3200
+ .profile = projections.profile,
3152
3201
  }) catch @panic("OOM");
3153
3202
  }
3154
3203
  for (conformance_fixtures) |fixture| {
3155
3204
  const sidecar_json = sidecarExtractJson(b, target, optimize, extract_mod, fixture.core_mod, fixture.entry);
3156
3205
  conformance_mod.addImport(fixture.ts_import, fixture.core_mod);
3157
3206
  conformance_mod.addImport(fixture.shim_import, sidecarShimModule(b, target, optimize, corewire_exe, sidecar_json));
3158
- conformance_mod.addImport(fixture.facade_import, facadeCoreModule(b, target, optimize, node, corewire_exe, sidecar_json));
3207
+ const projections = facadeProjections(b, corewire_exe, sidecar_json, fixture.f64_slots);
3159
3208
  core_contracts.append(b.allocator, .{
3160
3209
  .name = fixture.contract_name,
3161
- .sidecar = sidecar_json,
3162
- .facade = facadeTsFile(b, corewire_exe, sidecar_json),
3210
+ .sidecar = projections.sidecar,
3211
+ .facade = projections.facade,
3212
+ .profile = projections.profile,
3163
3213
  }) catch @panic("OOM");
3164
3214
  }
3165
3215
 
@@ -3192,17 +3242,12 @@ fn tsCoreE2eArtifact(
3192
3242
  while (inputs.next()) |input| {
3193
3243
  parity_mod.addObjectFile(.{ .cwd_relative = b.dupe(input) });
3194
3244
  }
3195
- const parity_tests = filteredTestArtifact(b, parity_mod, "external-core-parity-tests", &.{});
3196
- // Run the checker over the supplied sidecar explicitly (the
3197
- // shim generation above validates too, but the checker tier —
3198
- // both projections, integer_slots structural rules included —
3199
- // is the surface an external compile is verified against).
3200
- const check_sidecar = b.addRunArtifact(corewire_exe);
3201
- check_sidecar.addArg("--sidecar");
3202
- check_sidecar.addFileArg(parity_sidecar);
3203
- check_sidecar.addArg("--check");
3204
- parity_tests.step.dependOn(&check_sidecar.step);
3205
- break :blk parity_tests;
3245
+ // The generated mirror is the only projection this lane uses;
3246
+ // sidecarShimModule validates exactly that surface. Do not run
3247
+ // the all-projections checker here: an external compiler's
3248
+ // sidecar may legitimately predate facade-only metadata while
3249
+ // remaining a valid mirror contract for its linked archive.
3250
+ break :blk filteredTestArtifact(b, parity_mod, "external-core-parity-tests", &.{});
3206
3251
  } else null;
3207
3252
 
3208
3253
  // The full-corpus compiled-core batteries: each supplied fixture's
@@ -3247,14 +3292,6 @@ fn tsCoreE2eArtifact(
3247
3292
  battery_mod.addImport(entry.core_import, paired_mod);
3248
3293
  if (entry.second_import) |second| battery_mod.addImport(second, entry.second_mod.?);
3249
3294
  const battery = filteredTestArtifact(b, battery_mod, b.fmt("compiled-core-{s}-tests", .{entry.name}), &.{});
3250
- // Run the checker tier over the supplied sidecar explicitly —
3251
- // the same surface an external compile is verified against in
3252
- // the markup parity suite.
3253
- const check_sidecar = b.addRunArtifact(corewire_exe);
3254
- check_sidecar.addArg("--sidecar");
3255
- check_sidecar.addFileArg(supply.sidecar);
3256
- check_sidecar.addArg("--check");
3257
- battery.step.dependOn(&check_sidecar.step);
3258
3295
  compiled_core_parity.append(b.allocator, .{ .name = b.dupe(entry.name), .tests = battery }) catch @panic("OOM");
3259
3296
  }
3260
3297
 
@@ -3331,18 +3368,36 @@ fn pairedCoreModule(
3331
3368
  return mod;
3332
3369
  }
3333
3370
 
3334
- /// A sidecar's TypeScript facade projection alone (core_facade.ts) —
3335
- /// the contract module an external core toolchain compiles.
3336
- fn facadeTsFile(
3371
+ const FacadeProjections = struct {
3372
+ sidecar: std.Build.LazyPath,
3373
+ facade: std.Build.LazyPath,
3374
+ profile: std.Build.LazyPath,
3375
+ };
3376
+
3377
+ /// A sidecar's compiled-core projections: the effective contract after
3378
+ /// caller-stated demotions, the generated entry module (core_facade.ts), and
3379
+ /// the compiler profile that builds it (core_profile.json), emitted by one
3380
+ /// corewire invocation so no staged sibling can describe a different layout.
3381
+ fn facadeProjections(
3337
3382
  b: *std.Build,
3338
3383
  corewire_exe: *std.Build.Step.Compile,
3339
3384
  sidecar_json: std.Build.LazyPath,
3340
- ) std.Build.LazyPath {
3385
+ f64_slots: []const []const u8,
3386
+ ) FacadeProjections {
3341
3387
  const generate = b.addRunArtifact(corewire_exe);
3342
3388
  generate.addArg("--sidecar");
3343
3389
  generate.addFileArg(sidecar_json);
3344
3390
  generate.addArg("--facade");
3345
- return generate.addOutputFileArg("core_facade.ts");
3391
+ const facade = generate.addOutputFileArg("core_facade.ts");
3392
+ generate.addArg("--profile");
3393
+ const profile = generate.addOutputFileArg("core_profile.json");
3394
+ generate.addArg("--effective-sidecar");
3395
+ const sidecar = generate.addOutputFileArg("core.contract.json");
3396
+ for (f64_slots) |slot| {
3397
+ generate.addArg("--f64-slot");
3398
+ generate.addArg(slot);
3399
+ }
3400
+ return .{ .sidecar = sidecar, .facade = facade, .profile = profile };
3346
3401
  }
3347
3402
 
3348
3403
  /// One fixture's generated-mirror module: run corewire over the
@@ -3372,50 +3427,6 @@ fn sidecarShimModule(
3372
3427
  });
3373
3428
  }
3374
3429
 
3375
- /// One fixture's compiled-facade module: run corewire over the sidecar
3376
- /// for its TypeScript projection (core_facade.ts), then compile that
3377
- /// projection through the shipped transpiler — the checker/emitter tier
3378
- /// is the compile, so this step IS the subset-acceptance proof — and
3379
- /// stage the emitted Zig beside its rt kernel like any fixture core.
3380
- fn facadeCoreModule(
3381
- b: *std.Build,
3382
- target: std.Build.ResolvedTarget,
3383
- optimize: std.builtin.OptimizeMode,
3384
- node: []const u8,
3385
- corewire_exe: *std.Build.Step.Compile,
3386
- sidecar_json: std.Build.LazyPath,
3387
- ) *std.Build.Module {
3388
- const generate = b.addRunArtifact(corewire_exe);
3389
- generate.addArg("--sidecar");
3390
- generate.addFileArg(sidecar_json);
3391
- generate.addArg("--facade");
3392
- const facade_ts = generate.addOutputFileArg("core_facade.ts");
3393
- const staged_ts = b.addWriteFiles();
3394
- const facade_entry = staged_ts.addCopyFile(facade_ts, "core.ts");
3395
-
3396
- const transpile = b.addSystemCommand(&.{node});
3397
- transpile.addFileArg(b.path("packages/core/src/cli.ts"));
3398
- transpile.addFileArg(facade_entry);
3399
- transpile.addArg("-o");
3400
- const emitted_core = transpile.addOutputFileArg("core.zig");
3401
- tsCoreAddDirInputs(b, transpile, "packages/core/sdk");
3402
- const transpiler_sources = [_][]const u8{
3403
- "checker.ts", "cli.ts", "diagnostics.ts", "emitter.ts", "infer.ts", "modules.ts", "transpile.ts", "typed_ast.ts", "types.ts",
3404
- };
3405
- for (transpiler_sources) |source| {
3406
- transpile.addFileInput(b.path(b.fmt("packages/core/src/{s}", .{source})));
3407
- }
3408
-
3409
- const staged = b.addWriteFiles();
3410
- const core_root = staged.addCopyFile(emitted_core, "core.zig");
3411
- _ = staged.addCopyFile(b.path("packages/core/rt/rt.zig"), "rt.zig");
3412
- return b.createModule(.{
3413
- .root_source_file = core_root,
3414
- .target = target,
3415
- .optimize = optimize,
3416
- });
3417
- }
3418
-
3419
3430
  /// Extract a fixture's contract sidecar from its transpiled module
3420
3431
  /// (tools/corewire/extract.zig) — a generated one-line main per
3421
3432
  /// fixture, so corpus sidecars regenerate whenever the fixture or the
package/native-sdk.d.ts CHANGED
@@ -178,7 +178,10 @@ export type NativeSdkViewKind =
178
178
  | "progress_indicator"
179
179
  | "progressIndicator";
180
180
 
181
- export type NativeSdkGpuSurfaceBackend = "none" | "metal";
181
+ /** Concrete backend reported by GPU surface view and frame state. */
182
+ export type NativeSdkGpuSurfaceBackend = "none" | "metal" | "direct2d" | "software";
183
+ /** Portable backend request accepted when creating a GPU surface. */
184
+ export type NativeSdkGpuSurfaceBackendRequest = "metal" | "software";
182
185
  export type NativeSdkGpuSurfacePixelFormat = "none" | "bgra8_unorm";
183
186
  export type NativeSdkGpuSurfacePresentMode = "none" | "timer";
184
187
  export type NativeSdkGpuSurfaceAlphaMode = "none" | "opaque" | "premultiplied";
@@ -327,8 +330,8 @@ export interface NativeSdkCreateNativeViewOptions extends NativeSdkCreateViewBas
327
330
  kind: NativeSdkNativeViewKind;
328
331
  frame?: NativeSdkRect;
329
332
  url?: never;
330
- /** Only valid for gpu_surface views. Defaults to the first supported backend. */
331
- gpuBackend?: NativeSdkGpuSurfaceBackend;
333
+ /** Only valid for gpu_surface views. Omit to use the first supported backend. */
334
+ gpuBackend?: NativeSdkGpuSurfaceBackendRequest;
332
335
  /** Only valid for gpu_surface views. */
333
336
  gpuPixelFormat?: NativeSdkGpuSurfacePixelFormat;
334
337
  /** Only valid for gpu_surface views. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "The Native SDK: the complete toolkit for building native desktop applications — declarative markup, native rendering, WebView surfaces, and OS capabilities",
5
5
  "type": "module",
6
6
  "bin": {
@@ -32,14 +32,14 @@
32
32
  "@typescript/typescript6": "6.0.2"
33
33
  },
34
34
  "optionalDependencies": {
35
- "@native-sdk/cli-darwin-arm64": "0.7.0",
36
- "@native-sdk/cli-darwin-x64": "0.7.0",
37
- "@native-sdk/cli-linux-arm64-gnu": "0.7.0",
38
- "@native-sdk/cli-linux-arm64-musl": "0.7.0",
39
- "@native-sdk/cli-linux-x64-gnu": "0.7.0",
40
- "@native-sdk/cli-linux-x64-musl": "0.7.0",
41
- "@native-sdk/cli-win32-arm64": "0.7.0",
42
- "@native-sdk/cli-win32-x64": "0.7.0"
35
+ "@native-sdk/cli-darwin-arm64": "0.7.2",
36
+ "@native-sdk/cli-darwin-x64": "0.7.2",
37
+ "@native-sdk/cli-linux-arm64-gnu": "0.7.2",
38
+ "@native-sdk/cli-linux-arm64-musl": "0.7.2",
39
+ "@native-sdk/cli-linux-x64-gnu": "0.7.2",
40
+ "@native-sdk/cli-linux-x64-musl": "0.7.2",
41
+ "@native-sdk/cli-win32-arm64": "0.7.2",
42
+ "@native-sdk/cli-win32-x64": "0.7.2"
43
43
  },
44
44
  "repository": {
45
45
  "type": "git",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@native-sdk/core",
9
- "version": "0.7.0",
9
+ "version": "0.7.2",
10
10
  "devDependencies": {
11
11
  "@typescript/old": "npm:typescript@6.0.3",
12
12
  "@typescript/typescript6": "6.0.2"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.7.0",
3
+ "version": "0.7.2",
4
4
  "description": "The TypeScript authoring tier: the app-core subset, its dev-time transpiler to arena-backed Zig, and the SDK module cores import",
5
5
  "repository": {
6
6
  "type": "git",
@@ -216,11 +216,22 @@ function nextTextWordOffset(text: Uint8Array, offset: number): number {
216
216
  return cursor;
217
217
  }
218
218
 
219
+ /// The selection constructor: offsets are whole byte offsets by
220
+ /// contract, proven in place — range-guarded (an ordered comparison
221
+ /// excludes NaN) and stated whole with Math.trunc. A value outside the
222
+ /// provable ±(2^53 − 1) window clamps to 0, the same floor every
223
+ /// caller's snap already applies.
224
+ function caretSelectionAt(anchor: number, focus: number): TextSelection {
225
+ const wholeAnchor = anchor >= 0 && anchor <= 9007199254740991 ? Math.trunc(anchor) : 0;
226
+ const wholeFocus = focus >= 0 && focus <= 9007199254740991 ? Math.trunc(focus) : 0;
227
+ return { anchor: wholeAnchor, focus: wholeFocus };
228
+ }
229
+
219
230
  function snapTextCaretSelection(text: Uint8Array, selection: TextSelection): TextSelection {
220
- return {
221
- anchor: snapTextCaretOffset(text, selection.anchor),
222
- focus: snapTextCaretOffset(text, selection.focus),
223
- };
231
+ return caretSelectionAt(
232
+ snapTextCaretOffset(text, selection.anchor),
233
+ snapTextCaretOffset(text, selection.focus),
234
+ );
224
235
  }
225
236
 
226
237
  function snapTextRange(text: Uint8Array, range: TextRange): TextRange {
@@ -290,7 +301,7 @@ function replaceTextEditRange(
290
301
  );
291
302
  return {
292
303
  text: result.text,
293
- selection: { anchor: cursor, focus: cursor },
304
+ selection: caretSelectionAt(cursor, cursor),
294
305
  composition: composition,
295
306
  };
296
307
  }
@@ -308,7 +319,7 @@ function setTextComposition(
308
319
  const absoluteCursor = snapTextCaretOffset(result.text, result.insertedStart + cursor);
309
320
  return {
310
321
  text: result.text,
311
- selection: { anchor: absoluteCursor, focus: absoluteCursor },
322
+ selection: caretSelectionAt(absoluteCursor, absoluteCursor),
312
323
  composition: { start: result.insertedStart, end: result.insertedEnd },
313
324
  };
314
325
  }
@@ -320,10 +331,10 @@ function cancelTextComposition(state: TextEditState, capacity: number): TextEdit
320
331
  if (result === null) return null;
321
332
  return {
322
333
  text: result.text,
323
- selection: snapTextCaretSelection(result.text, {
324
- anchor: result.insertedStart,
325
- focus: result.insertedStart,
326
- }),
334
+ selection: snapTextCaretSelection(
335
+ result.text,
336
+ caretSelectionAt(result.insertedStart, result.insertedStart),
337
+ ),
327
338
  composition: null,
328
339
  };
329
340
  }
@@ -355,7 +366,7 @@ function deleteForwardTextEdit(state: TextEditState, capacity: number): TextEdit
355
366
  const caret = snapTextCaretOffset(state.text, state.selection.focus);
356
367
  if (caret >= state.text.length) {
357
368
  const len = state.text.length;
358
- return { text: state.text, selection: { anchor: len, focus: len }, composition: null };
369
+ return { text: state.text, selection: caretSelectionAt(len, len), composition: null };
359
370
  }
360
371
  return replaceTextEditRange(
361
372
  state,
@@ -394,7 +405,7 @@ function deleteWordForwardTextEdit(state: TextEditState, capacity: number): Text
394
405
  const caret = snapTextCaretOffset(state.text, state.selection.focus);
395
406
  if (caret >= state.text.length) {
396
407
  const len = state.text.length;
397
- return { text: state.text, selection: { anchor: len, focus: len }, composition: null };
408
+ return { text: state.text, selection: caretSelectionAt(len, len), composition: null };
398
409
  }
399
410
  return replaceTextEditRange(
400
411
  state,
@@ -425,8 +436,8 @@ function moveTextCaret(state: TextEditState, move: TextCaretMove): TextEditState
425
436
  target = state.text.length;
426
437
  }
427
438
  const selection: TextSelection = move.extend
428
- ? { anchor: state.selection.anchor, focus: target }
429
- : { anchor: target, focus: target };
439
+ ? caretSelectionAt(state.selection.anchor, target)
440
+ : caretSelectionAt(target, target);
430
441
  return {
431
442
  text: state.text,
432
443
  selection: snapTextCaretSelection(state.text, selection),
@@ -459,6 +459,7 @@ export class SubsetChecker {
459
459
  for (const file of this.files) this.checkModuleShape(file);
460
460
  this.checkEntryContract();
461
461
  this.checkNameCollisions();
462
+ this.checkGeneratedMetadataNames();
462
463
  this.checkModelHoldsData();
463
464
  this.checkModelTextIsBytes();
464
465
  this.checkCmdPurity();
@@ -1207,6 +1208,44 @@ export class SubsetChecker {
1207
1208
  }
1208
1209
  }
1209
1210
 
1211
+ /// NS1038 — fixed declarations consumed by the contract extractor share
1212
+ /// the emitted Zig namespace with authored declarations. Reserve the
1213
+ /// module-level type-origin table and each union's payload-member table so
1214
+ /// a valid TypeScript name fails with a teaching instead of duplicate Zig.
1215
+ private checkGeneratedMetadataNames(): void {
1216
+ const reportTypeOrigins = (name: ts.Identifier): void => {
1217
+ if (name.text === "type_origins") {
1218
+ this.report("NS1038", "`type_origins` collides with the generated contract type-origin metadata declaration.", name);
1219
+ }
1220
+ };
1221
+ for (const file of this.files) {
1222
+ for (const stmt of file.statements) {
1223
+ if (
1224
+ ts.isInterfaceDeclaration(stmt) ||
1225
+ ts.isTypeAliasDeclaration(stmt) ||
1226
+ ts.isClassDeclaration(stmt) ||
1227
+ ts.isFunctionDeclaration(stmt)
1228
+ ) {
1229
+ if (stmt.name) reportTypeOrigins(stmt.name);
1230
+ } else if (ts.isVariableStatement(stmt)) {
1231
+ for (const decl of stmt.declarationList.declarations) {
1232
+ if (ts.isIdentifier(decl.name)) reportTypeOrigins(decl.name);
1233
+ }
1234
+ }
1235
+ }
1236
+ for (const binding of exportListBindings(this.tast, file)) {
1237
+ if (binding.exportedName === "type_origins") {
1238
+ this.report("NS1038", "`type_origins` collides with the generated contract type-origin metadata declaration.", binding.spec.name);
1239
+ }
1240
+ }
1241
+ }
1242
+ for (const union of this.table.unions.values()) {
1243
+ if (union.arms.some((arm) => arm.fields.length === 1) && union.arms.some((arm) => arm.tag === "payload_members")) {
1244
+ this.report("NS1038", `Union \`${union.name}\` has an arm named \`payload_members\`, which collides with its generated single-payload metadata declaration.`, union.decl.name);
1245
+ }
1246
+ }
1247
+ }
1248
+
1210
1249
  /// NS1003: no function-typed fields anywhere in the model/message tree.
1211
1250
  private checkModelHoldsData(): void {
1212
1251
  const scanFields = (typeName: string, seen: Set<string>): void => {