@native-sdk/cli 0.4.4 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/build/app.zig +187 -6
  2. package/build/ts_run.mjs +63 -0
  3. package/build.zig +213 -1
  4. package/build.zig.zon +1 -0
  5. package/package.json +15 -10
  6. package/packages/core/package-lock.json +43 -0
  7. package/packages/core/package.json +37 -0
  8. package/packages/core/rt/rt.zig +1579 -0
  9. package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
  10. package/packages/core/sdk/core.ts +694 -0
  11. package/packages/core/sdk/events.ts +137 -0
  12. package/packages/core/sdk/text.ts +519 -0
  13. package/packages/core/src/checker.ts +1869 -0
  14. package/packages/core/src/cli.ts +68 -0
  15. package/packages/core/src/devhost.ts +291 -0
  16. package/packages/core/src/devhost_resolver.mjs +22 -0
  17. package/packages/core/src/diagnostics.ts +417 -0
  18. package/packages/core/src/emitter.ts +8815 -0
  19. package/packages/core/src/infer.ts +1515 -0
  20. package/packages/core/src/modules.ts +173 -0
  21. package/packages/core/src/ownership.ts +740 -0
  22. package/packages/core/src/text_polyfill.ts +337 -0
  23. package/packages/core/src/text_tables.ts +408 -0
  24. package/packages/core/src/transpile.ts +146 -0
  25. package/packages/core/src/typed_ast.ts +536 -0
  26. package/packages/core/src/types.ts +815 -0
  27. package/skill-data/native-ui/SKILL.md +14 -0
  28. package/skill-data/ts-core/SKILL.md +493 -0
  29. package/skill-data/zig/SKILL.md +10 -0
  30. package/src/app_runner/root.zig +24 -0
  31. package/src/app_runner/ts_core_main.zig +231 -0
  32. package/src/primitives/app_manifest/comptime_scene.zig +341 -0
  33. package/src/primitives/app_manifest/root.zig +5 -0
  34. package/src/primitives/canvas/commands.zig +14 -7
  35. package/src/primitives/canvas/lazy_tls.zig +73 -0
  36. package/src/primitives/canvas/render_generic_resources.zig +22 -15
  37. package/src/primitives/canvas/root.zig +6 -0
  38. package/src/primitives/canvas/tests.zig +1 -0
  39. package/src/primitives/canvas/text_atlas.zig +40 -32
  40. package/src/primitives/canvas/text_layout_cache.zig +29 -22
  41. package/src/primitives/canvas/text_measure_cache.zig +56 -41
  42. package/src/primitives/canvas/text_spans.zig +39 -26
  43. package/src/primitives/canvas/tokens.zig +54 -0
  44. package/src/primitives/canvas/ui.zig +125 -0
  45. package/src/primitives/canvas/ui_markup.zig +22 -3
  46. package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
  47. package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
  48. package/src/primitives/canvas/ui_markup_contract.zig +68 -14
  49. package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
  50. package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
  51. package/src/primitives/canvas/ui_markup_view.zig +105 -1
  52. package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
  53. package/src/primitives/canvas/ui_schema.zig +8 -0
  54. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  55. package/src/primitives/canvas/widget_invalidation.zig +14 -7
  56. package/src/primitives/canvas/widget_render.zig +25 -15
  57. package/src/primitives/canvas/widget_render_controls.zig +15 -9
  58. package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
  59. package/src/root.zig +7 -0
  60. package/src/runtime/canvas_frame.zig +57 -36
  61. package/src/runtime/canvas_images.zig +9 -3
  62. package/src/runtime/canvas_widget_control_tests.zig +5 -6
  63. package/src/runtime/canvas_widget_runtime.zig +7 -4
  64. package/src/runtime/effects.zig +490 -2
  65. package/src/runtime/effects_host_tests.zig +594 -0
  66. package/src/runtime/root.zig +18 -0
  67. package/src/runtime/session_replay.zig +7 -1
  68. package/src/runtime/tests.zig +2 -0
  69. package/src/runtime/ts_core_host.zig +1505 -0
  70. package/src/runtime/ts_core_host_tests.zig +1408 -0
  71. package/src/runtime/ts_ui_app.zig +469 -0
  72. package/src/runtime/ui_app.zig +58 -0
  73. package/src/runtime/view_canvas.zig +24 -17
  74. package/src/runtime/view_widget_tree.zig +2 -2
  75. package/src/tooling/codesign.zig +212 -105
  76. package/src/tooling/doctor.zig +78 -0
  77. package/src/tooling/manifest.zig +47 -0
  78. package/src/tooling/package.zig +124 -12
  79. package/src/tooling/raw_manifest.zig +15 -0
  80. package/src/tooling/root.zig +1 -0
  81. package/src/tooling/templates.zig +683 -28
  82. package/src/tooling/ts_core.zig +486 -0
  83. package/src/tooling/verbs.zig +17 -0
@@ -1,5 +1,6 @@
1
1
  const std = @import("std");
2
2
  const junction = @import("junction.zig");
3
+ const ts_core = @import("ts_core.zig");
3
4
 
4
5
  /// The SDK's default app icon, rendered from vector source by
5
6
  /// `zig build generate-icon` (tools/generate_app_icon.zig). Embedded so
@@ -64,11 +65,32 @@ pub const Shape = enum {
64
65
  full,
65
66
  };
66
67
 
68
+ /// Which core the native-frontend scaffold writes. No language flag and no
69
+ /// persistent config anywhere: the choice leaves NOTHING behind but the
70
+ /// tree itself (src/core.ts vs src/main.zig) - the build graph detects the
71
+ /// core from the tree on every build.
72
+ pub const CoreTemplate = enum {
73
+ /// TypeScript core (src/core.ts) + markup view - the default.
74
+ ts,
75
+ /// Zig core (src/main.zig) + markup view - the same starter app,
76
+ /// authored in Zig.
77
+ zig,
78
+
79
+ pub fn parse(value: []const u8) ?CoreTemplate {
80
+ if (std.mem.eql(u8, value, "ts-core")) return .ts;
81
+ if (std.mem.eql(u8, value, "zig-core")) return .zig;
82
+ return null;
83
+ }
84
+ };
85
+
67
86
  pub const InitOptions = struct {
68
87
  app_name: []const u8,
69
88
  framework_path: []const u8 = ".",
70
89
  frontend: Frontend = .vite,
71
90
  shape: Shape = .slim,
91
+ /// Applies to the native frontend only (web frontends have no core
92
+ /// tier to scaffold).
93
+ core: CoreTemplate = .ts,
72
94
  };
73
95
 
74
96
  pub fn writeDefaultApp(allocator: std.mem.Allocator, io: std.Io, destination: []const u8, options: InitOptions) !void {
@@ -86,6 +108,15 @@ pub fn writeDefaultApp(allocator: std.mem.Allocator, io: std.Io, destination: []
86
108
  try app_dir.createDirPath(io, "assets");
87
109
 
88
110
  if (options.frontend == .native) {
111
+ if (options.core == .ts) {
112
+ if (options.shape == .slim) {
113
+ return writeTsAppSlim(allocator, io, app_dir, names, destination, options.framework_path);
114
+ }
115
+ // build.zig.zon path dependencies must be relative to the app root.
116
+ const dependency_path = try nativeDependencyPath(allocator, io, destination, framework_path);
117
+ defer allocator.free(dependency_path);
118
+ return writeTsApp(allocator, io, app_dir, names, dependency_path, destination, options.framework_path);
119
+ }
89
120
  if (options.shape == .slim) {
90
121
  return writeNativeAppSlim(allocator, io, app_dir, names);
91
122
  }
@@ -151,6 +182,322 @@ fn slimGitignore() []const u8 {
151
182
  ;
152
183
  }
153
184
 
185
+ /// The TypeScript-core zero-config scaffold - the `native init` default:
186
+ /// core.ts (logic), app.native (view), app.zon (manifest). ZERO Zig in the
187
+ /// tree; the build graph detects src/core.ts, transpiles it, and stages the
188
+ /// generated wiring outside the app on every build.
189
+ ///
190
+ /// The tree also carries the EDITOR surface: package.json + tsconfig.json,
191
+ /// so stock editor TypeScript resolves `@native-sdk/core` with full
192
+ /// IntelliSense, plus a materialized node_modules copy of the SDK package
193
+ /// (ts_core.zig owns that contract). None of it is build truth — the tree
194
+ /// detection above keys on src/core.ts alone, and every `native` verb
195
+ /// works with node_modules deleted.
196
+ fn writeTsAppSlim(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir, names: TemplateNames, destination: []const u8, sdk_source: []const u8) !void {
197
+ const app_zon = try nativeAppZon(allocator, names);
198
+ defer allocator.free(app_zon);
199
+ const readme_md = try tsSlimReadme(allocator, names);
200
+ defer allocator.free(readme_md);
201
+
202
+ try writeFile(app_dir, io, "src/core.ts", tsCoreStarter());
203
+ try writeFile(app_dir, io, "src/app.native", tsAppMarkup());
204
+ try writeFile(app_dir, io, "app.zon", app_zon);
205
+ try writeFile(app_dir, io, "assets/icon.png", default_icon_png);
206
+ try writeFile(app_dir, io, ".gitignore", tsGitignore());
207
+ try writeFile(app_dir, io, "README.md", readme_md);
208
+ try writeTsEditorSurface(allocator, io, app_dir, names, destination, sdk_source);
209
+ }
210
+
211
+ /// The `--full` twin: the same TS tree plus an owned build.zig/zon pair
212
+ /// (the plain addApp call - the build graph's tree detection does the
213
+ /// rest) and a CI workflow, for users who want to own the build from day
214
+ /// one — the same full-shape contract as the Zig template.
215
+ fn writeTsApp(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir, names: TemplateNames, framework_path: []const u8, destination: []const u8, sdk_source: []const u8) !void {
216
+ const build_zig = try nativeBuildZig(allocator, names);
217
+ defer allocator.free(build_zig);
218
+ const build_zon = try nativeBuildZon(allocator, names, framework_path);
219
+ defer allocator.free(build_zon);
220
+ const app_zon = try nativeAppZon(allocator, names);
221
+ defer allocator.free(app_zon);
222
+ const readme_md = try tsSlimReadme(allocator, names);
223
+ defer allocator.free(readme_md);
224
+ const ci_yaml = try nativeCiYaml(allocator, names, framework_path, .ts);
225
+ defer allocator.free(ci_yaml);
226
+
227
+ try app_dir.createDirPath(io, ".github/workflows");
228
+ try writeFile(app_dir, io, ".github/workflows/ci.yml", ci_yaml);
229
+ try writeFile(app_dir, io, "build.zig", build_zig);
230
+ try writeFile(app_dir, io, "build.zig.zon", build_zon);
231
+ try writeFile(app_dir, io, "src/core.ts", tsCoreStarter());
232
+ try writeFile(app_dir, io, "src/app.native", tsAppMarkup());
233
+ try writeFile(app_dir, io, "app.zon", app_zon);
234
+ try writeFile(app_dir, io, "assets/icon.png", default_icon_png);
235
+ try writeFile(app_dir, io, ".gitignore", tsGitignore());
236
+ try writeFile(app_dir, io, "README.md", readme_md);
237
+ try writeTsEditorSurface(allocator, io, app_dir, names, destination, sdk_source);
238
+ }
239
+
240
+ /// The editor-and-versioning surface of a TS scaffold: package.json (the
241
+ /// app's name and its `@native-sdk/core` dependency at the SDK's bundled
242
+ /// version), tsconfig.json (the checker's own compiler options, so editor
243
+ /// errors match `native check` reality), and a materialized
244
+ /// node_modules/@native-sdk/core so resolution works BEFORE the package is
245
+ /// published to npm. `sdk_source` is the framework checkout as reachable
246
+ /// from the CLI's cwd (unlike the destination-relative build.zig.zon path).
247
+ fn writeTsEditorSurface(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir, names: TemplateNames, destination: []const u8, sdk_source: []const u8) !void {
248
+ const sdk_version = ts_core.bundledSdkVersion(allocator, io, sdk_source) catch |err| {
249
+ std.debug.print("the Native SDK at {s} is missing packages/core/package.json - is the checkout (or npm install) complete?\n", .{sdk_source});
250
+ return err;
251
+ };
252
+ defer allocator.free(sdk_version);
253
+ const package_json = try tsPackageJson(allocator, names, sdk_version);
254
+ defer allocator.free(package_json);
255
+ try writeFile(app_dir, io, "package.json", package_json);
256
+ try writeFile(app_dir, io, "tsconfig.json", tsTsconfig());
257
+ _ = try ts_core.ensureEditorPackage(allocator, io, sdk_source, destination);
258
+ }
259
+
260
+ /// The app's package.json: name + the pinned `@native-sdk/core` dependency,
261
+ /// nothing else. It exists for editors and versioning only — the `native`
262
+ /// verbs never read it (tree detection keys on src/core.ts; the build
263
+ /// transpiles against the SDK checkout) — and the pin is exact so the
264
+ /// post-publish `npm install` resolves the same content the CLI
265
+ /// materialized.
266
+ fn tsPackageJson(allocator: std.mem.Allocator, names: TemplateNames, sdk_version: []const u8) ![]const u8 {
267
+ var out: std.ArrayList(u8) = .empty;
268
+ errdefer out.deinit(allocator);
269
+ try out.appendSlice(allocator, "{\n \"name\": ");
270
+ try appendJsonString(&out, allocator, names.package_name);
271
+ try out.appendSlice(allocator,
272
+ \\,
273
+ \\ "private": true,
274
+ \\ "description": "Editor and versioning surface only: stock TypeScript tooling resolves @native-sdk/core from here. The native CLI never reads it and builds with node_modules absent.",
275
+ \\ "dependencies": {
276
+ \\ "@native-sdk/core":
277
+ );
278
+ try out.appendSlice(allocator, " ");
279
+ try appendJsonString(&out, allocator, sdk_version);
280
+ try out.appendSlice(allocator,
281
+ \\
282
+ \\ }
283
+ \\}
284
+ \\
285
+ );
286
+ return out.toOwnedSlice(allocator);
287
+ }
288
+
289
+ /// The editor tsconfig: the same compiler options the @native-sdk/core
290
+ /// checker builds its program with (typed_ast.ts subsetCompilerOptions), so
291
+ /// what the editor flags is what `native check` flags — minus the SDK
292
+ /// `paths` injection: editors resolve `@native-sdk/core` through
293
+ /// node_modules like any package.
294
+ fn tsTsconfig() []const u8 {
295
+ return
296
+ \\{
297
+ \\ // Mirrors the compiler options the @native-sdk/core checker enforces,
298
+ \\ // so editor diagnostics match `native check` reality. @native-sdk/core
299
+ \\ // resolves from node_modules: the native CLI materializes the SDK's
300
+ \\ // copy there (and keeps it fresh) until the package is on npm.
301
+ \\ "compilerOptions": {
302
+ \\ "strict": true,
303
+ \\ "target": "esnext",
304
+ \\ "module": "esnext",
305
+ \\ "moduleResolution": "bundler",
306
+ \\ "lib": ["esnext"],
307
+ \\ "types": [],
308
+ \\ "allowImportingTsExtensions": true,
309
+ \\ "verbatimModuleSyntax": true,
310
+ \\ "exactOptionalPropertyTypes": true,
311
+ \\ "noFallthroughCasesInSwitch": true,
312
+ \\ "isolatedModules": true,
313
+ \\ "noEmit": true,
314
+ \\ "skipLibCheck": true
315
+ \\ },
316
+ \\ "include": ["src/**/*.ts"]
317
+ \\}
318
+ \\
319
+ ;
320
+ }
321
+
322
+ /// TS scaffolds ignore node_modules on top of the slim set: the
323
+ /// @native-sdk/core copy in there is CLI-managed (npm-managed after
324
+ /// publish), never source. `.native/` stays: `native check` stages the
325
+ /// emitted core there for --full trees too.
326
+ fn tsGitignore() []const u8 {
327
+ return
328
+ \\.native/
329
+ \\zig-out/
330
+ \\.zig-cache/
331
+ \\node_modules/
332
+ \\
333
+ ;
334
+ }
335
+
336
+ /// The starter core: a counter with a repeating tick (Sub.timer) and a
337
+ /// timestamp request (Cmd.now) - one of each effect surface, small enough
338
+ /// to read whole.
339
+ fn tsCoreStarter() []const u8 {
340
+ return
341
+ \\// The app core: Model, Msg, update, and the pure helpers they call -
342
+ \\// plain TypeScript in the app-core subset, compiled to native Zig at
343
+ \\// build time (no JS runtime ships in the binary). The view lives in
344
+ \\// app.native and binds this model by its own field names exactly as
345
+ \\// written here (`tickCount` binds as `{tickCount}`).
346
+ \\//
347
+ \\// The loop: edit here -> `native dev --core` for instant logic checks
348
+ \\// under node -> `native dev` to run the real app. `native check`
349
+ \\// verifies this file and the markup together.
350
+ \\
351
+ \\import { Cmd, Sub } from "@native-sdk/core";
352
+ \\
353
+ \\export interface Model {
354
+ \\ readonly count: number;
355
+ \\ readonly ticking: boolean;
356
+ \\ readonly tickCount: number;
357
+ \\ readonly stampedMs: number;
358
+ \\}
359
+ \\
360
+ \\export type Msg =
361
+ \\ | { readonly kind: "increment" }
362
+ \\ | { readonly kind: "decrement" }
363
+ \\ | { readonly kind: "reset" }
364
+ \\ | { readonly kind: "toggle_ticking" }
365
+ \\ | { readonly kind: "stamp" }
366
+ \\ | { readonly kind: "stamped"; readonly at: number }
367
+ \\ | { readonly kind: "tick"; readonly at: number };
368
+ \\
369
+ \\// `tick` and `stamped` are dispatched by the host (timer fires and the
370
+ \\// Cmd.now result), never from markup - this list keeps `native check`'s
371
+ \\// unbound-state lint honest about that.
372
+ \\export const viewUnbound = ["tick", "stamped"] as const;
373
+ \\
374
+ \\export function initialModel(): Model {
375
+ \\ return { count: 0, ticking: false, tickCount: 0, stampedMs: -1 };
376
+ \\}
377
+ \\
378
+ \\// Exported single-model helpers become bindings too: `{total}` in
379
+ \\// app.native reads this.
380
+ \\export function total(model: Model): number {
381
+ \\ return model.count + model.tickCount;
382
+ \\}
383
+ \\
384
+ \\export function update(model: Model, msg: Msg): Model | [Model, Cmd<Msg>] {
385
+ \\ switch (msg.kind) {
386
+ \\ case "increment":
387
+ \\ return { ...model, count: model.count + 1 };
388
+ \\ case "decrement":
389
+ \\ return { ...model, count: model.count - 1 };
390
+ \\ case "reset":
391
+ \\ return { ...model, count: 0, tickCount: 0 };
392
+ \\ case "toggle_ticking":
393
+ \\ return { ...model, ticking: !model.ticking };
394
+ \\ case "stamp":
395
+ \\ // Effects are data: the host performs this after commit and
396
+ \\ // dispatches `stamped` with the time.
397
+ \\ return [model, Cmd.now("stamped")];
398
+ \\ case "stamped":
399
+ \\ return { ...model, stampedMs: msg.at };
400
+ \\ case "tick":
401
+ \\ return { ...model, tickCount: model.tickCount + 1 };
402
+ \\ }
403
+ \\}
404
+ \\
405
+ \\// Recurring effects are declared from the model: while `ticking` holds,
406
+ \\// the host fires `tick` every second; flip it off and the timer stops.
407
+ \\export function subscriptions(model: Model): Sub<Msg> {
408
+ \\ if (!model.ticking) return Sub.none;
409
+ \\ return Sub.timer("tick", 1000, "tick");
410
+ \\}
411
+ \\
412
+ ;
413
+ }
414
+
415
+ fn tsAppMarkup() []const u8 {
416
+ return
417
+ \\<!-- The whole view: markup over the core's emitted model. Embedded at
418
+ \\ build time and hot-reloaded while `native dev` runs. Fields bind
419
+ \\ by the names core.ts wrote ({tickCount}); exported single-model
420
+ \\ helpers bind too ({total}). Validate with: native check -->
421
+ \\<column gap="12" padding="16">
422
+ \\ <row gap="8" cross="center">
423
+ \\ <text grow="1">Counter</text>
424
+ \\ <button size="sm" variant="ghost" on-press="reset">Reset</button>
425
+ \\ </row>
426
+ \\ <row gap="8" main="center" cross="center" grow="1">
427
+ \\ <button variant="secondary" on-press="decrement">-</button>
428
+ \\ <text>{count}</text>
429
+ \\ <button variant="primary" on-press="increment">+</button>
430
+ \\ </row>
431
+ \\ <row gap="8" cross="center">
432
+ \\ <switch checked="{ticking}" on-toggle="toggle_ticking">Tick every second</switch>
433
+ \\ <text grow="1">ticks {tickCount}</text>
434
+ \\ <button size="sm" on-press="stamp">Stamp</button>
435
+ \\ </row>
436
+ \\ <status-bar>total: {total} | stamped: {stampedMs}ms</status-bar>
437
+ \\</column>
438
+ \\
439
+ ;
440
+ }
441
+
442
+ fn tsSlimReadme(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8 {
443
+ var out: std.ArrayList(u8) = .empty;
444
+ errdefer out.deinit(allocator);
445
+ try out.appendSlice(allocator, "# ");
446
+ try out.appendSlice(allocator, names.display_name);
447
+ try out.appendSlice(allocator,
448
+ \\
449
+ \\
450
+ \\A native app authored in TypeScript and markup: the logic lives in
451
+ \\`src/core.ts` (Model, Msg, update - the app-core subset, compiled to
452
+ \\native code at build time; no JS runtime ships in the binary) and the
453
+ \\view in `src/app.native`. There is no Zig in this tree and nothing to
454
+ \\configure: the build detects `src/core.ts` and wires everything.
455
+ \\
456
+ \\## The loop
457
+ \\
458
+ \\```sh
459
+ \\native dev --core # fastest: run the core's logic under node -
460
+ \\ # dispatch messages as JSON lines, watch the model
461
+ \\ # and effect transcript (not a renderer)
462
+ \\native dev # build and run the real app (markup hot reload)
463
+ \\native check # verify core.ts (subset checker) + markup + app.zon
464
+ \\native build # ReleaseFast binary in zig-out/bin/
465
+ \\native test # the app's test suite
466
+ \\```
467
+ \\
468
+ \\Edit `src/core.ts` for behavior, `src/app.native` for the view, and
469
+ \\`app.zon` for windows/identity/permissions. Markup binds the model's
470
+ \\field names exactly as core.ts wrote them (`tickCount` -> `{tickCount}`),
471
+ \\and exported single-model helpers bind as derived values (`{total}`).
472
+ \\
473
+ \\## Try the core loop
474
+ \\
475
+ \\```sh
476
+ \\printf '%s\n' '{"kind":"increment"}' '{"kind":"toggle_ticking"}' '{"advance":3000}' | native dev --core
477
+ \\```
478
+ \\
479
+ \\## Editor support
480
+ \\
481
+ \\Stock editor TypeScript just works: `package.json` and `tsconfig.json`
482
+ \\are the editor-and-versioning surface (the tsconfig mirrors the checker's
483
+ \\own options, so editor errors match `native check`), and
484
+ \\`node_modules/@native-sdk/core` is a CLI-managed copy of the SDK package
485
+ \\so `@native-sdk/core` resolves with full IntelliSense. Builds never read
486
+ \\any of it — delete node_modules and every `native` verb still works; the
487
+ \\next `native check`/`dev`/`build` puts it back. Running `npm install`
488
+ \\is optional for the same reason: the CLI materializes and refreshes the
489
+ \\package itself, and an install simply lands the identical content once
490
+ \\`@native-sdk/core` is on npm.
491
+ \\
492
+ \\## Requirements
493
+ \\
494
+ \\Node.js 22+ on PATH (the TypeScript-to-native transpiler runs at build
495
+ \\time; your shipped binary carries none of it).
496
+ \\
497
+ );
498
+ return out.toOwnedSlice(allocator);
499
+ }
500
+
154
501
  fn slimNativeReadme(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8 {
155
502
  var out: std.ArrayList(u8) = .empty;
156
503
  errdefer out.deinit(allocator);
@@ -205,7 +552,7 @@ fn writeNativeApp(allocator: std.mem.Allocator, io: std.Io, app_dir: std.Io.Dir,
205
552
  defer allocator.free(app_zon);
206
553
  const readme_md = try nativeReadme(allocator, names, framework_path);
207
554
  defer allocator.free(readme_md);
208
- const ci_yaml = try nativeCiYaml(allocator, names, framework_path);
555
+ const ci_yaml = try nativeCiYaml(allocator, names, framework_path, .zig);
209
556
  defer allocator.free(ci_yaml);
210
557
 
211
558
  try writeFile(app_dir, io, "build.zig", build_zig);
@@ -277,9 +624,11 @@ fn nativeMainZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
277
624
  var out: std.ArrayList(u8) = .empty;
278
625
  errdefer out.deinit(allocator);
279
626
  try out.appendSlice(allocator,
280
- \\//! A minimal native-rendered Native SDK app: the view lives in
281
- \\//! `app.native` (embedded into the binary, and watched for hot reload in
282
- \\//! dev); this file is the logic: `Model`, `Msg`, and `update`.
627
+ \\//! The app core in Zig: `Model`, `Msg`, and `update` - the same
628
+ \\//! counter-with-effects starter the TypeScript template builds. The view
629
+ \\//! lives in `app.native` (embedded into the binary, and watched for hot
630
+ \\//! reload in dev); recurring work and clock reads ride the effects
631
+ \\//! channel, so `update` stays a plain function of model + message.
283
632
  \\
284
633
  \\const std = @import("std");
285
634
  \\const runner = @import("runner");
@@ -319,17 +668,66 @@ fn nativeMainZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
319
668
  \\ increment,
320
669
  \\ decrement,
321
670
  \\ reset,
671
+ \\ toggle_ticking,
672
+ \\ stamp,
673
+ \\ tick: native_sdk.EffectTimer,
674
+ \\
675
+ \\ // `tick` is dispatched by the host (the repeating timer fires),
676
+ \\ // never from markup - this keeps the unbound-state lint honest
677
+ \\ // about that.
678
+ \\ pub const view_unbound = .{"tick"};
322
679
  \\};
323
680
  \\
324
681
  \\pub const Model = struct {
325
682
  \\ count: i64 = 0,
683
+ \\ ticking: bool = false,
684
+ \\ tick_count: i64 = 0,
685
+ \\ stamped_ms: i64 = -1,
686
+ \\
687
+ \\ // Public single-model helpers become bindings too: `{total}` in
688
+ \\ // app.native reads this.
689
+ \\ pub fn total(model: *const Model) i64 {
690
+ \\ return model.count + model.tick_count;
691
+ \\ }
326
692
  \\};
327
693
  \\
328
- \\pub fn update(model: *Model, msg: Msg) void {
694
+ \\pub const Effects = native_sdk.Effects(Msg);
695
+ \\
696
+ \\/// The repeating tick's effects-channel key: starting an active key
697
+ \\/// replaces the timer in place, so toggling never double-registers.
698
+ \\pub const tick_timer_key: u64 = 1;
699
+ \\
700
+ \\pub fn update(model: *Model, msg: Msg, fx: *Effects) void {
329
701
  \\ switch (msg) {
330
702
  \\ .increment => model.count += 1,
331
703
  \\ .decrement => model.count -= 1,
332
- \\ .reset => model.count = 0,
704
+ \\ .reset => {
705
+ \\ model.count = 0;
706
+ \\ model.tick_count = 0;
707
+ \\ },
708
+ \\ .toggle_ticking => {
709
+ \\ model.ticking = !model.ticking;
710
+ \\ // Recurring effects are timers on the effects channel: while
711
+ \\ // `ticking` holds, the host fires `tick` every second; flip
712
+ \\ // it off and the timer stops.
713
+ \\ if (model.ticking) {
714
+ \\ fx.startTimer(.{
715
+ \\ .key = tick_timer_key,
716
+ \\ .interval_ms = 1000,
717
+ \\ .mode = .repeating,
718
+ \\ .on_fire = Effects.timerMsg(.tick),
719
+ \\ });
720
+ \\ } else {
721
+ \\ fx.cancelTimer(tick_timer_key);
722
+ \\ }
723
+ \\ },
724
+ \\ // The journaled clock read - deterministic under session replay,
725
+ \\ // the Zig equivalent of the TypeScript starter's `Cmd.now`.
726
+ \\ .stamp => model.stamped_ms = fx.wallMs(),
727
+ \\ .tick => |timer| {
728
+ \\ if (timer.outcome != .fired) return;
729
+ \\ model.tick_count += 1;
730
+ \\ },
333
731
  \\ }
334
732
  \\}
335
733
  \\
@@ -360,7 +758,7 @@ fn nativeMainZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
360
758
  \\,
361
759
  \\ .scene = shell_scene,
362
760
  \\ .canvas_label = canvas_label,
363
- \\ .update = update,
761
+ \\ .update_fx = update,
364
762
  \\ .markup = .{ .source = app_markup, .watch_path = "src/app.native", .io = init.io },
365
763
  \\ });
366
764
  \\ defer app_state.destroy();
@@ -406,9 +804,11 @@ fn nativeMainZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u8
406
804
 
407
805
  fn nativeAppMarkup() []const u8 {
408
806
  return
409
- \\<!-- The whole view. Embedded into the binary and hot-reloaded in dev:
410
- \\ edit this file while the app runs and the window updates without
411
- \\ losing the count. Validate with: native markup check src/app.native -->
807
+ \\<!-- The whole view: markup over the core's model. Embedded into the
808
+ \\ binary and hot-reloaded in dev: edit this file while the app runs
809
+ \\ and the window updates without losing the count. Fields bind by
810
+ \\ the names main.zig wrote ({tick_count}); public single-model
811
+ \\ helpers bind too ({total}). Validate with: native check -->
412
812
  \\<column gap="12" padding="16">
413
813
  \\ <row gap="8" cross="center">
414
814
  \\ <text grow="1">Counter</text>
@@ -419,7 +819,12 @@ fn nativeAppMarkup() []const u8 {
419
819
  \\ <text>{count}</text>
420
820
  \\ <button variant="primary" on-press="increment">+</button>
421
821
  \\ </row>
422
- \\ <status-bar>count: {count}</status-bar>
822
+ \\ <row gap="8" cross="center">
823
+ \\ <switch checked="{ticking}" on-toggle="toggle_ticking">Tick every second</switch>
824
+ \\ <text grow="1">ticks {tick_count}</text>
825
+ \\ <button size="sm" on-press="stamp">Stamp</button>
826
+ \\ </row>
827
+ \\ <status-bar>total: {total} | stamped: {stamped_ms}ms</status-bar>
423
828
  \\</column>
424
829
  \\
425
830
  ;
@@ -440,6 +845,7 @@ fn nativeTestsZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u
440
845
  \\const AppUi = main.AppUi;
441
846
  \\const Model = main.Model;
442
847
  \\const Msg = main.Msg;
848
+ \\const Effects = main.Effects;
443
849
  \\
444
850
  \\const AppMarkup = canvas.MarkupView(Model, Msg);
445
851
  \\
@@ -481,37 +887,106 @@ fn nativeTestsZig(allocator: std.mem.Allocator, names: TemplateNames) ![]const u
481
887
  \\ defer arena_state.deinit();
482
888
  \\ const arena = arena_state.allocator();
483
889
  \\
890
+ \\ // A real effects channel in fake-executor mode: requests are
891
+ \\ // recorded for assertions instead of touching the OS.
892
+ \\ var fx = Effects.init(testing.allocator);
893
+ \\ defer fx.deinit();
894
+ \\ fx.executor = .fake;
895
+ \\
484
896
  \\ var model = main.initialModel();
485
897
  \\
486
898
  \\ var tree = try buildTree(arena, &model);
487
899
  \\ _ = try expectByText(tree.root, .text, "0");
488
- \\ _ = try expectByText(tree.root, .status_bar, "count: 0");
900
+ \\ _ = try expectByText(tree.root, .status_bar, "total: 0 | stamped: -1ms");
489
901
  \\
490
902
  \\ // Click "+": the count increments and the view rebuilds with the
491
903
  \\ // new value, keeping widget ids stable.
492
904
  \\ const plus = try expectByText(tree.root, .button, "+");
493
- \\ main.update(&model, tree.msgForPointer(plus.id, .up).?);
905
+ \\ main.update(&model, tree.msgForPointer(plus.id, .up).?, &fx);
494
906
  \\ try testing.expectEqual(@as(i64, 1), model.count);
495
907
  \\
496
908
  \\ tree = try buildTree(arena, &model);
497
909
  \\ _ = try expectByText(tree.root, .text, "1");
498
- \\ _ = try expectByText(tree.root, .status_bar, "count: 1");
910
+ \\ _ = try expectByText(tree.root, .status_bar, "total: 1 | stamped: -1ms");
499
911
  \\ try testing.expectEqual(plus.id, (try expectByText(tree.root, .button, "+")).id);
500
912
  \\
501
913
  \\ // Click "-" twice: the count goes negative.
502
914
  \\ const minus = try expectByText(tree.root, .button, "-");
503
- \\ main.update(&model, tree.msgForPointer(minus.id, .up).?);
504
- \\ main.update(&model, tree.msgForPointer(minus.id, .up).?);
915
+ \\ main.update(&model, tree.msgForPointer(minus.id, .up).?, &fx);
916
+ \\ main.update(&model, tree.msgForPointer(minus.id, .up).?, &fx);
505
917
  \\ try testing.expectEqual(@as(i64, -1), model.count);
506
918
  \\
507
- \\ // Click "Reset": back to zero.
919
+ \\ // Click "Reset": the count and the tick tally both go back to zero.
508
920
  \\ tree = try buildTree(arena, &model);
509
921
  \\ const reset = try expectByText(tree.root, .button, "Reset");
510
- \\ main.update(&model, tree.msgForPointer(reset.id, .up).?);
922
+ \\ main.update(&model, tree.msgForPointer(reset.id, .up).?, &fx);
511
923
  \\ try testing.expectEqual(@as(i64, 0), model.count);
512
924
  \\
513
925
  \\ tree = try buildTree(arena, &model);
514
- \\ _ = try expectByText(tree.root, .status_bar, "count: 0");
926
+ \\ _ = try expectByText(tree.root, .status_bar, "total: 0 | stamped: -1ms");
927
+ \\}
928
+ \\
929
+ \\test "the ticking switch drives the repeating timer through the effects channel" {
930
+ \\ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
931
+ \\ defer arena_state.deinit();
932
+ \\ const arena = arena_state.allocator();
933
+ \\
934
+ \\ var fx = Effects.init(testing.allocator);
935
+ \\ defer fx.deinit();
936
+ \\ fx.executor = .fake;
937
+ \\
938
+ \\ var model = main.initialModel();
939
+ \\ var tree = try buildTree(arena, &model);
940
+ \\
941
+ \\ // Flip the switch on: the model tracks it and one repeating 1s
942
+ \\ // timer is registered on the effects channel.
943
+ \\ const ticker = try expectByText(tree.root, .switch_control, "Tick every second");
944
+ \\ main.update(&model, tree.msgForPointer(ticker.id, .up).?, &fx);
945
+ \\ try testing.expect(model.ticking);
946
+ \\ try testing.expectEqual(@as(usize, 1), fx.pendingTimerCount());
947
+ \\ const request = fx.pendingTimerAt(0).?;
948
+ \\ try testing.expectEqual(main.tick_timer_key, request.key);
949
+ \\ try testing.expectEqual(@as(u64, 1000), request.interval_ms);
950
+ \\
951
+ \\ // Each timer fire arrives as an ordinary `tick` Msg through the
952
+ \\ // same update path as a click.
953
+ \\ main.update(&model, .{ .tick = .{ .key = main.tick_timer_key } }, &fx);
954
+ \\ main.update(&model, .{ .tick = .{ .key = main.tick_timer_key } }, &fx);
955
+ \\ try testing.expectEqual(@as(i64, 2), model.tick_count);
956
+ \\
957
+ \\ tree = try buildTree(arena, &model);
958
+ \\ _ = try expectByText(tree.root, .text, "ticks 2");
959
+ \\ _ = try expectByText(tree.root, .status_bar, "total: 2 | stamped: -1ms");
960
+ \\
961
+ \\ // Flip it off: the timer is cancelled, nothing left armed.
962
+ \\ main.update(&model, tree.msgForPointer(ticker.id, .up).?, &fx);
963
+ \\ try testing.expect(!model.ticking);
964
+ \\ try testing.expectEqual(@as(usize, 0), fx.pendingTimerCount());
965
+ \\}
966
+ \\
967
+ \\test "stamp reads the journaled wall clock" {
968
+ \\ var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
969
+ \\ defer arena_state.deinit();
970
+ \\ const arena = arena_state.allocator();
971
+ \\
972
+ \\ var fx = Effects.init(testing.allocator);
973
+ \\ defer fx.deinit();
974
+ \\ fx.executor = .fake;
975
+ \\ // Swap the clock seam for a hand-cranked one: `fx.wallMs()`
976
+ \\ // becomes deterministic, exactly like session replay.
977
+ \\ var test_clock = native_sdk.TestClock{};
978
+ \\ test_clock.setWallMs(4200);
979
+ \\ fx.clock = test_clock.clock();
980
+ \\
981
+ \\ var model = main.initialModel();
982
+ \\ var tree = try buildTree(arena, &model);
983
+ \\
984
+ \\ const stamp = try expectByText(tree.root, .button, "Stamp");
985
+ \\ main.update(&model, tree.msgForPointer(stamp.id, .up).?, &fx);
986
+ \\ try testing.expectEqual(@as(i64, 4200), model.stamped_ms);
987
+ \\
988
+ \\ tree = try buildTree(arena, &model);
989
+ \\ _ = try expectByText(tree.root, .status_bar, "total: 0 | stamped: 4200ms");
515
990
  \\}
516
991
  \\
517
992
  \\test "the view lays out through the canvas engine" {
@@ -665,8 +1140,26 @@ fn nativeReadme(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
665
1140
  /// GitHub Actions workflow for a native-rendered app: a null-platform
666
1141
  /// logic-test job plus a Linux Xvfb automation smoke job that launches the
667
1142
  /// real binary and asserts on the accessibility snapshot. The generated
668
- /// file belongs to the user, like everything init writes.
669
- fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_path: []const u8) ![]const u8 {
1143
+ /// file belongs to the user, like everything init writes. A TypeScript
1144
+ /// core adds the node tier to both jobs: setup-node plus one `npm ci` in
1145
+ /// the fetched SDK's packages/core, because the @native-sdk/core
1146
+ /// transpiler runs under node at build time and needs its own installed
1147
+ /// dependency there — the same install `native build`'s teaching names.
1148
+ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_path: []const u8, core: CoreTemplate) ![]const u8 {
1149
+ const node_setup =
1150
+ \\ - uses: actions/setup-node@v4
1151
+ \\ with:
1152
+ \\ node-version: 22
1153
+ \\
1154
+ ;
1155
+ const transpiler_install =
1156
+ \\ - name: Install the core transpiler dependency
1157
+ \\ # src/core.ts compiles to native code at build time: the
1158
+ \\ # @native-sdk/core transpiler runs under node from the SDK
1159
+ \\ # dependency and needs its dependency installed there once.
1160
+ \\ run: npm ci --prefix "$NATIVE_SDK_PATH/packages/core"
1161
+ \\
1162
+ ;
670
1163
  var out: std.ArrayList(u8) = .empty;
671
1164
  errdefer out.deinit(allocator);
672
1165
  try out.appendSlice(allocator,
@@ -701,11 +1194,19 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
701
1194
  \\ - uses: mlugg/setup-zig@v2
702
1195
  \\ with:
703
1196
  \\ version: 0.16.0
1197
+ \\
1198
+ );
1199
+ if (core == .ts) try out.appendSlice(allocator, node_setup);
1200
+ try out.appendSlice(allocator,
704
1201
  \\ - name: Fetch native-sdk
705
1202
  \\ run: |
706
1203
  \\ if [ ! -f "$NATIVE_SDK_PATH/build.zig" ]; then
707
1204
  \\ git clone --depth 1 https://github.com/vercel-labs/native.git "$NATIVE_SDK_PATH"
708
1205
  \\ fi
1206
+ \\
1207
+ );
1208
+ if (core == .ts) try out.appendSlice(allocator, transpiler_install);
1209
+ try out.appendSlice(allocator,
709
1210
  \\ - run: zig build test -Dplatform=null
710
1211
  \\
711
1212
  \\ smoke:
@@ -716,6 +1217,10 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
716
1217
  \\ - uses: mlugg/setup-zig@v2
717
1218
  \\ with:
718
1219
  \\ version: 0.16.0
1220
+ \\
1221
+ );
1222
+ if (core == .ts) try out.appendSlice(allocator, node_setup);
1223
+ try out.appendSlice(allocator,
719
1224
  \\ - name: Install GTK and Xvfb
720
1225
  \\ # No WebKitGTK dev package: this app declares no web use, so its
721
1226
  \\ # Linux host compiles without the embedded web layer and never
@@ -727,6 +1232,10 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
727
1232
  \\ if [ ! -f "$NATIVE_SDK_PATH/build.zig" ]; then
728
1233
  \\ git clone --depth 1 https://github.com/vercel-labs/native.git "$NATIVE_SDK_PATH"
729
1234
  \\ fi
1235
+ \\
1236
+ );
1237
+ if (core == .ts) try out.appendSlice(allocator, transpiler_install);
1238
+ try out.appendSlice(allocator,
730
1239
  \\ - name: Build the Native SDK CLI
731
1240
  \\ run: cd "$NATIVE_SDK_PATH" && zig build
732
1241
  \\ - name: Build and drive the app headless
@@ -743,7 +1252,7 @@ fn nativeCiYaml(allocator: std.mem.Allocator, names: TemplateNames, framework_pa
743
1252
  \\ pid=$!
744
1253
  \\ trap 'kill "$pid" >/dev/null 2>&1 || true' EXIT
745
1254
  \\ "$cli" automate wait
746
- \\ "$cli" automate assert 'gpu_nonblank=true' 'role=button name="Reset"' 'count: 0'
1255
+ \\ "$cli" automate assert 'gpu_nonblank=true' 'role=button name="Reset"' 'total: 0'
747
1256
  \\ "$cli" automate screenshot main-canvas
748
1257
  \\ test -s .zig-cache/native-sdk-automation/screenshot-main-canvas.png
749
1258
  \\
@@ -3101,14 +3610,113 @@ test "writeDefaultApp emits frontend-specific Next paths" {
3101
3610
  try std.testing.expect(std.mem.indexOf(u8, tsconfig_text, "\"@/*\": [\"./app/*\"]") != null);
3102
3611
  }
3103
3612
 
3104
- test "writeDefaultApp emits a slim native scaffold by default" {
3105
- const destination = ".zig-cache/test-native-slim-template";
3613
+ test "writeDefaultApp emits the TS-core scaffold by default: three files of truth, zero Zig" {
3614
+ const destination = ".zig-cache/test-ts-slim-template";
3106
3615
  try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native });
3107
3616
 
3617
+ const core_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "src/core.ts");
3618
+ defer std.testing.allocator.free(core_text);
3619
+ const markup_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "src/app.native");
3620
+ defer std.testing.allocator.free(markup_text);
3621
+ const ts_app_zon = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.zon");
3622
+ defer std.testing.allocator.free(ts_app_zon);
3623
+ const ts_readme = try readTestFile(std.testing.allocator, std.testing.io, destination, "README.md");
3624
+ defer std.testing.allocator.free(ts_readme);
3625
+
3626
+ // ZERO Zig in the tree, no build files: the build graph detects
3627
+ // src/core.ts and stages the wiring outside the app. Zero-config
3628
+ // parity with the slim Zig scaffold: no CI workflow either — the
3629
+ // full shape owns that surface.
3630
+ try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "src/main.zig"));
3631
+ try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "build.zig"));
3632
+ try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, ".github/workflows/ci.yml"));
3633
+
3634
+ // The starter uses one Cmd and one Sub, declares the lint opt-out, and
3635
+ // exports a bindable helper.
3636
+ try std.testing.expect(std.mem.indexOf(u8, core_text, "Cmd.now(") != null);
3637
+ try std.testing.expect(std.mem.indexOf(u8, core_text, "Sub.timer(") != null);
3638
+ try std.testing.expect(std.mem.indexOf(u8, core_text, "export const viewUnbound") != null);
3639
+ try std.testing.expect(std.mem.indexOf(u8, core_text, "export function total(") != null);
3640
+ // The markup binds the model's own TS field names and the helper.
3641
+ try std.testing.expect(std.mem.indexOf(u8, markup_text, "{tickCount}") != null);
3642
+ try std.testing.expect(std.mem.indexOf(u8, markup_text, "{total}") != null);
3643
+ try std.testing.expect(std.mem.indexOf(u8, ts_app_zon, "gpu_surface") != null);
3644
+ // The README teaches the loop, node-first.
3645
+ try std.testing.expect(std.mem.indexOf(u8, ts_readme, "native dev --core") != null);
3646
+ try std.testing.expect(std.mem.indexOf(u8, ts_readme, "native check") != null);
3647
+
3648
+ // The editor surface: package.json pins @native-sdk/core at the SDK's
3649
+ // bundled version, tsconfig.json mirrors the checker's options, and
3650
+ // node_modules carries the materialized SDK package so stock tsc
3651
+ // resolves both entry points before the npm publish exists.
3652
+ const package_json = try readTestFile(std.testing.allocator, std.testing.io, destination, "package.json");
3653
+ defer std.testing.allocator.free(package_json);
3654
+ try std.testing.expect(std.mem.indexOf(u8, package_json, "\"name\": \"my-app\"") != null);
3655
+ try std.testing.expect(std.mem.indexOf(u8, package_json, "\"private\": true") != null);
3656
+ const bundled_version = try ts_core.bundledSdkVersion(std.testing.allocator, std.testing.io, ".");
3657
+ defer std.testing.allocator.free(bundled_version);
3658
+ const pinned = try std.fmt.allocPrint(std.testing.allocator, "\"@native-sdk/core\": \"{s}\"", .{bundled_version});
3659
+ defer std.testing.allocator.free(pinned);
3660
+ try std.testing.expect(std.mem.indexOf(u8, package_json, pinned) != null);
3661
+
3662
+ const tsconfig = try readTestFile(std.testing.allocator, std.testing.io, destination, "tsconfig.json");
3663
+ defer std.testing.allocator.free(tsconfig);
3664
+ try std.testing.expect(std.mem.indexOf(u8, tsconfig, "\"strict\": true") != null);
3665
+ try std.testing.expect(std.mem.indexOf(u8, tsconfig, "\"moduleResolution\": \"bundler\"") != null);
3666
+ try std.testing.expect(std.mem.indexOf(u8, tsconfig, "\"noEmit\": true") != null);
3667
+ try std.testing.expect(std.mem.indexOf(u8, tsconfig, "\"exactOptionalPropertyTypes\": true") != null);
3668
+
3669
+ const editor_manifest = try readTestFile(std.testing.allocator, std.testing.io, destination, "node_modules/@native-sdk/core/package.json");
3670
+ defer std.testing.allocator.free(editor_manifest);
3671
+ try std.testing.expect(std.mem.indexOf(u8, editor_manifest, "\"@native-sdk/core\"") != null);
3672
+ const editor_core = try readTestFile(std.testing.allocator, std.testing.io, destination, "node_modules/@native-sdk/core/sdk/core.ts");
3673
+ defer std.testing.allocator.free(editor_core);
3674
+ try std.testing.expect(editor_core.len > 0);
3675
+ const editor_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "node_modules/@native-sdk/core/sdk/text.ts");
3676
+ defer std.testing.allocator.free(editor_text);
3677
+ try std.testing.expect(editor_text.len > 0);
3678
+ const editor_events = try readTestFile(std.testing.allocator, std.testing.io, destination, "node_modules/@native-sdk/core/sdk/events.ts");
3679
+ defer std.testing.allocator.free(editor_events);
3680
+ try std.testing.expect(editor_events.len > 0);
3681
+
3682
+ // node_modules is generated surface: ignored, never source.
3683
+ const ts_gitignore = try readTestFile(std.testing.allocator, std.testing.io, destination, ".gitignore");
3684
+ defer std.testing.allocator.free(ts_gitignore);
3685
+ try std.testing.expect(std.mem.indexOf(u8, ts_gitignore, "node_modules/") != null);
3686
+ try std.testing.expect(std.mem.indexOf(u8, ts_gitignore, ".native/") != null);
3687
+ }
3688
+
3689
+ test "writeDefaultApp --full ts-core carries the same editor surface" {
3690
+ const destination = ".zig-cache/test-ts-full-template";
3691
+ try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full });
3692
+
3693
+ const build_zig_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "build.zig");
3694
+ defer std.testing.allocator.free(build_zig_text);
3695
+ try std.testing.expect(std.mem.indexOf(u8, build_zig_text, "native_sdk.addApp") != null);
3696
+ const package_json = try readTestFile(std.testing.allocator, std.testing.io, destination, "package.json");
3697
+ defer std.testing.allocator.free(package_json);
3698
+ try std.testing.expect(std.mem.indexOf(u8, package_json, "\"@native-sdk/core\"") != null);
3699
+ const tsconfig = try readTestFile(std.testing.allocator, std.testing.io, destination, "tsconfig.json");
3700
+ defer std.testing.allocator.free(tsconfig);
3701
+ try std.testing.expect(std.mem.indexOf(u8, tsconfig, "\"moduleResolution\": \"bundler\"") != null);
3702
+ const editor_core = try readTestFile(std.testing.allocator, std.testing.io, destination, "node_modules/@native-sdk/core/sdk/core.ts");
3703
+ defer std.testing.allocator.free(editor_core);
3704
+ try std.testing.expect(editor_core.len > 0);
3705
+ const gitignore_text = try readTestFile(std.testing.allocator, std.testing.io, destination, ".gitignore");
3706
+ defer std.testing.allocator.free(gitignore_text);
3707
+ try std.testing.expect(std.mem.indexOf(u8, gitignore_text, "node_modules/") != null);
3708
+ }
3709
+
3710
+ test "writeDefaultApp --template zig-core emits the slim Zig scaffold at ts-core parity" {
3711
+ const destination = ".zig-cache/test-native-slim-template";
3712
+ try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .core = .zig });
3713
+
3108
3714
  const app_zon_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.zon");
3109
3715
  defer std.testing.allocator.free(app_zon_text);
3110
3716
  const main_zig_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "src/main.zig");
3111
3717
  defer std.testing.allocator.free(main_zig_text);
3718
+ const markup_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "src/app.native");
3719
+ defer std.testing.allocator.free(markup_text);
3112
3720
  const gitignore_text = try readTestFile(std.testing.allocator, std.testing.io, destination, ".gitignore");
3113
3721
  defer std.testing.allocator.free(gitignore_text);
3114
3722
  const readme_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "README.md");
@@ -3116,14 +3724,34 @@ test "writeDefaultApp emits a slim native scaffold by default" {
3116
3724
  const icon = try readTestFile(std.testing.allocator, std.testing.io, destination, "assets/icon.png");
3117
3725
  defer std.testing.allocator.free(icon);
3118
3726
 
3119
- // Zero-config: no build files, no editor config, no CI workflow.
3727
+ // Zero-config: no build files, no editor config, no CI workflow — and
3728
+ // none of the TS scaffold's editor surface: a Zig app carries no
3729
+ // package.json/tsconfig/node_modules (zero residue; the tree is the
3730
+ // only language marker).
3120
3731
  try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "build.zig"));
3121
3732
  try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "build.zig.zon"));
3122
3733
  try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, ".vscode/settings.json"));
3123
3734
  try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, ".github/workflows/ci.yml"));
3735
+ try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "package.json"));
3736
+ try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "tsconfig.json"));
3737
+ try std.testing.expectError(error.FileNotFound, readTestFile(std.testing.allocator, std.testing.io, destination, "node_modules/@native-sdk/core/package.json"));
3124
3738
 
3125
3739
  try std.testing.expect(std.mem.indexOf(u8, app_zon_text, "gpu_surface") != null);
3126
3740
  try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "native_sdk.UiApp(Model, Msg)") != null);
3741
+ // Feature parity with the ts-core starter: the same counter app with a
3742
+ // repeating fx timer (the Sub.timer equivalent), a journaled clock
3743
+ // read (the Cmd.now equivalent), the lint opt-out for the host-fired
3744
+ // arm, and a bindable single-model helper.
3745
+ try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "fx.startTimer(") != null);
3746
+ try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "fx.wallMs()") != null);
3747
+ try std.testing.expect(std.mem.indexOf(u8, main_zig_text, ".update_fx = update,") != null);
3748
+ try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "pub const view_unbound = .{\"tick\"};") != null);
3749
+ try std.testing.expect(std.mem.indexOf(u8, main_zig_text, "pub fn total(") != null);
3750
+ // The markup is the ts starter's view over the Zig core's own field
3751
+ // names, bound exactly as main.zig wrote them.
3752
+ try std.testing.expect(std.mem.indexOf(u8, markup_text, "{tick_count}") != null);
3753
+ try std.testing.expect(std.mem.indexOf(u8, markup_text, "{total}") != null);
3754
+ try std.testing.expect(std.mem.indexOf(u8, markup_text, "on-toggle=\"toggle_ticking\"") != null);
3127
3755
  // The generated + derived state is ignored wholesale.
3128
3756
  try std.testing.expect(std.mem.indexOf(u8, gitignore_text, ".native/") != null);
3129
3757
  try std.testing.expect(std.mem.indexOf(u8, gitignore_text, "zig-out/") != null);
@@ -3138,7 +3766,7 @@ test "writeDefaultApp emits a slim native scaffold by default" {
3138
3766
 
3139
3767
  test "writeDefaultApp emits native project files" {
3140
3768
  const destination = ".zig-cache/test-native-init-template";
3141
- try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full });
3769
+ try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full, .core = .zig });
3142
3770
 
3143
3771
  const app_zon_text = try readTestFile(std.testing.allocator, std.testing.io, destination, "app.zon");
3144
3772
  defer std.testing.allocator.free(app_zon_text);
@@ -3182,9 +3810,36 @@ test "writeDefaultApp emits native project files" {
3182
3810
  try std.testing.expect(std.mem.indexOf(u8, readme_text, "hot") != null or std.mem.indexOf(u8, readme_text, "Hot") != null);
3183
3811
  }
3184
3812
 
3813
+ test "writeDefaultApp --full ts-core emits a CI workflow with the node tier" {
3814
+ const destination = ".zig-cache/test-ts-ci-template";
3815
+ try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full });
3816
+
3817
+ const ci_yaml_text = try readTestFile(std.testing.allocator, std.testing.io, destination, ".github/workflows/ci.yml");
3818
+ defer std.testing.allocator.free(ci_yaml_text);
3819
+
3820
+ try expectBasicYaml(ci_yaml_text);
3821
+ // The Zig full template's structure: logic tests plus the Linux
3822
+ // automation smoke, no WebKitGTK for a native-rendered app.
3823
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, " test:") != null);
3824
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, " smoke:") != null);
3825
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "mlugg/setup-zig@v2") != null);
3826
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "zig build test -Dplatform=null") != null);
3827
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "libgtk-4-dev xvfb") != null);
3828
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "libwebkitgtk-6.0-dev") == null);
3829
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "xvfb-run -a ./zig-out/bin/my-app &") != null);
3830
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "git clone --depth 1 https://github.com/vercel-labs/native.git \"$NATIVE_SDK_PATH\"") != null);
3831
+ // Plus the node tier the TS build needs: node on PATH and the
3832
+ // transpiler's own install inside the fetched SDK's packages/core,
3833
+ // in BOTH jobs (each builds the app, so each transpiles the core).
3834
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "actions/setup-node@v4") != null);
3835
+ const npm_ci = "npm ci --prefix \"$NATIVE_SDK_PATH/packages/core\"";
3836
+ const first = std.mem.indexOf(u8, ci_yaml_text, npm_ci).?;
3837
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text[first + npm_ci.len ..], npm_ci) != null);
3838
+ }
3839
+
3185
3840
  test "writeDefaultApp emits a CI workflow for native apps" {
3186
3841
  const destination = ".zig-cache/test-native-ci-template";
3187
- try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full });
3842
+ try writeDefaultApp(std.testing.allocator, std.testing.io, destination, .{ .app_name = "My App", .framework_path = ".", .frontend = .native, .shape = .full, .core = .zig });
3188
3843
 
3189
3844
  const ci_yaml_text = try readTestFile(std.testing.allocator, std.testing.io, destination, ".github/workflows/ci.yml");
3190
3845
  defer std.testing.allocator.free(ci_yaml_text);
@@ -3206,7 +3861,7 @@ test "writeDefaultApp emits a CI workflow for native apps" {
3206
3861
  try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "zig build -Dplatform=linux -Dweb-engine=system -Dautomation=true") != null);
3207
3862
  try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "xvfb-run -a ./zig-out/bin/my-app &") != null);
3208
3863
  try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "automate wait") != null);
3209
- try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "automate assert 'gpu_nonblank=true' 'role=button name=\"Reset\"' 'count: 0'") != null);
3864
+ try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "automate assert 'gpu_nonblank=true' 'role=button name=\"Reset\"' 'total: 0'") != null);
3210
3865
  try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "automate screenshot main-canvas") != null);
3211
3866
  try std.testing.expect(std.mem.indexOf(u8, ci_yaml_text, "test -s .zig-cache/native-sdk-automation/screenshot-main-canvas.png") != null);
3212
3867
  // The framework fetch step reuses the build.zig.zon dependency path.