@native-sdk/cli 0.9.2 → 0.9.3

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 (47) hide show
  1. package/build.zig +69 -1
  2. package/package.json +9 -9
  3. package/packages/core/package-lock.json +2 -2
  4. package/packages/core/package.json +1 -1
  5. package/packages/core/sdk/events.d.ts +7 -0
  6. package/packages/core/sdk/events.ts +26 -5
  7. package/packages/core/sdk/text.d.ts +4 -0
  8. package/packages/core/sdk/text.ts +51 -0
  9. package/packages/core/src/checker.ts +58 -1
  10. package/packages/core/src/contract.ts +5 -4
  11. package/packages/core/src/devhost_journal.mjs +2 -2
  12. package/packages/core/src/diagnostics.ts +2 -2
  13. package/packages/core/src/service_contract.ts +10 -0
  14. package/packages/core/src/typed_ast.ts +9 -7
  15. package/packages/core/src/types.ts +28 -8
  16. package/skill-data/automation/SKILL.md +4 -3
  17. package/skill-data/native-ui/SKILL.md +3 -1
  18. package/skill-data/ts-core/SKILL.md +7 -4
  19. package/src/app_runner/root.zig +208 -6
  20. package/src/app_runner/ts_core_main.zig +2 -0
  21. package/src/automation/protocol.zig +5 -1
  22. package/src/automation/snapshot.zig +119 -0
  23. package/src/platform/macos/appkit_host.m +79 -12
  24. package/src/platform/macos/root.zig +68 -5
  25. package/src/primitives/canvas/events.zig +79 -1
  26. package/src/primitives/canvas/root.zig +1 -0
  27. package/src/primitives/canvas/text_interaction.zig +23 -0
  28. package/src/primitives/canvas/text_tests.zig +45 -0
  29. package/src/primitives/canvas/ui.zig +11 -8
  30. package/src/primitives/canvas/ui_markup_compiled_tests.zig +3 -0
  31. package/src/primitives/canvas/ui_markup_reflect.zig +6 -5
  32. package/src/primitives/canvas/ui_markup_view_tests.zig +18 -2
  33. package/src/primitives/canvas/ui_tests.zig +37 -0
  34. package/src/primitives/canvas/widget_builtin_tests.zig +13 -0
  35. package/src/runtime/automation_snapshot.zig +4 -0
  36. package/src/runtime/canvas_widget_control_tests.zig +2 -0
  37. package/src/runtime/canvas_widget_text_tests.zig +124 -0
  38. package/src/runtime/native_command_event_tests.zig +29 -0
  39. package/src/runtime/session_journal.zig +21 -2
  40. package/src/runtime/ts_ui_app.zig +164 -1
  41. package/src/runtime/ui_app.zig +91 -18
  42. package/src/runtime/ui_app_tests.zig +232 -13
  43. package/src/runtime/view_widget_text.zig +1 -1
  44. package/src/tooling/verbs.zig +1 -0
  45. package/tools/corewire/emit.zig +31 -12
  46. package/tools/corewire/emit_facade.zig +57 -2
  47. package/tools/corewire/shim_rt.zig +20 -0
package/build.zig CHANGED
@@ -209,6 +209,24 @@ pub fn build(b: *std.Build) void {
209
209
  const app_runner_window_placement_mod = module(b, target, optimize, "src/app_runner/window_placement.zig");
210
210
  app_runner_window_placement_mod.addImport("native_sdk", desktop_mod);
211
211
  const app_runner_window_placement_tests = testArtifact(b, app_runner_window_placement_mod);
212
+ const app_runner_options = b.addOptions();
213
+ app_runner_options.addOption([]const u8, "platform", "null");
214
+ app_runner_options.addOption([]const u8, "trace", "off");
215
+ app_runner_options.addOption([]const u8, "web_engine", "system");
216
+ app_runner_options.addOption(bool, "debug_overlay", false);
217
+ app_runner_options.addOption(bool, "automation", false);
218
+ app_runner_options.addOption(bool, "web_layer", false);
219
+ const app_runner_mod = module(b, target, optimize, "src/app_runner/root.zig");
220
+ app_runner_mod.addImport("native_sdk", desktop_mod);
221
+ app_runner_mod.addImport("build_options", app_runner_options.createModule());
222
+ app_runner_mod.addImport("app_manifest_zon", b.createModule(.{ .root_source_file = b.path("tests/app-runner/menu_commands_fixture.zon") }));
223
+ const app_runner_migrations_mod = module(b, target, optimize, "src/app_runner/no_migrations.zig");
224
+ app_runner_migrations_mod.addImport("native_sdk", desktop_mod);
225
+ app_runner_mod.addImport("relational_migrations", app_runner_migrations_mod);
226
+ const app_runner_tests = testArtifact(b, app_runner_mod);
227
+ const app_runner_test_run = b.addRunArtifact(app_runner_tests);
228
+ const app_runner_test_step = b.step("test-app-runner", "Run framework app-runner manifest fallback tests");
229
+ app_runner_test_step.dependOn(&app_runner_test_run.step);
212
230
  desktop_mod.link_libc = true;
213
231
  if (target.result.os.tag == .macos) {
214
232
  const flags: []const []const u8 = if (b.sysroot) |sysroot|
@@ -607,6 +625,7 @@ pub fn build(b: *std.Build) void {
607
625
  test_step.dependOn(&b.addRunArtifact(json_tests).step);
608
626
  test_step.dependOn(&b.addRunArtifact(app_runner_assets_tests).step);
609
627
  test_step.dependOn(&b.addRunArtifact(app_runner_window_placement_tests).step);
628
+ test_step.dependOn(&app_runner_test_run.step);
610
629
  test_step.dependOn(&b.addRunArtifact(canvas_tests).step);
611
630
  test_step.dependOn(&b.addRunArtifact(record_store_tests).step);
612
631
  test_step.dependOn(&file_crash_run.step);
@@ -2158,6 +2177,52 @@ pub fn build(b: *std.Build) void {
2158
2177
  native_shell_smoke_run.step.dependOn(&cli_exe.step);
2159
2178
  native_shell_smoke_step.dependOn(&native_shell_smoke_run.step);
2160
2179
 
2180
+ const menu_bar_smoke_step = b.step("test-menu-bar-smoke", "Run zero-config TypeScript app-menu automation smoke test");
2181
+ const menu_bar_smoke_build = managedExampleRun(b, cli_exe, &.{ "build", "-Dplatform=macos", "-Dweb-engine=system", "-Dautomation=true", "-Doptimize=Debug" });
2182
+ menu_bar_smoke_build.setCwd(b.path("examples/menu-bar"));
2183
+ const menu_bar_smoke_run = b.addSystemCommand(&.{
2184
+ "sh", "-c",
2185
+ \\set -eu
2186
+ \\cd examples/menu-bar
2187
+ \\app="zig-out/bin/menu-bar"
2188
+ \\cli="$1"
2189
+ \\case "$cli" in /*) ;; *) cli="../../$cli" ;; esac
2190
+ \\automation_dir=".zig-cache/native-sdk-automation"
2191
+ \\mkdir -p "$automation_dir"
2192
+ \\rm -f "$automation_dir/snapshot.txt" "$automation_dir/accessibility.txt" "$automation_dir/windows.txt" "$automation_dir"/command*.txt
2193
+ \\"$app" > .zig-cache/native-sdk-menu-bar-smoke.log 2>&1 &
2194
+ \\pid=$!
2195
+ \\trap 'status=$?; kill "$pid" >/dev/null 2>&1 || true; wait "$pid" >/dev/null 2>&1 || true; if [ "$status" -ne 0 ]; then echo "---- app log (.zig-cache/native-sdk-menu-bar-smoke.log) ----" >&2; cat .zig-cache/native-sdk-menu-bar-smoke.log >&2 2>/dev/null || true; fi' EXIT
2196
+ \\ready="$("$cli" automate wait 2>&1)"
2197
+ \\case "$ready" in *"ready=true"*) ;; *) echo "menu-bar automation snapshot was not ready" >&2; exit 1 ;; esac
2198
+ \\before="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
2199
+ \\case "$before" in *'command id="player.next" title="Next Track" enabled=true checked=false'*) ;; *) echo "app.zon command catalog was not loaded by the zero-config runner" >&2; exit 1 ;; esac
2200
+ \\case "$before" in *'app-menu title="Player" items=6'*) ;; *) echo "app.zon Player menu was not loaded by the zero-config runner" >&2; exit 1 ;; esac
2201
+ \\case "$before" in *'app-menu-item label="Next Track" command="player.next" enabled=true checked=false key="n" modifiers=(primary=true,command=false,control=false,option=false,shift=false)'*) ;; *) echo "app.zon player.next menu item was not loaded by the zero-config runner" >&2; exit 1 ;; esac
2202
+ \\case "$before" in
2203
+ \\ *'Ambient Coast'*) expected='Night Drive' ;;
2204
+ \\ *'Night Drive'*) expected='Paper Planes' ;;
2205
+ \\ *'Paper Planes'*) expected='Ambient Coast' ;;
2206
+ \\ *) echo "menu-bar snapshot did not expose the current TypeScript model track" >&2; exit 1 ;;
2207
+ \\esac
2208
+ \\"$cli" automate menu-command player.next >/dev/null 2>&1
2209
+ \\attempts=0
2210
+ \\while [ "$attempts" -lt 50 ]; do
2211
+ \\ snapshot="$(cat "$automation_dir/snapshot.txt" 2>/dev/null || true)"
2212
+ \\ case "$snapshot" in *"$expected"*) break ;; esac
2213
+ \\ attempts=$((attempts + 1))
2214
+ \\ sleep 0.1
2215
+ \\done
2216
+ \\case "$snapshot" in *"$expected"*) ;; *) echo "app.zon menu command did not reach the zero-config TypeScript commandMsg mapper" >&2; exit 1 ;; esac
2217
+ \\echo "menu-bar smoke ok"
2218
+ ,
2219
+ "sh",
2220
+ });
2221
+ menu_bar_smoke_run.addFileArg(cli_exe.getEmittedBin());
2222
+ menu_bar_smoke_run.step.dependOn(&menu_bar_smoke_build.step);
2223
+ menu_bar_smoke_run.step.dependOn(&cli_exe.step);
2224
+ menu_bar_smoke_step.dependOn(&menu_bar_smoke_run.step);
2225
+
2161
2226
  const gpu_surface_smoke_step = b.step("test-gpu-surface-smoke", "Run macOS GPU surface automation smoke test");
2162
2227
  // The GPU smoke apps are managed examples (no build.zig of their own),
2163
2228
  // so their binaries come from the CLI verb. -Doptimize=Debug keeps the
@@ -2648,7 +2713,7 @@ pub fn build(b: *std.Build) void {
2648
2713
  \\case "$ready_snapshot" in *'view @w1/components-canvas kind=gpu_surface'*'gpu_nonblank=true'*'canvas_frame_gpu_packet_representable=true'*) ;; *) echo "component gallery GPU surface was not ready" >&2; exit 1 ;; esac
2649
2714
  \\case "$ready_snapshot" in *'view @w1/main kind=webview'*) echo "component gallery created an implicit WebView" >&2; exit 1 ;; *) ;; esac
2650
2715
  \\"$cli" automate assert 'role=tree name="Components"' 'role=treeitem name="Components".*state=\[expanded\]' 'role=treeitem name="Accordion".*state=\[selected\]' 'role=group name="Details".*state=\[selected,expanded\]' 'name="Accordion details are visible. The model owns this expanded state."'
2651
- \\"$cli" automate assert 'role=group name="Theme"' 'role=button name="Default".*state=\[selected\]' 'role=button name="Geist"'
2716
+ \\"$cli" automate assert 'role=group name="Theme pack"' 'role=group name="Color scheme"' 'role=group name="Theme accent"' 'role=button name="Default".*state=\[selected\]' 'role=button name="Geist"' 'role=button name="System".*state=\[selected\]' 'role=button name="Pink"' 'role=button name="Teal"'
2652
2717
  \\"$cli" automate screenshot components-canvas >/dev/null 2>&1
2653
2718
  \\cp "$automation_dir/screenshot-components-canvas.png" "$automation_dir/screenshot-components-house.png"
2654
2719
  \\rm -f "$automation_dir/screenshot-components-canvas.png"
@@ -3515,6 +3580,9 @@ fn tsCoreE2eArtifact(
3515
3580
  // against (the same module the generated shims stage).
3516
3581
  conformance_mod.addImport("corewire_rt", module(b, target, optimize, "tools/corewire/shim_rt.zig"));
3517
3582
  conformance_mod.addImport("shim_markup_core", sidecarShimModule(b, target, optimize, corewire_exe, b.path("tests/sidecar/markup_fixture.contract.json")));
3583
+ // Compile-cost guard: this generated mirror carries 160 realistically
3584
+ // named Msg arms and must need no quota setting in app or test code.
3585
+ conformance_mod.addImport("shim_wide_core", sidecarShimModule(b, target, optimize, corewire_exe, b.path("tests/sidecar/wide_msg_fixture.contract.json")));
3518
3586
  // The integer-class fixture: a hand-written sidecar attesting mixed
3519
3587
  // i64/u64 slot classes, so the suite drives boundary and full-range
3520
3588
  // integer values through a generated mirror's decode paths.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/cli",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
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": {
@@ -35,14 +35,14 @@
35
35
  "scriptc": "0.0.31"
36
36
  },
37
37
  "optionalDependencies": {
38
- "@native-sdk/cli-darwin-arm64": "0.9.2",
39
- "@native-sdk/cli-darwin-x64": "0.9.2",
40
- "@native-sdk/cli-linux-arm64-gnu": "0.9.2",
41
- "@native-sdk/cli-linux-arm64-musl": "0.9.2",
42
- "@native-sdk/cli-linux-x64-gnu": "0.9.2",
43
- "@native-sdk/cli-linux-x64-musl": "0.9.2",
44
- "@native-sdk/cli-win32-arm64": "0.9.2",
45
- "@native-sdk/cli-win32-x64": "0.9.2"
38
+ "@native-sdk/cli-darwin-arm64": "0.9.3",
39
+ "@native-sdk/cli-darwin-x64": "0.9.3",
40
+ "@native-sdk/cli-linux-arm64-gnu": "0.9.3",
41
+ "@native-sdk/cli-linux-arm64-musl": "0.9.3",
42
+ "@native-sdk/cli-linux-x64-gnu": "0.9.3",
43
+ "@native-sdk/cli-linux-x64-musl": "0.9.3",
44
+ "@native-sdk/cli-win32-arm64": "0.9.3",
45
+ "@native-sdk/cli-win32-x64": "0.9.3"
46
46
  },
47
47
  "repository": {
48
48
  "type": "git",
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@native-sdk/core",
9
- "version": "0.9.2",
9
+ "version": "0.9.3",
10
10
  "dependencies": {
11
11
  "scriptc": "0.0.31"
12
12
  },
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@native-sdk/core",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "description": "The TypeScript authoring tier: the app-core subset, its checker and contract frontend, the exact-pinned core compiler dependency, and the SDK module cores import",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,4 +1,11 @@
1
1
  export type { TextCaretDirection, TextCaretMove, TextSelection, TextInputEvent } from "./text.js";
2
+ export type ThemeStatePack = "house" | "geist";
3
+ export type ThemeStateColorScheme = "light" | "dark" | "system";
4
+ export type ThemeState = {
5
+ readonly pack?: ThemeStatePack;
6
+ readonly colorScheme?: ThemeStateColorScheme;
7
+ readonly accent?: string;
8
+ };
2
9
  export type StatusItemTone = "normal" | "warning" | "critical";
3
10
  export type StatusItemMenuRole = "command" | "info" | "header" | "hero" | "agent" | "context";
4
11
  export interface StatusItemModifiers {
@@ -37,6 +37,8 @@
37
37
  // - `AppearanceEvent`, `ChromeEvent`, `AudioEvent`: the full arm
38
38
  // payload shapes, canonical and importable for helper signatures
39
39
  // (an arm value is structurally assignable to its event record).
40
+ // - `ThemeState`: the model-derived built-in theme axes returned by
41
+ // `themeState(model)`; omitted fields inherit the manifest/system.
40
42
  // - `StatusItemState`, `StatusItemDescriptor`, and their nested records:
41
43
  // the model-derived shell returned by `statusItem(model)` or keyed
42
44
  // `statusItems(model)`; the generated launcher refreshes shell,
@@ -44,6 +46,20 @@
44
46
 
45
47
  export type { TextCaretDirection, TextCaretMove, TextSelection, TextInputEvent } from "./text.ts";
46
48
 
49
+ /// The stock theme axes a TypeScript core may derive from committed model
50
+ /// state. Omit `pack`/`accent` to inherit app.zon; omit `colorScheme` (or
51
+ /// return `"system"`) to follow the OS. High contrast and reduced motion
52
+ /// remain system-owned, and high contrast suppresses accent overrides.
53
+ export type ThemeStatePack = "house" | "geist";
54
+
55
+ export type ThemeStateColorScheme = "light" | "dark" | "system";
56
+
57
+ export type ThemeState = {
58
+ readonly pack?: ThemeStatePack;
59
+ readonly colorScheme?: ThemeStateColorScheme;
60
+ readonly accent?: string;
61
+ };
62
+
47
63
  /// One row in a menu-bar status item's menu. Non-separator rows need a
48
64
  /// unique non-zero `id`, a non-empty `label`, and (when actionable) a
49
65
  /// command name accepted by `commandMsg`. Rich readout roles may carry
@@ -247,8 +263,10 @@ export interface PinchEvent {
247
263
  readonly y: number;
248
264
  }
249
265
 
250
- /// A file drop's optional point in view-local canvas coordinates. Desktop
251
- /// hosts that only know the target window leave `FileDropEvent.point` null.
266
+ /// A file drop's optional point in top-left-origin local coordinates. A
267
+ /// non-empty `FileDropEvent.viewLabel` names its canvas or WebView coordinate
268
+ /// space; an empty label may carry window-content coordinates. Hosts that
269
+ /// cannot resolve local coordinates leave `FileDropEvent.point` null.
252
270
  export interface FileDropPoint {
253
271
  readonly x: number;
254
272
  readonly y: number;
@@ -256,9 +274,12 @@ export interface FileDropPoint {
256
274
 
257
275
  /// The app-level file-drop channel's record (`dropMsg(drop)`). `windowId`
258
276
  /// and `viewLabel` identify the source; `point` is present when the host can
259
- /// resolve view-local coordinates. Paths are byte text so arbitrary UTF-8
260
- /// filesystem names cross without becoming runtime JS strings. Return null
261
- /// from `dropMsg` to ignore a drop, or map it to an ordinary Msg.
277
+ /// resolve local coordinates. The macOS system host reports labeled canvas or
278
+ /// WebView coordinates and degrades unlabeled regions to window-content
279
+ /// coordinates; hosts without either leave `point` null. Paths are byte text
280
+ /// so arbitrary UTF-8 filesystem names cross without becoming runtime JS
281
+ /// strings. Return null from `dropMsg` to ignore a drop, or map it to an
282
+ /// ordinary Msg.
262
283
  export interface FileDropEvent {
263
284
  readonly windowId: number;
264
285
  readonly viewLabel: string;
@@ -22,6 +22,10 @@ export type TextInputEvent = {
22
22
  readonly kind: "delete_word_backward";
23
23
  } | {
24
24
  readonly kind: "delete_word_forward";
25
+ } | {
26
+ readonly kind: "delete_to_start";
27
+ } | {
28
+ readonly kind: "delete_to_line_start";
25
29
  } | {
26
30
  readonly kind: "clear";
27
31
  } | {
@@ -56,6 +56,8 @@ export type TextInputEvent =
56
56
  | { readonly kind: "delete_forward" }
57
57
  | { readonly kind: "delete_word_backward" }
58
58
  | { readonly kind: "delete_word_forward" }
59
+ | { readonly kind: "delete_to_start" }
60
+ | { readonly kind: "delete_to_line_start" }
59
61
  | { readonly kind: "clear" }
60
62
  | { readonly kind: "move_caret"; readonly move: TextCaretMove }
61
63
  | { readonly kind: "set_selection"; readonly selection: TextSelection }
@@ -417,6 +419,51 @@ function deleteWordForwardTextEdit(state: TextEditState, capacity: number): Text
417
419
  );
418
420
  }
419
421
 
422
+ function textLineStartOffset(text: Uint8Array, offset: number): number {
423
+ let cursor = snapTextOffset(text, offset);
424
+ while (cursor > 0 && text[cursor - 1] !== 0x0a) cursor -= 1;
425
+ return cursor;
426
+ }
427
+
428
+ function deleteToStartTextEdit(state: TextEditState, capacity: number): TextEditState | null {
429
+ const range = activeTextReplaceRange(state);
430
+ if (!rangeIsCollapsed(range, state.text.length)) {
431
+ return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
432
+ }
433
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
434
+ if (caret === 0) {
435
+ return { text: state.text, selection: caretSelectionAt(0, 0), composition: null };
436
+ }
437
+ return replaceTextEditRange(
438
+ state,
439
+ { start: 0, end: caret },
440
+ new Uint8Array(0),
441
+ capacity,
442
+ null,
443
+ 0,
444
+ );
445
+ }
446
+
447
+ function deleteToLineStartTextEdit(state: TextEditState, capacity: number): TextEditState | null {
448
+ const range = activeTextReplaceRange(state);
449
+ if (!rangeIsCollapsed(range, state.text.length)) {
450
+ return replaceTextEditRange(state, range, new Uint8Array(0), capacity, null, 0);
451
+ }
452
+ const caret = snapTextCaretOffset(state.text, state.selection.focus);
453
+ const lineStart = textLineStartOffset(state.text, caret);
454
+ if (lineStart === caret) {
455
+ return { text: state.text, selection: caretSelectionAt(caret, caret), composition: null };
456
+ }
457
+ return replaceTextEditRange(
458
+ state,
459
+ { start: lineStart, end: caret },
460
+ new Uint8Array(0),
461
+ capacity,
462
+ null,
463
+ 0,
464
+ );
465
+ }
466
+
420
467
  function moveTextCaret(state: TextEditState, move: TextCaretMove): TextEditState {
421
468
  const range = selectionRange(state.selection, state.text.length);
422
469
  const focus = snapTextCaretOffset(state.text, state.selection.focus);
@@ -472,6 +519,10 @@ export function applyTextInputEvent(
472
519
  return deleteWordBackwardTextEdit(normalized, capacity);
473
520
  case "delete_word_forward":
474
521
  return deleteWordForwardTextEdit(normalized, capacity);
522
+ case "delete_to_start":
523
+ return deleteToStartTextEdit(normalized, capacity);
524
+ case "delete_to_line_start":
525
+ return deleteToLineStartTextEdit(normalized, capacity);
475
526
  case "clear":
476
527
  return { text: new Uint8Array(0), selection: { anchor: 0, focus: 0 }, composition: null };
477
528
  case "move_caret":
@@ -507,6 +507,7 @@ export class SubsetChecker {
507
507
  this.checkModelBindingSurface();
508
508
  this.checkMigrationHook();
509
509
  this.checkThemePackHelper();
510
+ this.checkThemeStateHelper();
510
511
  this.checkStatusItemHelper();
511
512
  this.checkStatusItemsHelper();
512
513
  this.checkWindowsHelper();
@@ -843,6 +844,55 @@ export class SubsetChecker {
843
844
  }
844
845
  }
845
846
 
847
+ /// `themeState(model)` subsumes themePack with one exact, projection-safe
848
+ /// record. Optional properties are intentional: omission is the manifest /
849
+ /// system inheritance signal that crosses the helper ABI as null.
850
+ private checkThemeStateHelper(): void {
851
+ const decl = this.entryExportedFunction("themeState");
852
+ if (decl === null) return;
853
+
854
+ if (this.table.modelHelperDecls().some((candidate) => candidate.name === "themePack")) {
855
+ this.report("NS1033", "Export either `themePack` or `themeState`, not both.", decl.name ?? decl);
856
+ }
857
+
858
+ const helper = this.table.modelHelperDecls().find(
859
+ (candidate) => candidate.name === "themeState" && candidate.decl === decl,
860
+ );
861
+ if (helper === undefined || decl.type === undefined) {
862
+ this.report(
863
+ "NS1033",
864
+ "`themeState` is not a single-Model-parameter helper with an explicit return type.",
865
+ decl.name ?? decl,
866
+ );
867
+ return;
868
+ }
869
+
870
+ const returns = this.table.resolveTypeNode(decl.type);
871
+ const state = returns.k === "struct" ? this.table.structs.get(returns.name) : undefined;
872
+ const names = state?.fields.map((field) => field.tsName).sort() ?? [];
873
+ const field = (name: string) => state?.fields.find((candidate) => candidate.tsName === name);
874
+ const pack = field("pack");
875
+ const colorScheme = field("colorScheme");
876
+ const accent = field("accent");
877
+ const optionalEnumMembersAre = (candidate: typeof pack, expected: readonly string[]): boolean => {
878
+ if (candidate?.type.k !== "optional" || candidate.type.inner.k !== "enum") return false;
879
+ const found = this.table.enums.get(candidate.type.inner.name)?.members.slice().sort() ?? [];
880
+ return found.join(",") === expected.slice().sort().join(",");
881
+ };
882
+ const valid =
883
+ names.join(",") === "accent,colorScheme,pack" &&
884
+ optionalEnumMembersAre(pack, ["house", "geist"]) &&
885
+ optionalEnumMembersAre(colorScheme, ["light", "dark", "system"]) &&
886
+ accent?.type.k === "optional" && accent.type.inner.k === "string";
887
+ if (!valid) {
888
+ this.report(
889
+ "NS1033",
890
+ "`themeState` must return the exact canonical `ThemeState` record (`pack?`, `colorScheme?`, `accent?`); import it from `@native-sdk/core/events`.",
891
+ decl.type,
892
+ );
893
+ }
894
+ }
895
+
846
896
  /// Persistence migration is a pure entry hook, not a model helper. It
847
897
  /// receives the previous canonical snapshot and monotonic schema version;
848
898
  /// returning the current Model succeeds, while throwing closes as
@@ -1871,7 +1921,7 @@ export class SubsetChecker {
1871
1921
  /// entry points, but the exports themselves live in the entry module.
1872
1922
  private static readonly entryOnlyExports = new Set([
1873
1923
  "update", "initialModel", "subscriptions", "migrate",
1874
- "commandMsg", "keyMsg", "frameMsg", "pinchMsg", "dropMsg", "appearanceMsg", "chromeMsg", "envMsgs", "themePack", "statusItem", "statusItems", "windows",
1924
+ "commandMsg", "keyMsg", "frameMsg", "pinchMsg", "dropMsg", "appearanceMsg", "chromeMsg", "envMsgs", "themePack", "themeState", "statusItem", "statusItems", "windows",
1875
1925
  "viewUnbound", "modelUnbound", "msgUnbound",
1876
1926
  ]);
1877
1927
 
@@ -2039,6 +2089,13 @@ export class SubsetChecker {
2039
2089
  : this.table.unions.get(typeName)?.arms.flatMap((a) => [...a.fields]) ?? [];
2040
2090
  for (const f of fields) {
2041
2091
  const decl = f.decl;
2092
+ if (ts.isPropertySignature(decl) && decl.questionToken) {
2093
+ this.report(
2094
+ "NS1012",
2095
+ `Optional field \`${f.tsName}?\` in the ${typeName} tree has an implicit undefined state — spell the empty explicitly as \`${f.tsName}: T | null\`.`,
2096
+ decl,
2097
+ );
2098
+ }
2042
2099
  if (ts.isPropertySignature(decl) && decl.type && ts.isFunctionTypeNode(decl.type)) {
2043
2100
  this.report("NS1003", `\`${f.tsName}\` stores a function in the ${typeName} tree.`, decl);
2044
2101
  }
@@ -457,10 +457,11 @@ class ContractEmitter {
457
457
  }
458
458
  }
459
459
  }
460
- // `statusItem` is consumed by the generated launcher, not markup. It
461
- // is still an ordinary Model helper in the core ABI, so teach native
462
- // check that this one helper is intentionally shell-bound without
463
- // making every app repeat it in `viewUnbound`.
460
+ // These helpers are consumed by the generated launcher, not markup.
461
+ // They remain ordinary Model helpers in the core ABI, so teach native
462
+ // check that they are intentionally shell-bound without making every
463
+ // app repeat them in `viewUnbound`.
464
+ if (helperNames.includes("themeState") && !model.includes("themeState")) model.push("themeState");
464
465
  if (helperNames.includes("statusItem") && !model.includes("statusItem")) model.push("statusItem");
465
466
  if (helperNames.includes("statusItems") && !model.includes("statusItems")) model.push("statusItems");
466
467
  if (helperNames.includes("windows") && !model.includes("windows")) model.push("windows");
@@ -5,8 +5,8 @@ import fs from "node:fs";
5
5
  // recordings.
6
6
  // EffectFileOp appended `delete`; the reflected journal layout fingerprint
7
7
  // moves so older recordings refuse cleanly instead of decoding op 8 wrongly.
8
- export const journalFormatFingerprint = 0xb3bd2e83971de44dn;
9
- export const automationProtocolFingerprint = 0x59d66f39803fd602n;
8
+ export const journalFormatFingerprint = 0xc510d4b0292ac71an;
9
+ export const automationProtocolFingerprint = 0x51f7889bbe3305e7n;
10
10
 
11
11
  const requestKeyBase = 0x5453525100000000n;
12
12
  const textEncoder = new TextEncoder();
@@ -125,7 +125,7 @@ export const rules = {
125
125
  id: "NS1014",
126
126
  title: "the core's entry points live in core.ts",
127
127
  fix: "Move this export into src/core.ts (imported modules may hold the helpers it calls and the types it uses).",
128
- why: "The build wires `update`, `initialModel`, `subscriptions`, the host-event channels, `themePack`, and `viewUnbound` from the entry module only, so an entry export in an imported file would be silently ignored.",
128
+ why: "The build wires `update`, `initialModel`, `subscriptions`, the host-event channels, `themeState` / `themePack`, and `viewUnbound` from the entry module only, so an entry export in an imported file would be silently ignored.",
129
129
  class: "guarantee",
130
130
  },
131
131
  NS1015: {
@@ -257,7 +257,7 @@ export const rules = {
257
257
  NS1033: {
258
258
  id: "NS1033",
259
259
  title: "wiring exports match their runtime shapes",
260
- fix: "Declare the channel exactly: `commandMsg(name: string)` / `keyMsg(key: KeyEvent)` / `frameMsg(model: Model, frame: FrameEvent)` / `pinchMsg(pinch: PinchEvent)` / `dropMsg(drop: FileDropEvent)` returning `Msg | null`; `themePack(model: Model): ThemePack`; singular `statusItem(model: Model): StatusItemState` or collection `statusItems(model: Model): readonly StatusItemDescriptor[]`; `windows(model: Model): readonly WindowDescriptor[]`, with each entry constructed by `windowDescriptor` and a literal `label: asciiBytes(\"name\")` matching `src/windows/name.native`; `appearanceMsg` / `chromeMsg` naming an arm with that channel's record shape; `envMsgs` entries targeting one-`Uint8Array`-field arms; and persistence ok/none routes naming void arms while err names a one-`Uint8Array`-field arm. Import canonical records from the SDK modules.",
260
+ fix: "Declare the channel exactly: `commandMsg(name: string)` / `keyMsg(key: KeyEvent)` / `frameMsg(model: Model, frame: FrameEvent)` / `pinchMsg(pinch: PinchEvent)` / `dropMsg(drop: FileDropEvent)` returning `Msg | null`; `themePack(model: Model): ThemePack` or `themeState(model: Model): ThemeState` (not both); singular `statusItem(model: Model): StatusItemState` or collection `statusItems(model: Model): readonly StatusItemDescriptor[]`; `windows(model: Model): readonly WindowDescriptor[]`, with each entry constructed by `windowDescriptor` and a literal `label: asciiBytes(\"name\")` matching `src/windows/name.native`; `appearanceMsg` / `chromeMsg` naming an arm with that channel's record shape; `envMsgs` entries targeting one-`Uint8Array`-field arms; and persistence ok/none routes naming void arms while err names a one-`Uint8Array`-field arm. Import canonical records from the SDK modules.",
261
261
  why: "The generated wiring builds host events, persistence restore results, model-derived theme/status/window declarations, and their typed callbacks structurally at build time; a wrong shape would otherwise surface as a Zig compile error inside generated code instead of a teaching diagnostic here.",
262
262
  class: "guarantee",
263
263
  },
@@ -258,6 +258,16 @@ class ServiceShapeTable {
258
258
  if (this.listed.has(name)) return;
259
259
  const info = this.table.structs.get(name);
260
260
  if (!info) throw new ServiceShapeError(`The shared type table has no record named \`${name}\``, this.fallbackSite);
261
+ const optionalField = info.fields.find((field) =>
262
+ (ts.isPropertySignature(field.decl) || ts.isPropertyDeclaration(field.decl)) &&
263
+ field.decl.questionToken !== undefined
264
+ );
265
+ if (optionalField) {
266
+ throw new ServiceShapeError(
267
+ `Service boundary record \`${name}\` has optional property \`${optionalField.tsName}?\`; spell absence explicitly as \`${optionalField.tsName}: T | null\` so both service codecs encode the same state`,
268
+ optionalField.decl,
269
+ );
270
+ }
261
271
  this.listed.add(name);
262
272
  const record: ServiceRecordType = {
263
273
  name,
@@ -340,18 +340,20 @@ export class TypedAst {
340
340
 
341
341
  /// Properties of an object-literal type alias body, in declaration
342
342
  /// order — null unless every member is a plain record property (an
343
- /// identifier-named, annotated, non-optional property signature), so
343
+ /// identifier-named, annotated property signature), so
344
344
  /// a shape this walk cannot carry whole refuses as an unsupported
345
- /// alias instead of registering a struct with silently missing
346
- /// fields.
347
- propsOfTypeLiteral(node: tsImpl.TypeLiteralNode): PropInfo[] | null {
345
+ /// alias instead of registering a struct with silently missing fields.
346
+ /// The one omission-carrying value record is the SDK-owned ThemeState;
347
+ /// its caller opts in explicitly so authored/service records keep the
348
+ /// fixed-shape rule.
349
+ propsOfTypeLiteral(node: tsImpl.TypeLiteralNode, allowOptional = false): PropInfo[] | null {
348
350
  const out: PropInfo[] = [];
349
351
  for (const member of node.members) {
350
- if (!tsImpl.isPropertySignature(member) || !member.name || !tsImpl.isIdentifier(member.name)) return null;
351
- if (member.questionToken || !member.type) return null;
352
+ if (!tsImpl.isPropertySignature(member) || !member.name || !tsImpl.isIdentifier(member.name) || !member.type) return null;
353
+ if (member.questionToken && !allowOptional) return null;
352
354
  out.push({
353
355
  name: member.name.text,
354
- optional: false,
356
+ optional: member.questionToken !== undefined,
355
357
  readonly: hasReadonlyModifier(member),
356
358
  typeNode: member.type,
357
359
  declaration: member,
@@ -12,7 +12,8 @@
12
12
  // T | null/undefined -> ?T (R7)
13
13
  // Uint8Array -> []const u8 (R3)
14
14
 
15
- import { ts, TypedAst, hasExportModifier, exportListBindings, type PropInfo } from "./typed_ast.ts";
15
+ import path from "node:path";
16
+ import { ts, TypedAst, hasExportModifier, exportListBindings, sdkLibraryModules, type PropInfo } from "./typed_ast.ts";
16
17
  import { mutatingMethodNames } from "./ownership.ts";
17
18
 
18
19
  export type ZType =
@@ -265,14 +266,17 @@ export class TypeTable {
265
266
  this.declOrder.push(name);
266
267
  continue;
267
268
  }
268
- if (ts.isTypeLiteralNode(stmt.type) && this.tast.propsOfTypeLiteral(stmt.type) !== null) {
269
+ const projectOptional = this.isCanonicalThemeState(stmt);
270
+ if (ts.isTypeLiteralNode(stmt.type) && this.tast.propsOfTypeLiteral(stmt.type, projectOptional) !== null) {
269
271
  // A plain-record object-literal alias is a struct exactly like
270
272
  // an interface; the alias FORM is how a contract projection
271
273
  // spells a value-stored record (interfaces spell node
272
274
  // storage), and the storage itself still comes from the
273
275
  // promotion walk. Shapes the plain-record walk cannot carry
274
276
  // whole (quoted or optional properties) stay unclassified and
275
- // refuse at emission instead of losing fields silently.
277
+ // refuse at emission instead of losing fields silently. The
278
+ // canonical SDK ThemeState is the sole optional-property record:
279
+ // omission is its manifest/system inheritance signal.
276
280
  this.structs.set(name, {
277
281
  name,
278
282
  decl: stmt,
@@ -319,18 +323,32 @@ export class TypeTable {
319
323
  }
320
324
  const structInfo = this.structs.get(stmt.name.text);
321
325
  if (structInfo && structInfo.decl === stmt && ts.isTypeLiteralNode(stmt.type)) {
322
- const props = this.tast.propsOfTypeLiteral(stmt.type);
323
- if (props) structInfo.fields = props.map((p) => this.fieldOf(p));
326
+ const projectOptional = this.isCanonicalThemeState(stmt);
327
+ const props = this.tast.propsOfTypeLiteral(stmt.type, projectOptional);
328
+ if (props) structInfo.fields = props.map((p) => this.fieldOf(p, projectOptional));
324
329
  }
325
330
  }
326
331
  }
327
332
  }
328
333
 
329
- private fieldOf(p: PropInfo): ZField {
334
+ private isCanonicalThemeState(decl: ts.TypeAliasDeclaration): boolean {
335
+ const events = sdkLibraryModules.get("@native-sdk/core/events");
336
+ return decl.name.text === "ThemeState" && events !== undefined &&
337
+ path.resolve(decl.getSourceFile().fileName) === path.resolve(events);
338
+ }
339
+
340
+ private fieldOf(p: PropInfo, projectOptional = false): ZField {
341
+ const resolved = p.typeNode ? this.resolveTypeNode(p.typeNode) : { k: "void" } as ZType;
330
342
  return {
331
343
  tsName: p.name,
332
344
  zigName: zigDeclName(p.name),
333
- type: p.typeNode ? this.resolveTypeNode(p.typeNode) : { k: "void" },
345
+ // Only the canonical ThemeState projects JS `undefined` omission onto
346
+ // the contract's ordinary optional slot. Applying this globally would
347
+ // let service records acquire an absent state while their generated
348
+ // codecs still accept only explicit null.
349
+ type: projectOptional && p.optional && resolved.k !== "void" && resolved.k !== "optional"
350
+ ? { k: "optional", inner: resolved }
351
+ : resolved,
334
352
  decl: p.declaration,
335
353
  };
336
354
  }
@@ -748,7 +766,7 @@ export class TypeTable {
748
766
  }
749
767
 
750
768
  /// The canvas text-input event vocabulary — a union carrying exactly these
751
- /// eleven tags is the declared mirror the markup engines resolve `on-input`
769
+ /// thirteen tags is the declared mirror the markup engines resolve `on-input`
752
770
  /// through (matched structurally on the Zig side; see
753
771
  /// ui_markup_reflect.declaredTextInputUnion).
754
772
  const textInputMirrorTags = [
@@ -757,6 +775,8 @@ const textInputMirrorTags = [
757
775
  "delete_forward",
758
776
  "delete_word_backward",
759
777
  "delete_word_forward",
778
+ "delete_to_start",
779
+ "delete_to_line_start",
760
780
  "clear",
761
781
  "move_caret",
762
782
  "set_selection",
@@ -117,9 +117,10 @@ Semantics:
117
117
  10. Use `native automate widget-key <view-label> <key> [text]` for focused retained widget keyboard input. The key accepts modifier chords — `cmd+a`, `cmd+c`, `cmd+v`, `cmd+x`, `ctrl+shift+arrowleft` (`cmd` sets the primary shortcut modifier on every platform) — so select-all/copy/cut/paste and shift-extended selection are drivable; after a copy, widget lines in the snapshot show the live selection as `selection=a..b`, and the copied text lands on the real system clipboard (`pbpaste` on macOS).
118
118
  11. Use `native automate widget-pinch <view-label> <scale> [x y]` for trackpad pinch gestures against a gpu-surface view: the runtime dispatches the real `pinch_begin`/`pinch_change`/`pinch_end` platform events, with one change carrying `scale - 1`. `<scale>` is the FINAL multiplicative zoom for the gesture — the cumulative gesture scale (the product of `1 + delta`) lands exactly on it — `1.5` zooms in 50%, `0.5` zooms out to half. The optional anchor point is view-local points, defaulting to the view center. Apps hear it through the pinch channel (`Options.on_pinch` / the TS core's `pinchMsg`).
119
119
  12. Use `native automate screenshot <view-label> [scale]` to capture the named `gpu_surface` view's canvas as `screenshot-<view-label>.png` (the CLI prints the artifact path and waits for the file).
120
- 13. Use `native automate tray-action <item-id>` for the primary status item, or `native automate tray-action <status-item-id> <item-id>` for an explicit item. Both select a dropdown row through the same platform event a real menu-bar click emits (command dispatch with source `.tray`). Live items appear in `snapshot.txt` as `tray #status-id title="..." visible=... items=N` followed by ` tray-item #item-id ...` rows — the menu bar is outside every window capture, so this is the automation evidence for every model-driven item. Unknown id pairs degrade into the dispatch-error ring as `automation.tray_action`.
121
- 14. Use `native automate reload` to request a WebView reload.
122
- 15. Use `native automate profile on` to enable per-stage frame timing: while on, `snapshot.txt` carries a `frame_profile` line with rolling p50/p90/max microseconds per pipeline stage (`rebuild`, `layout`, `reconcile`, `emit`, `a11y`, `plan`, `patch`, `encode`, `present`, `host_decode`, `host_draw`), each with a lifetime sample count (`<stage>_n=`). Drive some interactions, then `native automate snapshot | grep -o 'frame_profile.*'` to read where frame time goes; `profile off` stops recording and drops the line. Turning it on starts a fresh sample window.
120
+ 13. Before driving an app-menu command, inspect the snapshot's `command id="..."` catalog and `app-menu` / `app-menu-item` rows to prove the running app loaded the expected `app.zon` or runner declarations. Then use `native automate menu-command <id>` to dispatch the same `.menu_command` platform event a real selection emits; the verb remains a raw event injector, so the snapshot receipt is what validates registration.
121
+ 14. Use `native automate tray-action <item-id>` for the primary status item, or `native automate tray-action <status-item-id> <item-id>` for an explicit item. Both select a dropdown row through the same platform event a real menu-bar click emits (command dispatch with source `.tray`). Live items appear in `snapshot.txt` as `tray #status-id title="..." visible=... items=N` followed by ` tray-item #item-id ...` rows — the menu bar is outside every window capture, so this is the automation evidence for every model-driven item. Unknown id pairs degrade into the dispatch-error ring as `automation.tray_action`.
122
+ 15. Use `native automate reload` to request a WebView reload.
123
+ 16. Use `native automate profile on` to enable per-stage frame timing: while on, `snapshot.txt` carries a `frame_profile` line with rolling p50/p90/max microseconds per pipeline stage (`rebuild`, `layout`, `reconcile`, `emit`, `a11y`, `plan`, `patch`, `encode`, `present`, `host_decode`, `host_draw`), each with a lifetime sample count (`<stage>_n=`). Drive some interactions, then `native automate snapshot | grep -o 'frame_profile.*'` to read where frame time goes; `profile off` stops recording and drops the line. Turning it on starts a fresh sample window.
123
124
 
124
125
  ## Screenshots
125
126