@native-sdk/cli 0.9.3 → 0.9.4

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.
@@ -878,7 +878,7 @@ The `.wake` platform event is how live platforms marshal worker completions onto
878
878
 
879
879
  ## Secondary windows
880
880
 
881
- In the default TypeScript path, export `windows(model): readonly WindowDescriptor[]` and put each possible window's Native markup at `src/windows/<label>.native`. Spell each constructor identity as a literal `label: asciiBytes("<label>")`; `native check` and every build reject dynamic labels and missing roots. Those roots may import shared components nested under `src/windows/`; the generated launcher compiles and hot-reloads the full closure. Use `windowDescriptor` from `@native-sdk/core`; its `closePolicy` field accepts `"quit"` or `"hide"`, and `titlebar` includes `"chromeless"`. A `"quit"` user close routes `onCloseCommand` through `commandMsg`; a `"hide"` close preserves the window and view and dispatches no close command. The `ts-core` skill has the complete descriptor and example.
881
+ In the default TypeScript path, export `windows(model): readonly WindowDescriptor[]` and put each possible window's Native markup at `src/windows/<label>.native`. Spell each constructor identity as a literal `label: asciiBytes("<label>")`; `native check` and every build reject dynamic labels and missing roots. Those roots may import shared components nested under `src/windows/`; the generated launcher compiles and hot-reloads the full closure. Use `windowDescriptor` from `@native-sdk/core`; its `restorePolicy` field accepts `"clamp_to_visible_screen"` or `"center_on_primary"` (centering is currently macOS-only), `closePolicy` accepts `"quit"` or `"hide"`, and `titlebar` includes `"chromeless"`. A `"quit"` user close routes `onCloseCommand` through `commandMsg`; a `"hide"` close preserves the window and view and dispatches no close command. The `ts-core` skill has the complete descriptor and example.
882
882
 
883
883
  ### Zig cores: `windows_fn` + `window_view`
884
884
 
@@ -905,6 +905,7 @@ fn windowView(ui: *App.Ui, model: *const Model, window_label: []const u8) App.Ui
905
905
  Rules that matter:
906
906
  - **Every canvas label must be unique across the app** (main + declared windows); input routes back by it, and automation verbs (`widget-click <canvas-label> <id>`, `screenshot`) address any window's canvas the same way.
907
907
  - **Close policy**: `WindowDescriptor.close_policy` is `.quit` by default; a user close really closes and dispatches `on_close` (the dismissal precedent), so clear the open flag in `update` — or keep declaring the window and the next rebuild brings it back (source wins). `.hide` keeps the same window, slot, and views alive, dispatches no `on_close`, and `showWindow(label)` reveals it. A close the model itself initiated never echoes a Msg. Existing platform safeguards still apply: unsupported hosts refuse `.hide` rather than strand an unreachable window.
908
+ - **Restore policy**: `WindowDescriptor.restore_policy` is `.clamp_to_visible_screen` by default. On macOS, `.center_on_primary` centers a fresh descriptor with no authored `x`/`y`; Windows and Linux currently keep their native default placement. Model-declared windows deliberately do not restore persisted frames.
908
909
  - **Budget**: at most `UiApp.max_ui_windows` (4) declared windows; excess warns and is ignored. Every dispatched Msg rebuilds every open window's view.
909
910
  - **Present-before-show**: canvas windows (any `gpu_surface` view — startup, scene, and declared windows alike) are created ordered-out and become visible only after their first canvas frame presents, so opening one never flashes blank. Automatic (`WindowOptions.show = .on_first_present`, derived from the views); webview windows show immediately. The null platform records `window_show`, `window_visible`, and present/shown sequence numbers for ordering assertions; `NATIVE_SDK_WINDOW_TIMING=1` logs create→show latency on macOS.
910
911
  - **Markup binds ONE window's content** — there is no `window` element in the closed grammar. A markup-authored secondary window is a `canvas.CompiledMarkupView` whose `build` `window_view` calls for that label.
@@ -231,6 +231,7 @@ export function windows(model: Model): readonly WindowDescriptor[] {
231
231
  title: asciiBytes("Settings"),
232
232
  width: 420,
233
233
  height: 240,
234
+ restorePolicy: "center_on_primary",
234
235
  resizable: false,
235
236
  closePolicy: "quit",
236
237
  onCloseCommand: asciiBytes("app.settings-closed"),
@@ -240,6 +241,8 @@ export function windows(model: Model): readonly WindowDescriptor[] {
240
241
 
241
242
  `closePolicy` is `"quit"` by default. Under `"quit"`, a user close really closes the window and routes `onCloseCommand` through `commandMsg`; map it to the Msg that clears the model's open flag. If the model keeps declaring the label, source wins and the next reconciliation recreates it. Under `"hide"`, the same native window and view stay alive, no close command fires, and `Cmd.showWindow("settings")` reveals it. Stopping the declaration always performs a real reconcile close. The platform safeguards for `hide` are the same as manifest windows. Model-declared secondary windows are desktop-only.
242
243
 
244
+ `restorePolicy` accepts `"clamp_to_visible_screen"` (the default) or `"center_on_primary"`. Model-declared windows do not restore persisted frames. On macOS, the latter centers a fresh descriptor with no `x`/`y` directly at native creation time; Windows and Linux currently keep their native default placement.
245
+
243
246
  `titlebar` accepts `"standard"`, `"hidden_inset"`, `"hidden_inset_tall"`, and `"chromeless"`. The last removes all OS chrome and is required when a transparent model-declared window targets Windows; provide working app-drawn close/minimize controls for that fully skinned shape.
244
247
 
245
248
  ### The init command
@@ -6,7 +6,7 @@
6
6
  Verify without writing:
7
7
  node packages/core/scripts/gen_service_surface.mjs --check -->
8
8
 
9
- # Service compile surface — scriptc 0.0.31
9
+ # Service compile surface — scriptc 0.0.33
10
10
 
11
11
  What TypeScript under `src/services/` can use, as stated by the pinned
12
12
  compiler itself (surface manifest schema 1, 527 entries:
@@ -1,7 +1,8 @@
1
1
  //! The generated wiring for a TypeScript app core — staged (never written
2
2
  //! into the app) by the framework build when the tree carries src/core.ts:
3
- //! the build transpiles the core beside this file as core.zig, copies the
4
- //! app's src/app.native beside it too, and roots the app module here. The
3
+ //! the build transpiles the core beside this file as core.zig, links the
4
+ //! app's src/app.native as an isolated data object, and roots the app module
5
+ //! here. The
5
6
  //! app tree stays three files of truth — core.ts (logic), app.native
6
7
  //! (view), app.zon (manifest) — and every value below derives from them at
7
8
  //! comptime:
@@ -79,7 +80,14 @@ const App = Adapter.App;
79
80
 
80
81
  const shell_scene = native_sdk.app_manifest.shellConfigFrom(manifest);
81
82
  const canvas_label = native_sdk.app_manifest.firstGpuSurfaceLabel(shell_scene);
82
- pub const app_markup = @embedFile("app.native");
83
+ extern const native_sdk_app_markup: u8;
84
+ extern const native_sdk_app_markup_len: usize;
85
+
86
+ /// Primary markup is linked as a data object so changing it does not dirty
87
+ /// this Zig module's already-compiled SDK/app graph.
88
+ pub fn appMarkup() []const u8 {
89
+ return @as([*]const u8, @ptrCast(&native_sdk_app_markup))[0..native_sdk_app_markup_len];
90
+ }
83
91
 
84
92
  const app_permissions = manifestStringList(manifest, "permissions");
85
93
  const allowed_origins = manifestAllowedOrigins();
@@ -90,7 +98,7 @@ pub fn main(init: std.process.Init) !void {
90
98
  .name = manifest.name,
91
99
  .scene = shell_scene,
92
100
  .canvas_label = canvas_label,
93
- .markup = .{ .source = app_markup, .watch_path = "src/app.native", .io = init.io },
101
+ .markup = .{ .source = appMarkup(), .watch_path = "src/app.native", .io = init.io },
94
102
  // app.zon's theme pack; unthemed manifests get the house register.
95
103
  // The stock tokens compose the pack with the LIVE system
96
104
  // appearance, so TS apps follow the OS light/dark flip with no
@@ -46,7 +46,11 @@ const Adapter = native_sdk.TsUiApp(core);
46
46
  pub const Model = core.Model;
47
47
  pub const Msg = core.Msg;
48
48
 
49
- pub const app_markup = @embedFile("app.native");
49
+ extern const native_sdk_app_markup: u8;
50
+ extern const native_sdk_app_markup_len: usize;
51
+ pub fn appMarkup() []const u8 {
52
+ return @as([*]const u8, @ptrCast(&native_sdk_app_markup))[0..native_sdk_app_markup_len];
53
+ }
50
54
 
51
55
  comptime {
52
56
  // The build graph resolves the carrier before staging this file; a
@@ -97,7 +101,7 @@ pub fn mobileOptions() Adapter.Options {
97
101
  .name = manifest.name,
98
102
  .scene = mobile_scene,
99
103
  .canvas_label = native_sdk.embed.mobile_gpu_surface_label,
100
- .markup = .{ .source = app_markup },
104
+ .markup = .{ .source = appMarkup() },
101
105
  // app.zon's theme pack and one-accent override, same as desktop.
102
106
  .theme = comptime manifestThemePack(),
103
107
  .theme_accent = comptime manifestThemeAccent(),
@@ -720,6 +720,7 @@ pub fn TsUiApp(comptime core: type) type {
720
720
  .x = optionalWindowFloat(window.x),
721
721
  .y = optionalWindowFloat(window.y),
722
722
  .resizable = window.resizable,
723
+ .restore_policy = windowRestorePolicy(window.restorePolicy),
723
724
  .min_width = statusItemFloat(window.minWidth),
724
725
  .min_height = statusItemFloat(window.minHeight),
725
726
  .titlebar = windowTitlebar(window.titlebar),
@@ -752,6 +753,14 @@ pub fn TsUiApp(comptime core: type) type {
752
753
  unreachable;
753
754
  }
754
755
 
756
+ fn windowRestorePolicy(value: anytype) @import("app_manifest").WindowRestorePolicy {
757
+ const Target = @import("app_manifest").WindowRestorePolicy;
758
+ inline for (std.meta.fields(Target)) |field| {
759
+ if (std.mem.eql(u8, @tagName(value), field.name)) return @enumFromInt(field.value);
760
+ }
761
+ unreachable;
762
+ }
763
+
755
764
  fn windowClosePolicy(value: anytype) @import("app_manifest").WindowClosePolicy {
756
765
  const Target = @import("app_manifest").WindowClosePolicy;
757
766
  inline for (std.meta.fields(Target)) |field| {
@@ -1018,9 +1027,10 @@ pub fn TsUiApp(comptime core: type) type {
1018
1027
  if (return_info != .pointer or return_info.pointer.size != .slice or !return_info.pointer.is_const) @compileError(teaching);
1019
1028
  const Window = statusItemRecordType(return_info.pointer.child, teaching);
1020
1029
  const info = @typeInfo(Window).@"struct";
1021
- if (info.fields.len != 18 or !@hasField(Window, "label") or !@hasField(Window, "canvasLabel") or
1030
+ if (info.fields.len != 19 or !@hasField(Window, "label") or !@hasField(Window, "canvasLabel") or
1022
1031
  !@hasField(Window, "title") or !@hasField(Window, "width") or !@hasField(Window, "height") or
1023
1032
  !@hasField(Window, "x") or !@hasField(Window, "y") or !@hasField(Window, "resizable") or
1033
+ !@hasField(Window, "restorePolicy") or
1024
1034
  !@hasField(Window, "minWidth") or !@hasField(Window, "minHeight") or !@hasField(Window, "titlebar") or
1025
1035
  !@hasField(Window, "transparent") or !@hasField(Window, "alwaysOnTop") or !@hasField(Window, "clickThrough") or
1026
1036
  !@hasField(Window, "activateOnShow") or !@hasField(Window, "allowsFullscreen") or
@@ -1029,6 +1039,7 @@ pub fn TsUiApp(comptime core: type) type {
1029
1039
  @FieldType(Window, "title") != []const u8 or !statusItemNumericType(@FieldType(Window, "width")) or
1030
1040
  !statusItemNumericType(@FieldType(Window, "height")) or !optionalNumericType(@FieldType(Window, "x")) or
1031
1041
  !optionalNumericType(@FieldType(Window, "y")) or @FieldType(Window, "resizable") != bool or
1042
+ !statusItemEnumType(@FieldType(Window, "restorePolicy"), &.{ "clamp_to_visible_screen", "center_on_primary" }) or
1032
1043
  !statusItemNumericType(@FieldType(Window, "minWidth")) or !statusItemNumericType(@FieldType(Window, "minHeight")) or
1033
1044
  !statusItemEnumType(@FieldType(Window, "titlebar"), &.{ "standard", "hidden_inset", "hidden_inset_tall", "chromeless" }) or
1034
1045
  @FieldType(Window, "transparent") != bool or @FieldType(Window, "alwaysOnTop") != bool or
@@ -1637,6 +1648,7 @@ test "TypeScript statusItems adapter validates and projects canonical descriptor
1637
1648
 
1638
1649
  const WindowsAdapterTestCore = struct {
1639
1650
  const Titlebar = enum { standard, hidden_inset, hidden_inset_tall, chromeless };
1651
+ const RestorePolicy = enum { clamp_to_visible_screen, center_on_primary };
1640
1652
  const ClosePolicy = enum { quit, hide };
1641
1653
  const Descriptor = struct {
1642
1654
  label: []const u8,
@@ -1647,6 +1659,7 @@ const WindowsAdapterTestCore = struct {
1647
1659
  x: ?f64,
1648
1660
  y: ?f64,
1649
1661
  resizable: bool,
1662
+ restorePolicy: RestorePolicy,
1650
1663
  minWidth: f64,
1651
1664
  minHeight: f64,
1652
1665
  titlebar: Titlebar,
@@ -1660,11 +1673,11 @@ const WindowsAdapterTestCore = struct {
1660
1673
  };
1661
1674
 
1662
1675
  const descriptors = [_]Descriptor{
1663
- .{ .label = "one", .canvasLabel = "one-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .chromeless, .transparent = true, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
1664
- .{ .label = "two", .canvasLabel = "two-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
1665
- .{ .label = "three", .canvasLabel = "three-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
1666
- .{ .label = "four", .canvasLabel = "four-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
1667
- .{ .label = "excess", .canvasLabel = "excess-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
1676
+ .{ .label = "one", .canvasLabel = "one-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .restorePolicy = .center_on_primary, .minWidth = 0, .minHeight = 0, .titlebar = .chromeless, .transparent = true, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
1677
+ .{ .label = "two", .canvasLabel = "two-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .restorePolicy = .clamp_to_visible_screen, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
1678
+ .{ .label = "three", .canvasLabel = "three-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .restorePolicy = .clamp_to_visible_screen, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
1679
+ .{ .label = "four", .canvasLabel = "four-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .restorePolicy = .clamp_to_visible_screen, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
1680
+ .{ .label = "excess", .canvasLabel = "excess-canvas", .title = "", .width = 100, .height = 100, .x = null, .y = null, .resizable = true, .restorePolicy = .clamp_to_visible_screen, .minWidth = 0, .minHeight = 0, .titlebar = .standard, .transparent = false, .alwaysOnTop = false, .clickThrough = false, .activateOnShow = true, .allowsFullscreen = true, .closePolicy = .quit, .onCloseCommand = "" },
1668
1681
  };
1669
1682
 
1670
1683
  pub const Msg = union(enum) { noop };
@@ -1723,6 +1736,7 @@ test "TypeScript windows adapter keeps the declared prefix on overflow and proje
1723
1736
  try std.testing.expectEqual(Adapter.App.max_ui_windows, descriptors.len);
1724
1737
  try std.testing.expectEqualStrings("one", descriptors[0].label);
1725
1738
  try std.testing.expectEqual(@import("app_manifest").WindowTitlebarStyle.chromeless, descriptors[0].titlebar);
1739
+ try std.testing.expectEqual(@import("app_manifest").WindowRestorePolicy.center_on_primary, descriptors[0].restore_policy);
1726
1740
  try std.testing.expect(descriptors[0].transparent);
1727
1741
  try std.testing.expectEqualStrings("four", descriptors[3].label);
1728
1742
  }
@@ -370,6 +370,12 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
370
370
  x: ?f32 = null,
371
371
  y: ?f32 = null,
372
372
  resizable: bool = true,
373
+ /// Placement policy passed to the host when creating this
374
+ /// fresh, non-restored window. On macOS,
375
+ /// `.center_on_primary` centers a descriptor without an authored
376
+ /// origin on the primary screen; other hosts currently retain
377
+ /// their native default placement.
378
+ restore_policy: app_manifest.WindowRestorePolicy = .clamp_to_visible_screen,
373
379
  /// Content min-size floor the WINDOW enforces (macOS
374
380
  /// `contentMinSize`): the user's resize stops at the floor
375
381
  /// instead of the layout clamping/clipping panes below
@@ -2880,6 +2886,7 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
2880
2886
  .x = descriptor.x,
2881
2887
  .y = descriptor.y,
2882
2888
  .resizable = descriptor.resizable,
2889
+ .restore_policy = descriptor.restore_policy,
2883
2890
  .titlebar = descriptor.titlebar,
2884
2891
  .transparent = descriptor.transparent,
2885
2892
  .always_on_top = descriptor.always_on_top,
@@ -21,6 +21,7 @@ const settings_window_label = "settings";
21
21
  const PanelModel = struct {
22
22
  settings_open: bool = false,
23
23
  position_settings: bool = true,
24
+ center_settings: bool = false,
24
25
  transparent_settings: bool = false,
25
26
  bumps: u32 = 0,
26
27
  user_closes: u32 = 0,
@@ -63,6 +64,7 @@ fn panelWindows(model: *const PanelModel, scratch: *PanelApp.WindowsScratch) []c
63
64
  .height = 240,
64
65
  .x = if (model.position_settings) 84 else null,
65
66
  .y = if (model.position_settings) 126 else null,
67
+ .restore_policy = if (model.center_settings) .center_on_primary else .clamp_to_visible_screen,
66
68
  .min_width = 280,
67
69
  .min_height = 200,
68
70
  .titlebar = if (model.transparent_settings) .chromeless else .standard,
@@ -245,6 +247,27 @@ test "a Msg declares the settings window, its canvas installs, and automation dr
245
247
  }
246
248
  }
247
249
 
250
+ test "a windows_fn restore policy reaches fresh WindowOptions" {
251
+ const fixture = try Fixture.create();
252
+ defer fixture.destroy();
253
+
254
+ fixture.app_state.model.position_settings = false;
255
+ fixture.app_state.model.center_settings = true;
256
+ try fixture.clickSettingsButton();
257
+ const info = fixture.settingsWindowInfo() orelse return error.TestUnexpectedResult;
258
+
259
+ for (fixture.harness.null_platform.windows[0..fixture.harness.null_platform.window_count], 0..) |window, index| {
260
+ if (window.id != info.id) continue;
261
+ // Model-declared windows deliberately set restore_state=false. With
262
+ // no authored origin this remains a fresh/default placement while
263
+ // preserving the descriptor's policy at WindowOptions.
264
+ try std.testing.expectEqual(support.platform.WindowInitialPlacement.default, fixture.harness.null_platform.window_placement[index]);
265
+ try std.testing.expectEqual(support.platform.WindowRestorePolicy.center_on_primary, fixture.harness.null_platform.window_restore_policy[index]);
266
+ return;
267
+ }
268
+ return error.WindowNotFound;
269
+ }
270
+
248
271
  test "a transparent descriptor selects premultiplied canvas alpha and an alpha-zero clear" {
249
272
  const fixture = try Fixture.create();
250
273
  defer fixture.destroy();
@@ -503,7 +503,7 @@ fn tsSlimReadme(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
503
503
  \\
504
504
  \\## Requirements
505
505
  \\
506
- \\Node.js 22.15+ (on the 23 line: 23.5+) on PATH (the TypeScript frontend
506
+ \\Node.js 24+ on PATH (the TypeScript frontend
507
507
  \\and the core compiler run at build time; your shipped binary carries
508
508
  \\none of it).
509
509
  \\
@@ -1158,7 +1158,7 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
1158
1158
  const node_setup =
1159
1159
  \\ - uses: actions/setup-node@v4
1160
1160
  \\ with:
1161
- \\ node-version: 22
1161
+ \\ node-version: 24
1162
1162
  \\
1163
1163
  ;
1164
1164
  const compiler_install =
@@ -4531,6 +4531,10 @@ test "writeDefaultApp --full ts-core emits a CI workflow with the node tier" {
4531
4531
  // frontend + compiler install inside the fetched SDK's packages/core,
4532
4532
  // in BOTH jobs (each builds the app, so each compiles the core).
4533
4533
  try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "actions/setup-node@v4") != null);
4534
+ const node_24 = "node-version: 24";
4535
+ const first_node = std.mem.indexOf(u8, ci_yaml_text, node_24).?;
4536
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text[first_node + node_24.len ..], node_24) != null);
4537
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "node-version: 22") == null);
4534
4538
  const npm_ci = "npm ci --prefix \"$NATIVE_SDK_PATH/packages/core\"";
4535
4539
  const first = std.mem.indexOf(u8, ci_yaml_text, npm_ci).?;
4536
4540
  try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text[first + npm_ci.len ..], npm_ci) != null);
@@ -74,7 +74,7 @@ fn nodeMissing() Error {
74
74
  std.debug.print(
75
75
  \\TypeScript app cores need node on PATH (the @native-sdk/core frontend and the
76
76
  \\core dev-harness run under it; the binary you ship carries no JS runtime).
77
- \\Install Node.js 22.15+ (on the 23 line: 23.5+) - https://nodejs.org or
77
+ \\Install Node.js 24+ - https://nodejs.org or
78
78
  \\`brew install node` - and re-run.
79
79
  \\
80
80
  , .{});
@@ -38,6 +38,8 @@ pub const Options = struct {
38
38
  url_override: ?[]const u8 = null,
39
39
  command_override: ?[]const []const u8 = null,
40
40
  timeout_ms: ?u32 = null,
41
+ /// Explain authored-input changes and the content-gated downstream graph.
42
+ explain_rebuild: bool = false,
41
43
  };
42
44
 
43
45
  pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Options) !void {
@@ -50,6 +52,11 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
50
52
  return error.MissingManifest;
51
53
  }
52
54
  const metadata = try manifest_tool.readMetadata(allocator, io, "app.zon");
55
+ const rebuild_snapshot = if (options.explain_rebuild)
56
+ try explainRebuild(allocator, io)
57
+ else
58
+ null;
59
+ defer if (rebuild_snapshot) |snapshot| allocator.free(snapshot);
53
60
 
54
61
  // Tree detection happens here too (the build graph re-derives it), so
55
62
  // a both-cores tree fails with one clean teaching message before any
@@ -122,6 +129,12 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
122
129
  switch (verb) {
123
130
  .dev => {
124
131
  if (!wants_frontend_dev) try argv.append(allocator, "run");
132
+ // Zig's full summary reports each named build step's duration,
133
+ // cache status, and peak RSS. Native's generated graph names the
134
+ // frontend, corewire, staging, scriptc, and final Zig phases, so
135
+ // slow iterative builds are attributable without reproducing
136
+ // them under an external profiler.
137
+ try argv.appendSlice(allocator, &.{ "--summary", "all" });
125
138
  if (!hasOptimizeFlag(options.forwarded_args)) {
126
139
  // The dev loop is a Debug loop: the markup hot-reload
127
140
  // watcher and the teaching diagnostics are compiled in only
@@ -133,6 +146,8 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
133
146
  }
134
147
  },
135
148
  .build => {
149
+ try argv.appendSlice(allocator, &.{ "--summary", "all" });
150
+ if (options.explain_rebuild) try argv.append(allocator, "-Dbuild-trace=true");
136
151
  if (!hasOptimizeFlag(options.forwarded_args)) {
137
152
  // Both build shapes register -Doptimize (addApp and the
138
153
  // expanded template each b.option it by hand).
@@ -157,6 +172,7 @@ pub fn run(allocator: std.mem.Allocator, io: std.Io, verb: Verb, options: Option
157
172
  }
158
173
 
159
174
  try runZig(io, verb, argv.items);
175
+ if (rebuild_snapshot) |snapshot| try persistRebuildSnapshot(io, snapshot);
160
176
 
161
177
  if (wants_frontend_dev) {
162
178
  // WebView apps with a dev server config: the binary is built, now
@@ -219,6 +235,168 @@ fn hasOptimizeFlag(args: []const []const u8) bool {
219
235
  return false;
220
236
  }
221
237
 
238
+ const rebuild_snapshot_path = ".native/cache/rebuild-inputs.tsv";
239
+
240
+ const RebuildInput = struct {
241
+ path: []const u8,
242
+ hash: [std.crypto.hash.sha2.Sha256.digest_length * 2]u8,
243
+ };
244
+
245
+ fn appendRebuildInput(allocator: std.mem.Allocator, io: std.Io, inputs: *std.ArrayList(RebuildInput), path: []const u8) !void {
246
+ const owned_path = try allocator.dupe(u8, path);
247
+ errdefer allocator.free(owned_path);
248
+ var file = try std.Io.Dir.cwd().openFile(io, path, .{});
249
+ defer file.close(io);
250
+ var read_buffer: [64 * 1024]u8 = undefined;
251
+ var reader = file.reader(io, &read_buffer);
252
+ var hasher = std.crypto.hash.sha2.Sha256.init(.{});
253
+ var chunk: [64 * 1024]u8 = undefined;
254
+ while (true) {
255
+ const len = try reader.interface.readSliceShort(&chunk);
256
+ hasher.update(chunk[0..len]);
257
+ if (len < chunk.len) break;
258
+ }
259
+ const digest = hasher.finalResult();
260
+ try inputs.append(allocator, .{ .path = owned_path, .hash = std.fmt.bytesToHex(digest, .lower) });
261
+ }
262
+
263
+ fn rebuildPathIgnored(path: []const u8) bool {
264
+ var components = std.mem.splitScalar(u8, path, '/');
265
+ while (components.next()) |component| {
266
+ if (std.mem.eql(u8, component, ".git") or
267
+ std.mem.eql(u8, component, ".native") or
268
+ std.mem.eql(u8, component, ".zig-cache") or
269
+ std.mem.eql(u8, component, "zig-out") or
270
+ std.mem.eql(u8, component, "node_modules")) return true;
271
+ }
272
+ return false;
273
+ }
274
+
275
+ fn rebuildInputs(allocator: std.mem.Allocator, io: std.Io) ![]RebuildInput {
276
+ var inputs: std.ArrayList(RebuildInput) = .empty;
277
+ errdefer {
278
+ for (inputs.items) |input| allocator.free(input.path);
279
+ inputs.deinit(allocator);
280
+ }
281
+ // Ejected builds can consume any authored file, and even the standard
282
+ // graph has non-extension inputs: Zig sources, migration lock JSON,
283
+ // vendored service packages, assets, and frontend configuration. Hash the
284
+ // app tree instead of maintaining an inevitably incomplete suffix list;
285
+ // exclude only directories owned by VCS, dependency installs, and build
286
+ // outputs (including this snapshot itself under .native/).
287
+ var root = try std.Io.Dir.cwd().openDir(io, ".", .{ .iterate = true });
288
+ defer root.close(io);
289
+ var walker = try root.walkSelectively(allocator);
290
+ defer walker.deinit();
291
+ while (try walker.next(io)) |entry| {
292
+ const path = try allocator.dupe(u8, entry.path);
293
+ defer allocator.free(path);
294
+ for (path) |*char| if (char.* == '\\') {
295
+ char.* = '/';
296
+ };
297
+ if (entry.kind == .directory) {
298
+ if (!rebuildPathIgnored(path)) try walker.enter(io, entry);
299
+ continue;
300
+ }
301
+ if (entry.kind != .file) continue;
302
+ if (rebuildPathIgnored(path)) continue;
303
+ try appendRebuildInput(allocator, io, &inputs, path);
304
+ }
305
+ std.mem.sort(RebuildInput, inputs.items, {}, struct {
306
+ fn less(_: void, a: RebuildInput, b: RebuildInput) bool {
307
+ return std.mem.order(u8, a.path, b.path) == .lt;
308
+ }
309
+ }.less);
310
+ return inputs.toOwnedSlice(allocator);
311
+ }
312
+
313
+ fn explainRebuild(allocator: std.mem.Allocator, io: std.Io) ![]u8 {
314
+ const inputs = try rebuildInputs(allocator, io);
315
+ defer {
316
+ for (inputs) |input| allocator.free(input.path);
317
+ allocator.free(inputs);
318
+ }
319
+ const prior = std.Io.Dir.cwd().readFileAlloc(io, rebuild_snapshot_path, allocator, .limited(16 * 1024 * 1024)) catch null;
320
+ defer if (prior) |bytes| allocator.free(bytes);
321
+
322
+ var snapshot = std.Io.Writer.Allocating.init(allocator);
323
+ errdefer snapshot.deinit();
324
+ var changed: usize = 0;
325
+ for (inputs) |input| {
326
+ try snapshot.writer.print("{s}\t{s}\n", .{ &input.hash, input.path });
327
+ const old_hash: ?[]const u8 = if (prior) |bytes| old: {
328
+ var lines = std.mem.splitScalar(u8, bytes, '\n');
329
+ while (lines.next()) |line| {
330
+ const tab = std.mem.indexOfScalar(u8, line, '\t') orelse continue;
331
+ if (std.mem.eql(u8, line[tab + 1 ..], input.path)) break :old line[0..tab];
332
+ }
333
+ break :old null;
334
+ } else null;
335
+ if (old_hash != null and std.mem.eql(u8, old_hash.?, &input.hash)) continue;
336
+ changed += 1;
337
+ std.debug.print("native rebuild: {s} {s} -> {s}\n", .{ input.path, old_hash orelse "<new>", &input.hash });
338
+ if (std.mem.eql(u8, input.path, "app.zon")) {
339
+ std.debug.print(" invalidates manifest-derived configuration -> affected contracts, app-code/platform link, and final artifact\n", .{});
340
+ } else if (std.mem.eql(u8, input.path, "build.zig") or std.mem.eql(u8, input.path, "build.zig.zon")) {
341
+ std.debug.print(" invalidates the owned build graph -> graph-selected compilation and final artifact\n", .{});
342
+ } else if (std.mem.eql(u8, input.path, "src/app.native")) {
343
+ std.debug.print(" invalidates markup data object -> final app link; app-code/core scriptc remain content-gated\n", .{});
344
+ } else if (std.mem.endsWith(u8, input.path, ".native")) {
345
+ std.debug.print(" invalidates staged markup source set -> app-code object -> final link; core scriptc remains content-gated\n", .{});
346
+ } else if (std.mem.startsWith(u8, input.path, "src/services/")) {
347
+ std.debug.print(" invalidates TS frontend -> service contract/source hash -> service host compile; API client/registry/core scriptc change only if API shape changes\n", .{});
348
+ } else if (std.mem.endsWith(u8, input.path, ".ts")) {
349
+ std.debug.print(" invalidates TS frontend -> core contract/facade/stage -> core scriptc -> app-code object -> final link\n", .{});
350
+ } else if (std.mem.endsWith(u8, input.path, ".zig")) {
351
+ std.debug.print(" invalidates Zig build/app code -> affected compile and final link\n", .{});
352
+ } else if (std.mem.endsWith(u8, input.path, ".sql") or std.mem.endsWith(u8, input.path, "/migrations.lock.json")) {
353
+ std.debug.print(" invalidates SQLite schema/migration generation -> app-code object -> final link\n", .{});
354
+ } else if (std.mem.startsWith(u8, input.path, "frontend/")) {
355
+ std.debug.print(" invalidates frontend build inputs -> bundled web assets and final package\n", .{});
356
+ } else if (std.mem.startsWith(u8, input.path, "assets/")) {
357
+ std.debug.print(" invalidates authored assets -> affected runtime/package artifact\n", .{});
358
+ } else {
359
+ std.debug.print(" changes an authored app input -> the build graph determines affected downstream steps\n", .{});
360
+ }
361
+ }
362
+ if (prior) |bytes| {
363
+ var lines = std.mem.splitScalar(u8, bytes, '\n');
364
+ while (lines.next()) |line| {
365
+ const tab = std.mem.indexOfScalar(u8, line, '\t') orelse continue;
366
+ const old_hash = line[0..tab];
367
+ const old_path = line[tab + 1 ..];
368
+ const present = for (inputs) |input| {
369
+ if (std.mem.eql(u8, input.path, old_path)) break true;
370
+ } else false;
371
+ if (present) continue;
372
+ changed += 1;
373
+ std.debug.print("native rebuild: {s} {s} -> <deleted>\n", .{ old_path, old_hash });
374
+ if (std.mem.startsWith(u8, old_path, "src/services/")) {
375
+ std.debug.print(" invalidates TS frontend -> service API/source set -> service host; core scriptc changes if the removed module changed API shape\n", .{});
376
+ } else if (std.mem.eql(u8, old_path, "src/app.native")) {
377
+ std.debug.print(" invalidates primary markup data object -> final app link\n", .{});
378
+ } else if (std.mem.endsWith(u8, old_path, ".native")) {
379
+ std.debug.print(" invalidates markup source set -> app-code object -> final link\n", .{});
380
+ } else if (std.mem.endsWith(u8, old_path, ".zig")) {
381
+ std.debug.print(" invalidates Zig build/app code -> affected compile and final link\n", .{});
382
+ } else {
383
+ std.debug.print(" removes an authored app input -> the build graph determines affected downstream steps\n", .{});
384
+ }
385
+ }
386
+ }
387
+ if (prior == null) std.debug.print("native rebuild: no prior successful snapshot; current inputs are the baseline\n", .{});
388
+ if (prior != null and changed == 0) std.debug.print("native rebuild: no authored input hashes changed\n", .{});
389
+ return snapshot.toOwnedSlice();
390
+ }
391
+
392
+ fn persistRebuildSnapshot(io: std.Io, snapshot: []const u8) !void {
393
+ try std.Io.Dir.cwd().createDirPath(io, ".native/cache");
394
+ var atomic = try std.Io.Dir.cwd().createFileAtomic(io, rebuild_snapshot_path, .{ .make_path = true, .replace = true });
395
+ defer atomic.deinit(io);
396
+ try atomic.file.writeStreamingAll(io, snapshot);
397
+ try atomic.replace(io);
398
+ }
399
+
222
400
  fn runZig(io: std.Io, verb: Verb, argv: []const []const u8) !void {
223
401
  // The dev verb owns a whole process TREE: `zig build run` spawns the
224
402
  // app as its child, and a `native dev` that dies (Ctrl-C, a driver
@@ -318,3 +496,52 @@ test "optimize flags are detected among forwarded args" {
318
496
  try std.testing.expect(!hasOptimizeFlag(&.{"-Dautomation=true"}));
319
497
  try std.testing.expect(!hasOptimizeFlag(&.{}));
320
498
  }
499
+
500
+ test "rebuild explanations persist manifest and source hashes" {
501
+ const allocator = std.testing.allocator;
502
+ const io = std.testing.io;
503
+ const root = ".zig-cache/test-rebuild-explain";
504
+ var cwd = std.Io.Dir.cwd();
505
+ cwd.deleteTree(io, root) catch {};
506
+ defer cwd.deleteTree(io, root) catch {};
507
+ try cwd.createDirPath(io, root ++ "/src/services");
508
+ try cwd.createDirPath(io, root ++ "/src/schema");
509
+ try cwd.createDirPath(io, root ++ "/assets");
510
+ try cwd.createDirPath(io, root ++ "/.native/cache");
511
+ try cwd.createDirPath(io, root ++ "/node_modules/package");
512
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/app.zon", .data = ".{ .name = \"rebuild-test\" }\n" });
513
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/build.zig", .data = "pub fn build() void {}\n" });
514
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/src/core.ts", .data = "export const core = 1;\n" });
515
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/src/main.zig", .data = "pub fn main() void {}\n" });
516
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/src/app.native", .data = "<column/>\n" });
517
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/src/services/work.ts", .data = "export function work(): number { return 1; }\n" });
518
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/src/schema/migrations.lock.json", .data = "{}\n" });
519
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/assets/icon.bin", .data = "authored asset\n" });
520
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/.native/cache/generated", .data = "generated\n" });
521
+ try cwd.writeFile(io, .{ .sub_path = root ++ "/node_modules/package/index.js", .data = "dependency\n" });
522
+ const original = try std.process.currentPathAlloc(io, allocator);
523
+ defer allocator.free(original);
524
+ try std.process.setCurrentPath(io, root);
525
+ defer std.process.setCurrentPath(io, original) catch {};
526
+ const first = try explainRebuild(allocator, io);
527
+ defer allocator.free(first);
528
+ try std.testing.expect(std.mem.indexOf(u8, first, "\tapp.zon\n") != null);
529
+ try std.testing.expect(std.mem.indexOf(u8, first, "\tbuild.zig\n") != null);
530
+ try std.testing.expect(std.mem.indexOf(u8, first, "\tsrc/main.zig\n") != null);
531
+ try std.testing.expect(std.mem.indexOf(u8, first, "\tsrc/schema/migrations.lock.json\n") != null);
532
+ try std.testing.expect(std.mem.indexOf(u8, first, "\tassets/icon.bin\n") != null);
533
+ try std.testing.expect(std.mem.indexOf(u8, first, "\t.native/") == null);
534
+ try std.testing.expect(std.mem.indexOf(u8, first, "\tnode_modules/") == null);
535
+ try persistRebuildSnapshot(io, first);
536
+ const second = try explainRebuild(allocator, io);
537
+ defer allocator.free(second);
538
+ try std.testing.expectEqualStrings(first, second);
539
+ try cwd.writeFile(io, .{ .sub_path = "src/services/work.ts", .data = "// comment\nexport function work(): number { return 1; }\n" });
540
+ const changed = try explainRebuild(allocator, io);
541
+ defer allocator.free(changed);
542
+ try std.testing.expect(!std.mem.eql(u8, first, changed));
543
+ try cwd.writeFile(io, .{ .sub_path = "app.zon", .data = ".{ .name = \"rebuild-test\", .capabilities = .{\"store\"} }\n" });
544
+ const manifest_changed = try explainRebuild(allocator, io);
545
+ defer allocator.free(manifest_changed);
546
+ try std.testing.expect(!std.mem.eql(u8, changed, manifest_changed));
547
+ }