@native-sdk/cli 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/README.md +4 -4
  2. package/build.zig +52 -23
  3. package/package.json +10 -10
  4. package/packages/core/compile-surface/core.ts +16 -0
  5. package/packages/core/package-lock.json +2 -2
  6. package/packages/core/package.json +1 -1
  7. package/packages/core/sdk/core.d.ts +11 -0
  8. package/packages/core/sdk/core.ts +29 -2
  9. package/packages/core/sdk/events.d.ts +10 -0
  10. package/packages/core/sdk/events.ts +24 -4
  11. package/packages/core/src/checker.ts +1 -1
  12. package/packages/core/src/contract.ts +4 -1
  13. package/packages/core/src/devhost.ts +10 -1
  14. package/packages/core/src/diagnostics.ts +1 -1
  15. package/skill-data/core/SKILL.md +48 -20
  16. package/skill-data/core/references/app-model-runtime.md +2 -2
  17. package/skill-data/core/references/project-anatomy.md +22 -6
  18. package/skill-data/native-ui/SKILL.md +68 -27
  19. package/skill-data/ts-core/SKILL.md +13 -8
  20. package/skill-data/zig/SKILL.md +1 -1
  21. package/skills/native-sdk/SKILL.md +6 -5
  22. package/src/app_runner/app_assets.zig +138 -0
  23. package/src/app_runner/root.zig +2 -0
  24. package/src/app_runner/ts_core_main.zig +4 -2
  25. package/src/embed/tests.zig +3 -1
  26. package/src/primitives/canvas/events.zig +8 -0
  27. package/src/primitives/canvas/root.zig +2 -0
  28. package/src/primitives/canvas/test_support.zig +1 -0
  29. package/src/primitives/canvas/ui.zig +53 -8
  30. package/src/primitives/canvas/ui_markup.zig +1 -0
  31. package/src/primitives/canvas/ui_markup_compiled.zig +32 -3
  32. package/src/primitives/canvas/ui_markup_compiled_tests.zig +27 -0
  33. package/src/primitives/canvas/ui_markup_contract.zig +20 -3
  34. package/src/primitives/canvas/ui_markup_reflect.zig +41 -0
  35. package/src/primitives/canvas/ui_markup_view.zig +29 -3
  36. package/src/primitives/canvas/ui_markup_view_tests.zig +48 -1
  37. package/src/primitives/canvas/ui_schema.zig +5 -1
  38. package/src/primitives/canvas/ui_schema_tests.zig +3 -3
  39. package/src/primitives/canvas/ui_tests.zig +14 -0
  40. package/src/primitives/canvas/widget_access.zig +4 -3
  41. package/src/primitives/canvas/widget_invalidation.zig +11 -0
  42. package/src/primitives/canvas/widget_render.zig +106 -1
  43. package/src/primitives/canvas/widget_routing.zig +12 -7
  44. package/src/primitives/canvas/widget_runtime_tests.zig +172 -0
  45. package/src/primitives/canvas/widgets.zig +52 -0
  46. package/src/root.zig +1 -0
  47. package/src/runtime/automation_widget_dispatch.zig +19 -0
  48. package/src/runtime/canvas_limits.zig +5 -0
  49. package/src/runtime/canvas_widget_event_tests.zig +425 -8
  50. package/src/runtime/canvas_widget_events.zig +254 -7
  51. package/src/runtime/canvas_widget_state.zig +127 -1
  52. package/src/runtime/core.zig +6 -0
  53. package/src/runtime/effects.zig +27 -1
  54. package/src/runtime/effects_notification_tests.zig +65 -0
  55. package/src/runtime/gpu_surface_events.zig +60 -14
  56. package/src/runtime/tests.zig +1 -0
  57. package/src/runtime/ts_core_host.zig +16 -0
  58. package/src/runtime/ts_ui_app.zig +55 -2
  59. package/src/runtime/ui_app.zig +112 -0
  60. package/src/runtime/ui_app_tests.zig +356 -0
  61. package/src/runtime/view.zig +35 -0
  62. package/src/runtime/view_widget_tree.zig +12 -0
  63. package/src/tooling/package.zig +4 -4
  64. package/tools/corewire/core_abi.zig +1 -0
  65. package/tools/corewire/emit.zig +55 -8
  66. package/tools/corewire/emit_facade.zig +63 -2
  67. package/tools/corewire/emit_profile.zig +4 -1
  68. package/tools/corewire/sidecar.zig +36 -6
@@ -1,22 +1,26 @@
1
1
  ---
2
2
  name: core
3
- description: Core Native SDK guide for AI agents. Read this before explaining the Native SDK or changing a Native SDK app. Covers the mental model (native-rendered apps by default, WebView shells as a coexisting architecture), project structure, app.zon, App and Runtime patterns, frontend integration, web engines, JavaScript bridge commands, permissions, windows, WebViews, dialogs, packaging, debugging, testing, and when to load deeper references. For authoring native-rendered UI (Native markup .native views, Model/Msg/update, UiApp), load the native-ui skill. Use when the user asks what the Native SDK is, how to build or modify an app, how to package or debug it, or how to add native capabilities.
3
+ description: Core Native SDK guide for AI agents. Read this before explaining the Native SDK or changing a Native SDK app. Establishes TypeScript + Native markup as the default app-authoring path, routes default app work to the native-ui and ts-core skills, and covers the shared foundation: project structure, app.zon, lower-level App and Runtime patterns, frontend integration, web engines, JavaScript bridge commands, permissions, windows, WebViews, dialogs, packaging, debugging, and testing. Use when the user asks what the Native SDK is, how to build or modify an app, how to package or debug it, or how to add native capabilities.
4
4
  ---
5
5
 
6
6
  # Build Native SDK apps
7
7
 
8
- The Native SDK is a cross-platform native app toolkit inspired by the web. The default app (`native init`) is native-rendered: a declarative Native markup view (`.native`) plus Zig logic on the `UiApp` loop, drawn by Native SDK's own engine — **load the `native-ui` skill for everything about authoring those** (markup grammar, bindings, messages, testing, hot reload). This skill covers the shared foundation and the WebView-shell architecture: apps that render web frontends in a WebView (`native init --frontend next|vite|react|svelte|vue`). Both architectures share windows, policies, lifecycle, commands, and platform services, and one app can mix native-rendered surfaces and WebViews. WebView engines: platform WebView (WKWebView on macOS, WebKitGTK on Linux) or Chromium through CEF where supported.
8
+ The Native SDK is a cross-platform native app toolkit inspired by the web. The default app (`native init`) is native-rendered and authored as a declarative Native markup view (`src/app.native`) plus a TypeScript app core (`src/core.ts`). The core is checked and compiled ahead of time to native code; no JS runtime ships in the binary. **For default app implementation, load both the `native-ui` and `ts-core` skills.** Zig is the implementation language of the toolkit and a first-class app-core choice via `--template zig-core`, not the default app-authoring language.
9
9
 
10
- Agents should assume they do not know the Native SDK from general model knowledge. Read this skill first. For implementation work, run `native skills get core --full` so the referenced files are included in the CLI output.
10
+ This skill covers the shared foundation and lower-level architectures: apps that explicitly choose a Zig core, runtime extensions, and apps that render web frontends in a WebView (`native init --frontend next|vite|react|svelte|vue`). Native-rendered surfaces and WebViews share windows, policies, lifecycle, commands, and platform services, and one app can mix them. WebView engines are the platform WebView (WKWebView on macOS, WebKitGTK on Linux) or Chromium through CEF where supported.
11
+
12
+ Agents should assume they do not know the Native SDK from general model knowledge. Read this skill first. For ordinary app implementation, load `native-ui` and `ts-core`; for shared/runtime, WebView, packaging, or native-capability work, run `native skills get core --full` so the referenced files are included in the CLI output.
11
13
 
12
14
  ## Mental model
13
15
 
14
- - `App` describes the product: app state, name, WebView source, lifecycle callbacks, and optional bridge dispatcher.
16
+ - The default app has three files of truth: `src/core.ts` (`Model`, `Msg`, `update`), `src/app.native` (UI), and `app.zon` (manifest).
17
+ - Native markup binds model values and dispatches typed messages; only `update` changes state.
18
+ - The TypeScript core compiles to native code. Node is a build/check/dev tool, not an app runtime.
19
+ - `App` is the lower-level product/runtime interface used by generated wiring, Zig-core apps, WebView shells, and extensions.
15
20
  - `Runtime` owns the event loop, windows, bridge dispatch, security checks, automation, tracing, platform services, and window state.
16
21
  - `WebViewSource` tells the runtime what to load: inline HTML, a URL, or packaged assets from a local app origin.
17
22
  - `app.zon` is the app manifest: identity, icons, windows, frontend assets, web engine, permissions, bridge policy, security policy, and packaging inputs.
18
- - `src/runner.zig` is the generated runtime wiring. Edit it when adding runtime services, security policy, builtin bridge policy, tracing, automation, or platform setup.
19
- - `src/main.zig` is app behavior. Edit it when changing app state, source selection, lifecycle callbacks, or app-defined bridge handlers.
23
+ - `src/runner.zig` and `src/main.zig` appear only when an app explicitly owns lower-level Zig wiring (for example a `zig-core` app or a WebView shell). `--full` makes a TypeScript app own `build.zig` but still does not give it Zig app logic. Do not add Zig sources to a default TypeScript app merely because SDK examples contain them.
20
24
  - `frontend/` is normal web code. It talks to native Zig through `window.zero.invoke()` or builtin helpers when those are enabled.
21
25
 
22
26
  ## Task router
@@ -24,6 +28,8 @@ Agents should assume they do not know the Native SDK from general model knowledg
24
28
  These references are included by `native skills get core --full`. Use them when the task touches the topic:
25
29
 
26
30
  - Project creation, generated files, build steps: `references/project-anatomy.md`
31
+ - Default TypeScript core authoring, checker rules, effects, subscriptions, modules: `native skills get ts-core`
32
+ - Native markup, bindings, messages, hot reload, view testing: `native skills get native-ui`
27
33
  - `App`, `Runtime`, callbacks, embedding, tests: `references/app-model-runtime.md`
28
34
  - React/Vue/Svelte/Next/Vite, dev server, bundled assets: `references/frontend-assets.md`
29
35
  - App-defined bridge commands, builtin commands, permissions, windows, WebViews, dialogs: `references/bridge-security-native-capabilities.md`
@@ -37,19 +43,19 @@ Use the CLI for new apps:
37
43
 
38
44
  ```bash
39
45
  npm install -g @native-sdk/cli
40
- native init my_app --frontend next
46
+ native init my_app
41
47
  cd my_app
42
- zig build run
48
+ native dev
43
49
  ```
44
50
 
45
- Frontend choices are `next`, `vite`, `react`, `svelte`, and `vue`. The first `zig build run` installs frontend dependencies, builds the native shell, and opens a desktop window.
51
+ This creates `src/core.ts`, `src/app.native`, and `app.zon`; a native window opens with `native dev`. Use `native init my_app --template zig-core` only when the user chooses Zig. Frontend choices (`--frontend next|vite|react|svelte|vue`) are the separate WebView migration/integration path.
46
52
 
47
53
  ## Workflow for existing apps
48
54
 
49
55
  Before editing an existing Native SDK app:
50
56
 
51
- 1. Read `app.zon`, `src/main.zig`, `src/runner.zig`, and `build.zig`.
52
- 2. Identify whether the change is app metadata/policy, runtime wiring, app-native behavior, frontend behavior, packaging, or automation.
57
+ 1. Read `app.zon` and inspect `src/` before assuming a core language. Read `src/core.ts` + `src/app.native` for the default path; read `src/main.zig`, `src/runner.zig`, and `build.zig` only when they exist.
58
+ 2. Identify whether the app is TypeScript + Native markup (default), an explicitly chosen Zig core, or a WebView frontend, then identify the layer the change belongs to.
53
59
  3. Follow the generated code and examples in the repository instead of inventing a new app layout.
54
60
  4. Prefer exact security policy changes over broad allowances.
55
61
  5. Validate with the narrowest useful command.
@@ -57,14 +63,16 @@ Before editing an existing Native SDK app:
57
63
  Common file ownership:
58
64
 
59
65
  - `app.zon`: app identity, version, icons, windows, permissions, capabilities, bridge command policy, allowed origins, frontend dist/dev config, web engine, CEF config.
60
- - `src/main.zig`: `App` state, source selection, lifecycle callbacks, custom bridge handlers.
66
+ - `src/core.ts`: default app state and behavior — `Model`, `Msg`, `update`, pure helpers, `Cmd`, and `Sub`.
67
+ - `src/app.native`: default app UI — elements, layout, bindings, and message dispatch.
68
+ - `src/main.zig`: explicitly chosen Zig-core logic or lower-level `App` behavior, source selection, lifecycle callbacks, and custom bridge handlers.
61
69
  - `src/runner.zig`: `Runtime.init`, platform selection, security policy, builtin bridge policy, `js_window_api`, automation server, trace sinks, panic capture, window state store.
62
70
  - `build.zig`: build options, frontend build/dev/package steps, platform link setup, test steps.
63
71
  - `frontend/`: web app implementation, `window.zero` calls, dev/build config.
64
72
 
65
- ## Core app model
73
+ ## Lower-level WebView app model (advanced)
66
74
 
67
- The minimal Zig app returns `native_sdk.App` with `context`, `name`, and a WebView source:
75
+ This is not the default app-authoring path. A lower-level Zig/WebView shell returns `native_sdk.App` with `context`, `name`, and a WebView source:
68
76
 
69
77
  ```zig
70
78
  const App = struct {
@@ -183,7 +191,16 @@ Use signing and CEF options only when the product requires them.
183
191
 
184
192
  ## Development commands
185
193
 
186
- For iterative frontend work, use the managed dev server flow:
194
+ For a default TypeScript + Native markup app, use:
195
+
196
+ ```bash
197
+ native check
198
+ native dev
199
+ native dev --core
200
+ native test
201
+ ```
202
+
203
+ For iterative WebView-frontend work in an app that owns its build, use the managed dev server flow:
187
204
 
188
205
  ```bash
189
206
  zig build dev
@@ -213,7 +230,15 @@ Common bridge failure codes are `invalid_request`, `unknown_command`, `permissio
213
230
 
214
231
  ## Validate changes
215
232
 
216
- Useful commands:
233
+ Useful default-app commands:
234
+
235
+ ```bash
236
+ native check
237
+ native test
238
+ native build
239
+ ```
240
+
241
+ Useful SDK, Zig-core, and owned-build commands:
217
242
 
218
243
  ```bash
219
244
  zig build run
@@ -225,7 +250,7 @@ native doctor --manifest app.zon --strict
225
250
  zig build package
226
251
  ```
227
252
 
228
- Run BOTH `zig build` and `zig build test` before calling a change done: Zig's lazy analysis means code only tests reference (or only `main()` reference) can sit broken for weeks under the other command alone — tests never analyze `main`, so an API removed from std can keep "passing" until the app build finally touches it.
253
+ For an app that owns Zig code, run BOTH `zig build` and `zig build test` before calling a change done: Zig's lazy analysis means code only tests reference (or only `main()` reference) can sit broken under the other command alone. This Zig-specific requirement does not turn a default TypeScript app into a Zig app.
229
254
 
230
255
  The toolkit requires Zig 0.16.0. When a build fails with "no member named" errors on std APIs (`std.fs.cwd`, `ArrayList.init`, `std.io`, `GeneralPurposeAllocator`), the code was written against older Zig idioms — `native skills get zig` maps each such compile error to the 0.16 idiom as this SDK writes it.
231
256
 
@@ -236,11 +261,14 @@ zig build run -Dplatform=macos -Dautomation=true
236
261
  zig-out/bin/native automate snapshot
237
262
  ```
238
263
 
239
- When changing app behavior, add focused Zig tests when the code can run headlessly. Use automation-based tests only for WebView/runtime integration that requires a GUI-capable session.
264
+ When changing app behavior, keep tests in the app's existing authoring tier. TypeScript cores can run in the node dev loop and through generated full-loop tests; Zig-core logic uses focused Zig tests. Use automation-based tests for live window/runtime integration.
240
265
 
241
266
  ## Examples to inspect
242
267
 
243
- - `examples/hello`: smallest inline HTML app.
268
+ - `examples/ai-chat-ts`: a substantial app authored entirely in TypeScript + Native markup, with fetch effects and modules.
269
+ - `examples/soundboard-ts`: TypeScript + Native markup port of the full music-player showcase.
270
+ - `examples/system-monitor-ts`: TypeScript + Native markup app using spawn effects, timers, and tables.
271
+ - `examples/hello`: smallest lower-level inline HTML/WebView app.
244
272
  - `examples/webview`: bridge and WebView runtime example.
245
273
  - `examples/browser`: layered WebView/browser-style example.
246
274
  - `examples/next`: Next.js with production assets.
@@ -249,4 +277,4 @@ When changing app behavior, add focused Zig tests when the code can run headless
249
277
 
250
278
  ## When answering users
251
279
 
252
- Explain the Native SDK in concrete terms: Zig owns native app lifecycle and security; web UI renders in a WebView; the bridge is opt-in and policy controlled; `app.zon` is the manifest; framework frontend development uses a dev server in development and bundled assets in production. If asked to implement, read the app files first and make the smallest change in the correct layer.
280
+ Lead with the primary authoring story: applications are TypeScript cores plus Native markup by default, compiled to a small native binary with no JS runtime. Describe Zig as the toolkit implementation language and an explicit app-core/extension choice. Describe WebViews as a coexisting integration path for existing web content, not the starting point for a fresh app. If asked to implement, read the app files first, preserve the existing core language, and make the smallest change in the correct layer.
@@ -1,6 +1,6 @@
1
- # App Model and Runtime
1
+ # Lower-level App and Runtime
2
2
 
3
- Use this when editing `src/main.zig`, `src/runner.zig`, lifecycle behavior, runtime setup, or tests.
3
+ This is the advanced Zig/runtime layer underneath the default TypeScript + Native markup app. Use it when an existing project owns `src/main.zig` or `src/runner.zig`, or when the task explicitly requires lifecycle behavior, custom runtime setup, embedding, or WebView sources. Do not add this layer for ordinary `src/core.ts` app behavior.
4
4
 
5
5
  ## `App`
6
6
 
@@ -4,13 +4,17 @@ Use this when creating, orienting in, or restructuring a Native SDK app.
4
4
 
5
5
  ## Generated project files
6
6
 
7
- A zero-config app ships no build files at all — just `app.zon` + `src/` (+ `assets/`); the `native dev|test|build` verbs synthesize the build graph into `.native/build/` (gitignored). `build.zig`/`build.zig.zon` appear only in apps that own their build (`native eject`, the `--full` scaffold, or an expanded example):
7
+ A default zero-config app ships no build files at all. Its authored files are `app.zon`, `src/core.ts`, and `src/app.native` (+ `assets/`). `native check` validates the TypeScript core, markup, and manifest without generating a build graph; `native dev|test|build` compile the app to native code and synthesize the build graph into `.native/build/` (gitignored). `build.zig`/`build.zig.zon` appear only in apps that own their build (`native eject`, the `--full` scaffold, or an expanded example). A Zig core is an explicit alternative created with `--template zig-core`, not something to infer from the SDK's implementation or older examples.
8
+
9
+ Files by path:
8
10
 
9
11
  - `build.zig`: Zig build graph. Expanded scaffolds expose platform selection, trace mode, debug overlay, automation, JS bridge, web engine overrides, frontend install/build/dev steps, tests, and package steps.
10
12
  - `build.zig.zon`: Zig package manifest and dependency declaration.
11
13
  - `app.zon`: app manifest read by CLI/build/package/doctor tooling.
12
- - `src/main.zig`: app state, `app()` method, source resolver, optional bridge dispatcher, lifecycle callbacks.
13
- - `src/runner.zig`: platform and runtime setup: native backend, trace sinks, panic capture, log paths, state store, security policy, builtin bridge policy, automation.
14
+ - `src/core.ts`: the default app core — `Model`, `Msg`, `update`, pure helpers, effects (`Cmd`), and subscriptions (`Sub`).
15
+ - `src/app.native`: the default app view — elements, layout, bindings, and typed message dispatch.
16
+ - `src/main.zig`: present for an explicitly selected Zig core or lower-level WebView/runtime app; app state, `app()` method, source resolver, optional bridge dispatcher, lifecycle callbacks.
17
+ - `src/runner.zig`: present when the app owns lower-level platform/runtime setup: native backend, trace sinks, panic capture, log paths, state store, security policy, builtin bridge policy, automation.
14
18
  - `assets/`: icons and other package resources.
15
19
  - `frontend/`: framework app when using Next, Vite, React, Svelte, or Vue.
16
20
 
@@ -78,7 +82,17 @@ Important manifest fields:
78
82
 
79
83
  ## Build steps to know
80
84
 
81
- Common generated steps:
85
+ Common zero-config steps:
86
+
87
+ ```bash
88
+ native check
89
+ native dev
90
+ native test
91
+ native build
92
+ native package --target macos
93
+ ```
94
+
95
+ Equivalent/common owned-build steps:
82
96
 
83
97
  ```bash
84
98
  zig build run
@@ -101,8 +115,10 @@ zig build test-package-cef-layout -Dplatform=macos
101
115
  ## Layering rule
102
116
 
103
117
  - If changing app identity, packaging inputs, permissions, origins, windows, frontend dist/dev paths, or web engine, update `app.zon`.
118
+ - If changing default app state, messages, transitions, effects, subscriptions, or derived bindings, update `src/core.ts` and follow the `ts-core` skill.
119
+ - If changing the default app UI, update `src/app.native` and follow the `native-ui` skill.
104
120
  - If changing runtime services, platform setup, automation, logging, security wiring, or builtin bridge policy, update `src/runner.zig`.
105
- - If changing native business behavior, lifecycle callbacks, bridge handlers, or source selection, update `src/main.zig`.
121
+ - If an existing lower-level/Zig app changes native lifecycle callbacks, bridge handlers, source selection, or Zig-core behavior, update its `src/main.zig`.
106
122
  - If changing UI, routes, CSS, or web calls, update `frontend/`.
107
123
 
108
- Do not put package metadata in Zig app state unless the generated project already does that. Do not bypass `app.zon` policy for convenience.
124
+ Do not add `src/main.zig`, `src/runner.zig`, or an owned build merely to implement ordinary behavior in a default TypeScript app. Do not put package metadata in app state or bypass `app.zon` policy for convenience.
@@ -1,22 +1,27 @@
1
1
  ---
2
2
  name: native-ui
3
- description: Authoring guide for native-rendered Native SDK apps - declarative Native markup (.native) views plus Zig logic on the UiApp loop. Use when building or modifying native UI (widgets, layout, bindings, messages), writing .native files, wiring Model/Msg/update, testing markup views, or verifying a native app through the automation harness.
3
+ description: Authoring guide for the Native markup (.native) view tier of native-rendered Native SDK apps. TypeScript cores are the default and use this skill together with ts-core; Zig cores are an explicit alternative and this guide labels their lower-level UiApp recipes. Use when building or modifying native UI (widgets, layout, bindings, messages), writing .native files, wiring views to Model/Msg/update, testing markup views, or verifying a native app through the automation harness.
4
4
  ---
5
5
 
6
- # Author native UI with markup + Zig
6
+ # Author native UI with Native markup
7
7
 
8
- A native-rendered Native SDK app is a markup view plus Zig logic:
8
+ A native-rendered Native SDK app is a markup view plus an app core. The primary authoring path is:
9
9
 
10
- - `src/<view>.native` — the entire UI: elements, layout, bindings, message dispatch.
11
- - `src/main.zig` — `Model` (plain struct), `Msg` (tagged union), `update(model, msg)`, and a `main` that hands them to `native_sdk.UiApp(Model, Msg)`.
10
+ - `src/app.native` — the entire UI: elements, layout, bindings, message dispatch.
11
+ - `src/core.ts` — `Model`, the discriminated `Msg` union, `update(model, msg)`, effects, subscriptions, and derived binding helpers.
12
+ - `app.zon` — identity, windows, assets, permissions, and policy.
12
13
 
13
- The markup compiles to the same widget tree a hand-written `canvas.Ui(Msg)` builder view would produce: identical structural widget ids, identical typed handler table. Markup can never mutate state — it binds values and dispatches messages; all logic lives in Zig.
14
+ The TypeScript core is checked and compiled ahead of time to native code; no JS runtime ships in the binary. Load `native skills get ts-core` beside this skill for every default app implementation. A Zig core (`src/main.zig`) is first-class when explicitly selected with `native init --template zig-core`; the Zig-only wiring, builder, and runtime-extension recipes below are labeled so they are not mistaken for the default.
15
+
16
+ The markup compiles to the same widget tree a hand-written `canvas.Ui(Msg)` builder view would produce: identical structural widget ids, identical typed handler table. Markup can never mutate state — it binds values and dispatches messages; all logic lives in the app core, whichever core language the existing tree uses.
14
17
 
15
18
  Editors highlight `.native` markup well in HTML mode — the default scaffold writes no editor config, so add `.vscode/settings.json` with `"files.associations": {"*.native": "html"}` yourself, or scaffold with `native init --full`, which writes it.
16
19
 
17
- Start a new app with `native init` (zero-config: app.zon + src + assets, the CLI generates the build graph), or copy `examples/habits/` (smallest): change the name/id in app.zon and `assets/` copies verbatim — there are no build files to edit. The `native dev|test|build` verbs drive any app directory shaped this way.
20
+ Start a new app with `native init` (zero-config: `app.zon` + `src/core.ts` + `src/app.native` + assets; the CLI generates the build graph). Use `examples/ai-chat-ts`, `examples/soundboard-ts`, and `examples/system-monitor-ts` as substantial TypeScript references. The `native check|dev|test|build` verbs drive any app directory shaped this way.
21
+
22
+ ## App wiring (Zig cores and extensions only)
18
23
 
19
- ## App wiring
24
+ A default TypeScript app writes none of this: generated wiring connects `src/core.ts`, `src/app.native`, and `app.zon`. Use the following only when the existing app has a Zig core or the task explicitly requires owned runtime wiring.
20
25
 
21
26
  ```zig
22
27
  const HabitsApp = native_sdk.UiApp(Model, Msg);
@@ -394,12 +399,16 @@ The function library is CLOSED (17 functions; adding one is a toolkit change —
394
399
 
395
400
  Bounds (taught one past): 256 bytes, 64 terms, 16 nesting levels per expression. Where expressions are allowed: text interpolation, attribute values, `if` tests, template args at use sites. Path-only by design: message tags/payloads, `for each` iterables, import paths. Both engines evaluate through ONE shared evaluator — results are bit-for-bit identical, floats included — and `native markup check` validates syntax, bounds, function names (with did-you-mean), arity, and literal types without needing the model.
396
401
 
397
- Anything stateful or beyond the grammar is a Zig model function you bind to (`each="visible"`, `{summaryLine}`).
402
+ Anything stateful or beyond the grammar is a core helper you bind to (`each="visible"`, `{summaryLine}`): an exported single-model function in the default TypeScript core, or a public model method in a Zig core.
398
403
 
399
- Where the line sits between inline arithmetic and a model fn: inline expression arithmetic is sanctioned for ONE-OFF presentation-level derivation — `{percent(done / total)}` on the single readout that shows it is exactly what expressions are for. The moment a derivation is REUSED in a second binding, deserves a NAME, or carries meaning the model owns (a threshold, a rule, a policy), it belongs in a named model function: `{completionRate}` reads at the binding site, tests in Zig, and changes in one place.
404
+ Where the line sits between inline arithmetic and a core helper: inline expression arithmetic is sanctioned for ONE-OFF presentation-level derivation — `{percent(done / total)}` on the single readout that shows it is exactly what expressions are for. The moment a derivation is REUSED in a second binding, deserves a NAME, or carries meaning the model owns (a threshold, a rule, a policy), it belongs in a named helper: `{completionRate}` reads at the binding site, tests in the core's language, and changes in one place.
400
405
 
401
406
  ## Binding resolution rules
402
407
 
408
+ In a default TypeScript core, Model fields bind by their authored names and exported single-model helpers become derived bindings. Exported iterable helpers supply `for each`; item record fields continue the path. Keep TypeScript spelling exact (`tickCount` binds as `{tickCount}`), and see the `ts-core` skill for supported signatures, bytes/text, import graphs, and checker rules.
409
+
410
+ The following details are for a Zig core, where bindings resolve public Model fields and methods:
411
+
403
412
  A path like `{h.streak}` resolves left to right, starting from the model or a `for` variable:
404
413
 
405
414
  - everything bindable is declared INSIDE the Model struct: fields, and `pub fn` METHODS in the struct body. A file-scope `pub fn visibleRows(model: *const Model, ...)` written NEXT TO the struct is invisible to bindings and `for each` — a model-free `native markup check` still passes (grammar-only), and the view then fails at test/run time with "each does not name an iterable"; with a fresh model contract (refreshed by `native test`), `native check` catches it instantly with a did-you-mean. If a binding or `each` cannot find your fn, first check it lives inside `pub const Model = struct { ... }`
@@ -414,7 +423,7 @@ Bindings are zero-argument. A parameterized query (cards of column X) becomes on
414
423
 
415
424
  ## Derive, don't store
416
425
 
417
- The model stores source-of-truth state ONLY: the raw items, the current filter, the draft text. Anything the view shows that is computable from those — counts, sums, filtered views, formatted strings — is a pub method the markup binds to, never a model field. A cached derivable must be re-maintained in every `update` arm and goes stale the moment one is missed; a derived method cannot.
426
+ The model stores source-of-truth state ONLY: the raw items, the current filter, the draft text. Anything the view shows that is computable from those — counts, sums, filtered views, formatted strings — is a derived core helper the markup binds to, never a model field. A cached derivable must be re-maintained in every `update` arm and goes stale the moment one is missed; a derived helper cannot. In the default TypeScript core, export a single-model function; the `ts-core` skill covers the permitted return shapes and byte formatting. The examples below show the equivalent Zig-core methods.
418
427
 
419
428
  ```zig
420
429
  // WRONG: derived state cached in the model, maintained by hand in update()
@@ -475,7 +484,7 @@ For `<if test>`, prefer an explicit boolean predicate method over numeric truthi
475
484
 
476
485
  ## Messages
477
486
 
478
- `on-press`, `on-double-press`, `on-toggle`, `on-change`, `on-submit` (enter in a text field; primary+enter in a textarea, where enter inserts a newline), `on-dismiss` (dismissible surfaces: dialog, drawer, sheet, dropdown-menu — dispatched when Escape or a click outside dismisses the surface, so the model owns the close), `on-hold` (press-and-hold, see the Pickers section), and `on-hover-enter`/`on-hover-leave` (the pointer-hover containment pair, below) take `tag` or `tag:{payload}`. The tag must be a variant of your `Msg` union; payload bindings coerce to the variant's payload type: integers, floats, enums (from tag names), `[]const u8`, bool. `on-input` is special: name a `Msg` variant whose payload is `canvas.TextInputEvent` and the runtime delivers each text edit in it. `on-scroll` (the `scroll` element only) is the same shape: name a `Msg` variant whose payload is `canvas.ScrollState` and the runtime delivers the post-scroll state — `offset`, `viewport_extent`, `content_extent`, `maxOffset()` — after every user scroll (wheel, kinetic momentum steps, keyboard, accessibility). In Zig views the constructors are `Ui.inputMsg(.tag)` / `Ui.scrollMsg(.tag)` on `on_input` / `on_scroll`. `on-reach-end` (the `scroll` element only; `on_reach_end` in Zig views, any scroll container including the windowed virtual list) is a plain Msg dispatched when a user scroll comes within one viewport of the content end — the infinite-fetch signal, fired once per approach with hysteresis (re-arms past 1.5 viewports, which appending a batch causes by growing the extent). A programmatic jump to the end fires once and NEVER re-arms while the offset stays near the end — re-arming needs a post-scroll observation at least 1.5 viewports from it.
487
+ `on-press`, `on-double-press`, `on-toggle`, `on-change`, `on-submit` (enter in a text field; primary+enter in a textarea, where enter inserts a newline), `on-dismiss` (dismissible surfaces: dialog, drawer, sheet, dropdown-menu — dispatched when Escape or a click outside dismisses the surface, so the model owns the close), `on-hold` (press-and-hold, see the Pickers section), and `on-hover-enter`/`on-hover-leave` (the pointer-hover containment pair, below) take `tag` or `tag:{payload}`. The tag must be an arm of your `Msg` union; payload bindings coerce to the arm's payload type. In TypeScript, an arm is `{ readonly kind: "tag"; readonly field: Type }`; in Zig it is a tagged-union variant. `on-input` is special: name an arm carrying `TextInputEvent` from `@native-sdk/core/text` in TypeScript or `canvas.TextInputEvent` in Zig. `on-scroll` (the `scroll` element only) similarly carries `ScrollState` from `@native-sdk/core/events` in TypeScript or `canvas.ScrollState` in Zig. In Zig builder views the constructors are `Ui.inputMsg(.tag)` / `Ui.scrollMsg(.tag)` on `on_input` / `on_scroll`. `on-reach-end` (the `scroll` element only; `on_reach_end` in Zig views, any scroll container including the windowed virtual list) is a plain Msg dispatched when a user scroll comes within one viewport of the content end — the infinite-fetch signal, fired once per approach with hysteresis (re-arms past 1.5 viewports, which appending a batch causes by growing the extent). A programmatic jump to the end fires once and NEVER re-arms while the offset stays near the end — re-arming needs a post-scroll observation at least 1.5 viewports from it.
479
488
 
480
489
  Scroll offsets follow the same mirror discipline as text: the Msg carries the offset the runtime ALREADY applied, so store it in the model and echo it back through the scroll's `value` — the echoed source value equals the runtime offset, which the scroll reconcile rule treats as "unchanged", so rebuilds never stomp live scrolling. `on-scroll` is how long content pages or lazy-loads: keep a bounded window in the model and slide it from `offset` (near-end when `offset + viewport_extent` approaches `content_extent`).
481
490
 
@@ -487,7 +496,7 @@ Presses follow ONE rule: a click lands on the nearest pressable widget under the
487
496
 
488
497
  ### Keys: quiet list rows and the app-level fallback
489
498
 
490
- Keyboard focus has two registers. RING focus is the keyboard contract: Tab/Shift+Tab walk the focusables and draw the visible ring, and a ring-focused widget owns its keys in full — activation, group arrows, Home/End. QUIET focus is bookkeeping: a pointer press records which widget the user last touched, with no ring drawn (editable text kinds are the exception — a caret is a visible promise, so they show it however focus arrives). A key event resolves top to bottom, the focused widget always outranking the app: (1) the focused widget's bound handler; (2) structural consume — any key on an editable text kind (typing stays typing, checked by widget KIND, so a focused search field blocks app shortcuts without knowing they exist) and any key the widget's kind maps as a control intent; (3) only an unclaimed key_down reaches `Options.on_key`, the app-level fallback (a target-less event — nothing focused — skips straight there). The fallback is a plain function from the key event to an optional Msg:
499
+ Keyboard focus has two registers. RING focus is the keyboard contract: Tab/Shift+Tab walk the focusables and draw the visible ring, and a ring-focused widget owns its keys in full — activation, group arrows, Home/End. QUIET focus is bookkeeping: a pointer press records which widget the user last touched, with no ring drawn (editable text kinds are the exception — a caret is a visible promise, so they show it however focus arrives). A key event resolves top to bottom, the focused widget always outranking the app: (1) the focused widget's bound handler; (2) structural consume — any key on an editable text kind (typing stays typing, checked by widget KIND, so a focused search field blocks app shortcuts without knowing they exist) and any key the widget's kind maps as a control intent; (3) only an unclaimed key_down reaches the app-level fallback (a target-less event — nothing focused — skips straight there). In a default TypeScript core, export `keyMsg(key): Msg | null`; the host wires it automatically and the `ts-core` skill specifies the `KeyEvent` shape. In a Zig core, the equivalent is `Options.on_key`, a plain function from the key event to an optional Msg:
491
500
 
492
501
  ```zig
493
502
  // options: .on_key = onKey,
@@ -510,6 +519,8 @@ The model applies every edit event and is the source of truth; the runtime keeps
510
519
  <text-field text="{draft}" placeholder="New task…" on-input="draft_edit" on-submit="add" grow="1" />
511
520
  ```
512
521
 
522
+ In a default TypeScript core, use the byte-splice engine from `@native-sdk/core/text` (`applyTextInputEvent` over `TextEditState`); the `ts-core` skill has the complete copy/paste/selection/IME-safe pattern. The equivalent Zig-core buffer is:
523
+
513
524
  ```zig
514
525
  draft_buffer: canvas.TextBuffer(64) = .{}, // model field: text + selection + composition
515
526
  pub fn draft(model: *const Model) []const u8 { // the fn the markup's text= binds
@@ -527,7 +538,9 @@ The runtime owns cmd/ctrl+C/X/V in editable text: copy writes the current select
527
538
 
528
539
  Static text is selectable too: click-drag inside one `text` leaf or `paragraph` (markdown bodies included) selects with a highlight, cmd/ctrl+C copies it, and pressing anywhere else clears it. Selection and pressing coexist inside pressable rows — dragging selects (and presses nothing), a plain click collapses the selection and lands on the row's `on-press`. Selection is per-widget by design — there is no document model ordering text across widgets, so a drag cannot span two paragraphs (copy per paragraph). The selection survives rebuilds while that widget's text bytes are unchanged, and shows up in semantics/automation snapshots as `selection=a..b` on the widget line. Clipboard access from `update` is `fx.writeClipboard` / `fx.readClipboard` on the effects channel (see Effects) — never a `pbcopy` spawn; `runtime.readClipboard(&buffer)` / `runtime.writeClipboard(text)` remain for code that holds the runtime.
529
540
 
530
- ## Effects: subprocesses and HTTP from update
541
+ ## Effects in Zig cores: subprocesses and HTTP from update
542
+
543
+ In the default TypeScript core, effects are immutable `Cmd` values returned from `update`, and recurring work is declared with `Sub`; use the `ts-core` skill for the complete vocabulary and testing loop. The imperative effects channel below is the Zig-core equivalent.
531
544
 
532
545
  `update` can take a third parameter — the effects channel — by declaring `.update_fx` instead of `.update` (existing two-argument apps are untouched; set exactly one):
533
546
 
@@ -812,7 +825,7 @@ The `.wake` platform event is how live platforms marshal worker completions onto
812
825
  >
813
826
  > After feeding, drain with `try harness.runtime.dispatchPlatformEvent(app, .wake);` — results become Msgs through the same path live platforms use.
814
827
 
815
- ## Secondary windows: model-declared (`windows_fn` + `window_view`)
828
+ ## Secondary windows in Zig cores: model-declared (`windows_fn` + `window_view`)
816
829
 
817
830
  Windows are model state, like an anchored surface's open flag. `Options.windows_fn` returns the descriptors that should exist RIGHT NOW (presence is visibility — no `visible` flag; the platform window channel has no hide); `Options.window_view` builds each declared window's whole canvas tree by window label. The runtime reconciles after every dispatch: create the newly declared, close the no-longer-declared, rebuild every open window's view from the same model.
818
831
 
@@ -845,17 +858,35 @@ Rules that matter:
845
858
  - **Settings windows open the standard way**: the app-menu Settings item and its primary+comma shortcut (an app.zon `.shortcuts` entry mapped in `on_command`), never an in-window settings button. Ship them fixed-size (`.resizable = false`) at exactly the content's box, title them "Settings", and let changes apply live through the shared model — no Apply/OK row, no copy explaining the window.
846
859
  - Tests: after the open Msg, deliver the new window's `gpu_surface_frame` (its window id from `runtime.listWindows`) to install its tree; simulate a user close by dispatching `.window_frame_changed` with `open = false`. See `examples/system-monitor` (settings shortcut -> settings window).
847
860
 
848
- ## Hidden titlebar: `titlebar = "hidden_inset"`/`"hidden_inset_tall"` + `window-drag` + `on_chrome`
861
+ ## Hidden titlebar in both core tiers: `titlebar` + `window-drag` + the chrome channel
849
862
 
850
863
  The modern editor-app shape — content under a transparent titlebar, the app's header as the working titlebar. Two heights: `hidden_inset` keeps the compact band (~28pt, traffic lights hug the top), `hidden_inset_tall` switches to the unified-toolbar band (~52pt, macOS vertically centers the traffic lights — the tall unified-toolbar look). Pick tall when the header replacing the titlebar is toolbar-height, so the lights center against it. Three parts, all declared:
851
864
 
852
- 1. **app.zon**: `.titlebar = "hidden_inset"` or `"hidden_inset_tall"` on the shell window (and the matching `.titlebar = .hidden_inset`/`.hidden_inset_tall` on the `ShellWindow` in main.zig). The first shell window's declaration threads through the STARTUP window create, so the main window's chrome is right from the first frame; `zig build validate` checks the value.
865
+ 1. **app.zon**: `.titlebar = "hidden_inset"` or `"hidden_inset_tall"` on the shell window. That is the whole declaration in a default TypeScript app. An owned Zig shell also sets the matching `.titlebar = .hidden_inset`/`.hidden_inset_tall` on its `ShellWindow`. The first shell window's declaration threads through the STARTUP window create, so the main window's chrome is right from the first frame; `native validate` checks the manifest value.
853
866
  2. **The header row** gets `window-drag="true"`: its background (and plain text/icons inside) moves the window; buttons inside stay buttons; double-click zooms (macOS honors the user's titlebar double-click preference).
854
- 3. **`Options.on_chrome`** (`fn (chrome: platform.WindowChrome) ?Msg`) delivers the chrome overlay geometry — `chrome.insets`: titlebar band height on top (compact or tall), traffic-light extent on the leading edge; `chrome.buttons`: the traffic-light cluster's frame in content coordinates (top-left origin), the vertical truth for centering. All-zero in fullscreen, on standard chrome, and on other platforms. It fires BEFORE the first view build and on changes; store the geometry in the model, pad the header with a leading `<spacer width="{chrome_leading}" />`, and with the tall band match the header's height to `insets.top` (floored at its natural height) so `cross="center"` puts its controls on the lights' centerline.
867
+ 3. **The core's chrome channel** delivers the overlay geometry — `insets`: titlebar band height on top and traffic-light extent on the leading edge; `buttons`: the traffic-light cluster's frame in content coordinates (top-left origin), the vertical truth for centering. All-zero in fullscreen, on standard chrome, and on other platforms. It fires BEFORE the first view build and on changes. Store the geometry in model fields, pad the header with a leading spacer, and with the tall band match the header's height to `insets.top` (floored at its natural height) so `cross="center"` puts its controls on the lights' centerline.
868
+
869
+ In a default TypeScript core, import `ChromeInsets`/`ChromeButtons` from `@native-sdk/core/events`, add the matching Msg arm, and export the channel name from `src/core.ts`:
870
+
871
+ ```ts
872
+ import { type ChromeButtons, type ChromeInsets } from "@native-sdk/core/events";
873
+
874
+ export type Msg = /* ... */ | {
875
+ readonly kind: "chrome_changed";
876
+ readonly insets: ChromeInsets;
877
+ readonly buttons: ChromeButtons;
878
+ readonly tabsProjected: boolean;
879
+ };
880
+ export const chromeMsg = "chrome_changed";
881
+ ```
882
+
883
+ Handle that arm by storing `msg.insets.left` and `Math.max(headerNaturalHeight, msg.insets.top)` in fields such as `chromeLeading`/`headerHeight`; markup binds those exact TypeScript spellings (`<spacer width="{chromeLeading}" />`). `examples/system-monitor-ts` is the complete reference. In a Zig core, the equivalent hook is `Options.on_chrome: fn (platform.WindowChrome) ?Msg`, with snake-case bindings such as `{chrome_leading}` when the Zig model uses those names.
855
884
 
856
885
  macOS-first like `resizable = false`: GTK/Win32 keep standard chrome and the whole channel is harmless there. Full retrofit: `examples/markdown-viewer` (tall band; toolbar row is the drag region and tracks the band height). Tests: the null platform records `startWindowDrag` calls (`window_drag_starts`), per-window `window_titlebar`, and serves settable `window_chrome` (insets + buttons frame).
857
886
 
858
- ## Time: wall clock + monotonic, with a testable seam
887
+ ## Time in Zig cores: wall clock + monotonic, with a testable seam
888
+
889
+ Default TypeScript cores use journaled `Cmd.now` results and `Sub.timer` subscriptions; see the `ts-core` skill. The clock facade below is for Zig cores and lower-level runtime code.
859
890
 
860
891
  Zig 0.16 puts `std.time.milliTimestamp` behind `std.Io`, which `update` never sees — do NOT call `clock_gettime` yourself. The facade owns the clocks:
861
892
 
@@ -880,7 +911,19 @@ test_clock.setWallMs(1_700_000_000_000); // NTP-style wall jump, monotonic unto
880
911
  ```
881
912
 
882
913
  Wall answers "what time is it?" (jumps with OS clock adjustments); monotonic answers "how long did it take?". Don't subtract wall timestamps for durations.
883
- ## Images: runtime-registered pixels + the avatar pattern
914
+
915
+ ## Images in both core tiers: load/register, then bind the id
916
+
917
+ In a default TypeScript app, static images ship through `app.zon`'s `.assets.images` table and are registered before the first frame. Runtime images use effects-as-data: return `Cmd.imageLoad(id, { path?, url?, cachePath?, expectedBytes? }, { event })` from `update`, and store the numeric id in the model only when the result arm reports `state === "loaded"`. `Cmd.imageCancel(id)` ends an in-flight load, and `Cmd.imageUnregister(id)` releases a loaded registry slot. The `ts-core` skill specifies the result record and limits; the [Dynamic Images guide](https://native-sdk.dev/dynamic-images) is the complete TypeScript + Zig example.
918
+
919
+ The view binds that model-owned id in either tier; `0` is the no-image sentinel and keeps the fallback visible:
920
+
921
+ ```html
922
+ <image image="{cover}" width="120" height="80" label="Cover art" />
923
+ <avatar image="{avatar}" label="Octocat">OC</avatar>
924
+ ```
925
+
926
+ ### Zig cores and extensions: direct registration
884
927
 
885
928
  Image pixels are runtime-registered resources keyed by a caller-chosen `ImageId` (`u64` in the model, effect-key style; 0 = no image). The framework bundles NO codecs — encoded bytes decode through the platform (CGImageSource / gdk-pixbuf / WIC) via `PlatformServices.decode_image_fn`. Registration lives on the effects channel (synchronous calls, not effects — no Msg follows):
886
929
 
@@ -901,11 +944,7 @@ ui.avatar(.{ .image = model.avatar_image, .semantics = .{ .label = "Octocat" } }
901
944
  ui.image(.{ .image = model.chart_image, .width = 120, .height = 80, .semantics = .{ .label = "Chart" } }),
902
945
  ```
903
946
 
904
- ```html
905
- <!-- Markup avatars bind the same model id: one {binding} to the u64 ImageId
906
- (a field or pub fn — never a literal); 0 renders the initials fallback. -->
907
- <avatar image="{avatar_image}" label="Octocat">OC</avatar>
908
- ```
947
+ Markup binds the same model id through a field or derived helper, never a literal. A Zig core commonly spells that field `{avatar_image}`; a TypeScript core binds its authored spelling exactly, such as `{avatar}`.
909
948
 
910
949
  Rules:
911
950
 
@@ -1124,9 +1163,11 @@ Tests that touch files or clocks get their `Io` from `std.testing.io`. The full
1124
1163
 
1125
1164
  `native markup check src/view.native` — instant grammar/structure validation with `file:line:column` errors, including the font-coverage tofu guard: literal text with a codepoint outside the bundled face (⌘, ✓, ⑂, dingbats, CJK) is a teaching error naming the character, because it renders as a tofu box on the reference/screenshot and mobile paths — register a font that covers it (`UiApp.Options.fonts`) and bind the text from the model (the guard skips `{bindings}`), or use a vector icon (`icon=` / `<icon name>`) or plain words. Dynamic strings get the same lesson as a Debug-build `zero_canvas_ui` diagnostic when the view builds. The accessibility lint rides the same pass: unnamed interactive controls and role misuse are errors, unnamed images and redundant labels are warnings (`--strict` promotes).
1126
1165
 
1127
- The model side checks at check time too: the model-contract step (refreshed by `native test`, or run directly as `zig build model-contract` in an app that owns its build) reflects Model/Msg into `zig-out/model-contract.zon`, and `native check` (or `markup check` run in the app directory) then verifies every binding path, iterable, `key` field, message tag, payload type, and expression type against the app's real surface — did-you-mean over your actual field names, and type errors naming the field's Zig type. It also WARNS on model state and Msg tags no view uses; opt update-only names out with `pub const view_unbound = .{ "next_id" };` on Model or Msg (`--strict` turns the warnings into failures) — state consumed only by a Zig-BUILT view needs `view_unbound` too, because the markup checker cannot see Zig view reads. A stale artifact degrades to grammar-only checking with a loud note ("model contract: not yet built - bindings checked structurally only; run `native test` to enable typed checks"); binding paths and message tags are always re-enforced when the app builds (and on hot reload).
1166
+ The model side checks at check time too: the model-contract step (refreshed by `native test`, or run directly as `zig build model-contract` in an app that owns its build) reflects Model/Msg into `zig-out/model-contract.zon`, and `native check` (or `markup check` run in the app directory) then verifies every binding path, iterable, `key` field, message tag, payload type, and expression type against the app's real surface — did-you-mean over your actual field names, and type errors naming the core's type. It also WARNS on model state and Msg tags no view uses; a TypeScript core exports `viewUnbound = ["name"] as const`, while a Zig core declares `pub const view_unbound = .{ "name" };` (`--strict` turns the warnings into failures). State consumed only by a Zig-built view needs `view_unbound` too, because the markup checker cannot see Zig view reads. A stale artifact degrades to grammar-only checking with a loud note ("model contract: not yet built - bindings checked structurally only; run `native test` to enable typed checks"); binding paths and message tags are always re-enforced when the app builds (and on hot reload).
1167
+
1168
+ ## Testing pattern (Zig cores)
1128
1169
 
1129
- ## Testing pattern
1170
+ For the default TypeScript path, test the pure core under node (`native dev --core`) and through `native test`; use the `ts-core` skill for scripts, virtual time, effect transcripts, and generated full-loop coverage. The direct widget-tree pattern below is for Zig cores and toolkit work.
1130
1171
 
1131
1172
  Unit tests exercise the real dispatch path — no GUI needed:
1132
1173
 
@@ -1,11 +1,11 @@
1
1
  ---
2
2
  name: ts-core
3
- description: Authoring guide for TypeScript app cores - Model, Msg, update, and the pure functions they call, written in the closed app-core subset, checked by the @native-sdk/core frontend, and compiled ahead-of-time to native code by the external core compiler. Use when writing or modifying a src/core.ts app core, fixing subset checker errors (NS1001-NS1060), or deciding how to express state, messages, text (bytes and the byte-text string methods), text input, continuous controls (sliders, scroll), effects (Cmd), subscriptions (Sub), the host-event wiring channels (frameMsg, keyMsg, appearanceMsg, chromeMsg, envMsgs, app.zon assets), derived values, the view_unbound lint opt-out, local mutation of owned arrays, or how to split a core into modules under src/ (relative imports, namespace imports, @native-sdk/core/text, @native-sdk/core/events).
3
+ description: Authoring guide for the primary Native SDK app-logic path: TypeScript app cores - Model, Msg, update, and the pure functions they call, written in the closed app-core subset, checked by the @native-sdk/core frontend, and compiled ahead-of-time to native code by the external core compiler. Use for new apps unless the user explicitly chose Zig, when writing or modifying a src/core.ts app core, fixing subset checker errors (NS1001-NS1060), or deciding how to express state, messages, text (bytes and the byte-text string methods), text input, continuous controls (sliders, scroll), effects (Cmd), subscriptions (Sub), the host-event wiring channels (frameMsg, keyMsg, pinchMsg, dropMsg, appearanceMsg, chromeMsg, envMsgs, app.zon assets), derived values, the view_unbound lint opt-out, local mutation of owned arrays, or how to split a core into modules under src/ (relative imports, namespace imports, @native-sdk/core/text, @native-sdk/core/events).
4
4
  ---
5
5
 
6
6
  # Author app cores in the TypeScript subset
7
7
 
8
- An app core is the logic tier of a Native SDK app: `Model` (the app state), `Msg` (a discriminated union of everything that can happen), `update(model, msg)` (the one pure transition function), and the pure helpers they call. You write it as a TypeScript module rooted at `src/core.ts` - splitting into more modules under `src/` when it grows (see "Splitting a core into modules") - and the build checks the whole import graph with the `@native-sdk/core` frontend and compiles it to native code with the external core compiler. No JS engine ships in the binary — the program either passes the subset checker and compiles to native, or you get a teaching error naming the rule, the fix, and the reason. The same file is executable TypeScript: it typechecks with stock tsc and runs unmodified under node, so you can poke behavior with plain node scripts before the native build.
8
+ TypeScript is the primary app-authoring language. An app core is the logic tier of a Native SDK app: `Model` (the app state), `Msg` (a discriminated union of everything that can happen), `update(model, msg)` (the one pure transition function), and the pure helpers they call. You write it as a TypeScript module rooted at `src/core.ts` - splitting into more modules under `src/` when it grows (see "Splitting a core into modules") - and the build checks the whole import graph with the `@native-sdk/core` frontend and compiles it to native code with the external core compiler. No JS engine ships in the binary — the program either passes the subset checker and compiles to native, or you get a teaching error naming the rule, the fix, and the reason. The same file is executable TypeScript: it typechecks with stock tsc and runs unmodified under node, so you can poke behavior with plain node scripts before the native build.
9
9
 
10
10
  A whole TS app is three files of truth and zero Zig: `src/core.ts` (this guide; plus any modules it imports under `src/`), `src/app.native` (the markup view over the core's model), and `app.zon` (windows, identity, permissions). `native init` scaffolds exactly that; the build detects `src/core.ts` in the tree (never a flag or config — a tree with both `src/core.ts` and `src/main.zig` is a teaching error) and generates the wiring outside the app. The loop:
11
11
 
@@ -133,13 +133,14 @@ The command set (Cmd wire format v3):
133
133
 
134
134
  ### The named engine ops
135
135
 
136
- These map directly onto the host's effect engine — files, HTTP, the clipboard, one-shot timers. Routing follows the `Cmd.request` rules (inline `{ key?, ok, err }`, string-literal arm names, arm shapes checked by tsc and taught by NS1027), with one difference from `request`: each op's `ok` arm has the op's OWN result shape. Keys follow the one keyed-effect rule everywhere: issuing an op whose key is already in flight REPLACES the old one (the superseded op's result is dropped — no message), and `Cmd.cancel(key)` drops it silently. Every `err` arm carries exactly one `Uint8Array` field and receives a machine-readable reason. Paths, URLs, and bodies are bytes (`asciiBytes` for literals); dynamic values the engine refuses at runtime surface through the `err` arm, while compile-time-knowable bound violations stop the build (NS1030).
136
+ These map directly onto the host's effect engine — files, HTTP, the clipboard, notifications, one-shot timers. Routed operations follow the `Cmd.request` rules (inline `{ key?, ok, err }`, string-literal arm names, arm shapes checked by tsc and taught by NS1027), with one difference from `request`: each op's `ok` arm has the op's OWN result shape. Keys follow the one keyed-effect rule everywhere: issuing a keyed op whose key is already in flight REPLACES the old one (the superseded op's result is dropped — no message), and `Cmd.cancel(key)` drops it silently. Every `err` arm carries exactly one `Uint8Array` field and receives a machine-readable reason; fire-and-forget writes and notifications have no routing arms. Paths, URLs, and bodies are bytes (`asciiBytes` for literals); dynamic values the engine refuses at runtime surface through the `err` arm, while compile-time-knowable bounds for routed operations stop the build (NS1030). Fire-and-forget operations fail closed under the host's validation instead.
137
137
 
138
138
  - `Cmd.readFile(path, { key?, ok, err })` — read a whole file. `ok` arm: one `Uint8Array` field with the content. `err` reasons: `not_found`, `io_failed`, `truncated` (the file exceeds the engine's 1 MiB read bound — a cut file never passes as whole), `rejected`. Paths are at most 1024 bytes.
139
139
  - `Cmd.writeFile(path, bytes, { key?, ok, err })` — write a whole file (parent directories created, an existing file replaced whole; at most 1 MiB). `ok` arm: NO payload fields (`{ kind: "wrote" }`) — a successful write has nothing to report. `err` reasons: `io_failed`, `rejected`.
140
140
  - `Cmd.fetch({ url, method?, headers?, body?, timeoutMs? }, { key?, ok, err })` — a buffered HTTP(S) exchange. `ok` arm: exactly two fields, one `number` and one `Uint8Array` (`{ kind: "fetched", status: number, body: Uint8Array }`) — matched by type, so the names are yours. The status is the real HTTP status: a 404 is still `ok` (an HTTP-level error is a delivered response). `err` reasons: `connect_failed`, `tls_failed`, `protocol_failed`, `timed_out`, `rejected`, and `truncated` (the body exceeded the engine's 256 KiB buffered bound — never delivered silently cut). The spec is an inline object: `url` bytes (≤ 2 KiB), `method` one of `"GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD"` (default GET), `headers` an inline flat record — names are compile-time ASCII, values are string literals OR runtime bytes (`{ authorization: bearerToken(model.apiKey), "content-type": "application/json" }` — how a launch-supplied key rides an `Authorization` header; ≤ 8 headers, ≤ 1 KiB total, NS1029/NS1030), `body` bytes (≤ 64 KiB), `timeoutMs` a positive integer literal (engine default when omitted). Buffered only — no streaming responses in v1.
141
141
  - `Cmd.clipboardWrite(bytes)` — put bytes on the system clipboard, fire-and-forget: there is no routing, and a refused or over-bound write is dropped by design.
142
142
  - `Cmd.clipboardRead({ key?, ok, err })` — read the clipboard. `ok` arm: one `Uint8Array` field with the text. `err` reasons: `failed` (no clipboard service, over-bound content, pasteboard error), `rejected`.
143
+ - `Cmd.showNotification({ title, subtitle?, body? })` — request a desktop notification, fire-and-forget: `title` is required bytes (1–128), `subtitle` optional bytes (up to 128), and `body` optional bytes (up to 1024). The host validates all fields before entering the platform service; invalid or unavailable requests fail closed, and Focus / Do Not Disturb and user settings remain authoritative after acceptance. Fake execution and session replay never display one.
143
144
  - `Cmd.delay(key, ms, "fired")` — a keyed ONE-SHOT timer: dispatches the named arm once, `ms` from now, with the fire time (ms) as its single number payload (the same arm shape `Cmd.now` and `Sub.timer` target). Re-issuing a live delay key re-arms it from now — that is the debounce discipline (`Cmd.delay("autosave", 800, "save_now")` on every keystroke, one fire after the pause). `Cmd.cancel(key)` drops it silently. The interval is 1ms to one year; a literal outside that stops the build (NS1030).
144
145
 
145
146
  One honesty note on `Cmd.persist()`: it compiles and encodes, but no shipping host implements the persist verb yet, so the checker teaches NS1028 as a WARNING (never failing the build). Persist real state with `Cmd.writeFile` and load it back with `Cmd.readFile` from `initialModel`'s boot command — the pattern every real app uses.
@@ -216,8 +217,8 @@ One caveat for node-side pokes: the build resolves the `@native-sdk/core*` speci
216
217
  - **`src/` is the boundary**: `../` escapes and absolute paths are taught (NS1034); bare npm specifiers are taught (NS1035 - vendor the code under `src/` or make the import `import type`). Only `@native-sdk/core` (the intrinsic Cmd/Sub/asciiBytes surface) and the SDK library modules below carry runtime meaning from outside.
217
218
  - **Everything module-level is importable**: interfaces, literal-union aliases, discriminated unions, module `const` numbers and tables, and helper functions all cross files (renamed imports and `import * as ns` namespace aliases both work — the alias is dot-syntax over the same flat namespace, never a value of its own). Export lists and value re-exports work too: `export { helper, doneCount as remaining }` binds names over existing declarations, and `export { parsePs } from "./parsers.ts"` forwards another module's export by name (a renamed binding emits as a flat-namespace alias). Type names and EXPORTED value names must be unique across the core's files (NS1038 - declare once, import where used; renamed exports claim their new names in the same namespace); colliding PRIVATE helpers are fine (the compile uniques them per module).
218
219
  - **No runtime import cycles** (NS1036). `import type` back-edges are legal and idiomatic: a helper module type-imports `Model` from `./core.ts` while `core.ts` runtime-imports the helpers - that is the expected shape, not a smell.
219
- - **The entry contract (NS1014)**: `update`, `initialModel`, `subscriptions`, the wiring channels (`commandMsg`/`keyMsg`/`frameMsg`/`appearanceMsg`/`chromeMsg`/`envMsgs`), and `viewUnbound` are DECLARED in `core.ts` and exported under their own names (`export` on the declaration or an un-renamed `export { update }` list entry — a rename or a re-export from an imported module cannot bind an entry point) - imports may FEED them, never replace them. The markup binding surface is also entry-only: an exported single-Model-parameter helper binds (`{doneCount}`) only when it is DECLARED in `core.ts` — export lists participate under their exported names (`export { taskTotal as taskCount }` binds `{taskCount}`), but a re-export of an imported helper does not bind (under node the app's module object is the entry's exports, so it would bind natively but not exist under node). Imported modules export cross-module API for update and the entry helpers to call.
220
- - **SDK library modules**: `@native-sdk/core/text` ships the byte-splice text engine - `applyTextInputEvent(state, event, capacity)` / `clampedInsertEvent` over `TextEditState` (the full caret/word/selection/IME reducer for markup text controls), plus `containsIgnoreCase`, `orderIgnoreCase`, and `trimAsciiSpaces`. `@native-sdk/core/events` ships the canonical event record types (`TextInputEvent` re-exported, `ScrollState`, `FrameEvent`, `KeyEvent`, `ColorScheme`/`AppearanceEvent`, `ChromeInsets`/`ChromeButtons`/`ChromeEvent`, `AudioState`/`AudioEvent`) so no core re-types the vocabulary. Unlike `@native-sdk/core` (intrinsic, never compiled into the core) these are ordinary subset TypeScript, compiled INTO your core when imported and absent when not. Under node they resolve like the core module itself. One namespace rule to know (NS1038): module-scope names are unique across the whole import graph, so a core that imports an SDK event type deletes its own in-file mirror of that name.
220
+ - **The entry contract (NS1014)**: `update`, `initialModel`, `subscriptions`, the wiring channels (`commandMsg`/`keyMsg`/`frameMsg`/`pinchMsg`/`dropMsg`/`appearanceMsg`/`chromeMsg`/`envMsgs`), and `viewUnbound` are DECLARED in `core.ts` and exported under their own names (`export` on the declaration or an un-renamed `export { update }` list entry — a rename or a re-export from an imported module cannot bind an entry point) - imports may FEED them, never replace them. The markup binding surface is also entry-only: an exported single-Model-parameter helper binds (`{doneCount}`) only when it is DECLARED in `core.ts` — export lists participate under their exported names (`export { taskTotal as taskCount }` binds `{taskCount}`), but a re-export of an imported helper does not bind (under node the app's module object is the entry's exports, so it would bind natively but not exist under node). Imported modules export cross-module API for update and the entry helpers to call.
221
+ - **SDK library modules**: `@native-sdk/core/text` ships the byte-splice text engine - `applyTextInputEvent(state, event, capacity)` / `clampedInsertEvent` over `TextEditState` (the full caret/word/selection/IME reducer for markup text controls), plus `containsIgnoreCase`, `orderIgnoreCase`, and `trimAsciiSpaces`. `@native-sdk/core/events` ships the canonical event record types (`TextInputEvent` re-exported, `ScrollState`, `FrameEvent`, `KeyEvent`, `PinchEvent`, `FileDropEvent`, `ColorScheme`/`AppearanceEvent`, `ChromeInsets`/`ChromeButtons`/`ChromeEvent`, `AudioState`/`AudioEvent`) so no core re-types the vocabulary. Unlike `@native-sdk/core` (intrinsic, never compiled into the core) these are ordinary subset TypeScript, compiled INTO your core when imported and absent when not. Under node they resolve like the core module itself. One namespace rule to know (NS1038): module-scope names are unique across the whole import graph, so a core that imports an SDK event type deletes its own in-file mirror of that name.
221
222
 
222
223
  The reference splits are `examples/soundboard-ts` (core.ts + library.ts + player.ts + the SDK text engine), `examples/system-monitor-ts` (core.ts + parsers.ts + table.ts + the SDK text engine), and `examples/ai-chat-ts` (core.ts + api.ts — the JSON-over-bytes wire-format reference: request encoding and a targeted parse walk that returns `null` on anything malformed) in the SDK repo.
223
224
 
@@ -308,13 +309,17 @@ export type Msg = /* ... */ | { readonly kind: "library_scrolled"; readonly scro
308
309
  <scroll value="{libraryScrollTop}" on-scroll="library_scrolled"> ... </scroll>
309
310
  ```
310
311
 
312
+ - **Drag (`on-drag`, the live insertion event):** write a bound constructor such as `<row global-key="{card.id}" on-drag="card_dragged:{card.id}">`. Its Msg arm must be exactly `{ kind: "card_dragged"; sourceId: number; phase: number; x: number; y: number; viewWidth: number; viewHeight: number }`. Markup fills `sourceId`; the runtime fills view-local geometry and `phase` (`0` change, `1` end, `2` cancel). The renderer lifts the source appearance under the pointer at full opacity and leaves its in-flow rendering blank. For precise reordering, keep committed data unchanged during change and have derived array helpers move the same globally keyed source record to the candidate slot. That hidden row is the ONE reserved card-sized space: it starts at the source and moves to the candidate instead of duplicating. Keyed draggable neighbors ease between candidate poses; commit the array order on end and clear the candidate on cancel. A plain Escape during the drag is consumed and dispatches phase 2; the floating item continues from its pointer position into the committed slot (or back on cancel), and reduced-motion appearances snap the reflow.
313
+
311
314
  ## The host-event wiring channels
312
315
 
313
- The generated wiring detects each channel from an export (export exists → wired; a wrong shape is a taught NS1033). Event records are matched by field name, STRUCTURALLY: import them from `@native-sdk/core/events` (`FrameEvent`, `KeyEvent`, `ColorScheme`, `ChromeInsets`/`ChromeButtons`) or declare the same shapes in your core — both emit as your module's types and match identically. The `appearanceMsg`/`chromeMsg` arms themselves stay inline union members (`kind` plus the event's fields — the subset has no intersection arms); the SDK's `AppearanceEvent`/`ChromeEvent` records are those arms' canonical payload shapes, importable for helper signatures.
316
+ The generated wiring detects each channel from an export (export exists → wired; a wrong shape is a taught NS1033). Event records are matched by field name, STRUCTURALLY: import them from `@native-sdk/core/events` (`FrameEvent`, `KeyEvent`, `PinchEvent`, `FileDropEvent`, `ColorScheme`, `ChromeInsets`/`ChromeButtons`) or declare the same shapes in your core — both emit as your module's types and match identically. The `appearanceMsg`/`chromeMsg` arms themselves stay inline union members (`kind` plus the event's fields — the subset has no intersection arms); the SDK's `AppearanceEvent`/`ChromeEvent` records are those arms' canonical payload shapes, importable for helper signatures.
314
317
 
315
318
  - **`commandMsg(name: string): Msg | null`** — menus, shortcuts, and chrome tabs, by command id (string equality works on `string` values).
316
319
  - **`frameMsg(model: Model, frame: FrameEvent): Msg | null`** — presented frames. `FrameEvent` is exactly `{ width, height, timestampMs, intervalMs }` numbers (canvas points; fractional milliseconds). Return null for frames that change nothing — the idle law holds exactly when an idle app dispatches nothing (a frame arm that always returns a Msg would spin the loop at full frame rate). The installing frame is excluded; the first PRESENTED frame corrects any seeded value.
317
320
  - **`keyMsg(key: KeyEvent): Msg | null`** — the app-level key FALLBACK (a focused widget's own keys and editable text always win first). `KeyEvent` is exactly `{ key: string; shift: boolean; control: boolean; alt: boolean; super: boolean }`; the key NAME arrives lowercased (`key.key === "space"`).
321
+ - **`pinchMsg(pinch: PinchEvent): Msg | null`** — the view-global trackpad pinch channel. `PinchEvent` carries `windowId`, `label`, begin/change/end `phase`, multiplicative `scale` delta, and the view-local `x`/`y` anchor.
322
+ - **`dropMsg(drop: FileDropEvent): Msg | null`** — native file drops after widget routing. `FileDropEvent` is exactly `{ windowId; viewLabel; point; paths }`: `point` is `{ x; y } | null`, and `paths` is `readonly Uint8Array[]` so arbitrary UTF-8 filesystem names remain byte text. Return null to ignore the drop or map it to any ordinary Msg.
318
323
  - **`export const appearanceMsg = "<arm>"`** — system appearance changes dispatch the named arm, a record of exactly `{ colorScheme: ColorScheme; reduceMotion: boolean; highContrast: boolean }` where `ColorScheme` is a NAMED `"light" | "dark"` alias (routing is data: a string-literal arm name, the effects rule applied to the app shell).
319
324
  - **`export const chromeMsg = "<arm>"`** — window-chrome geometry (the hidden-titlebar channel), a record of exactly `{ insets: { top; right; bottom; left }; buttons: { x; y; width; height }; tabsProjected: boolean }` (numbers/boolean). Delivered before the first view build and again on changes.
320
325
  - **`export const envMsgs = [{ env: "NAME", msg: "<arm>" }] as const`** — each named environment variable present at launch dispatches its value through the arm (exactly one `Uint8Array` field, `BytesKind` — annotate with `readonly EnvMsg<Msg>[]` from the SDK for tsc checking) as one journaled Msg right after the boot command. The core never reads the environment (NS1005), and neither does replay: the deliveries are journaled at record time and fed back from the journal, so a recording replays byte-identically even when the variables are unset or changed at replay launch.
@@ -356,7 +361,7 @@ Every diagnostic carries one of these IDs plus the fix and the why. Write to the
356
361
  - **NS1031 exported model helpers join the model's binding surface.** An exported single-Model-parameter helper becomes a Model declaration markup binds (`doneCount` → `{doneCount}`); two members with one binding name would be ambiguous — rename one.
357
362
  - **NS1032 viewUnbound names update-only model state.** `export const viewUnbound = [...] as const` entries must be string literals naming Model fields, exported model helpers, or Msg kinds — by their TypeScript spellings (`"nextId"`); anything else would silence nothing and hide a typo.
358
363
  - **NS1030 effect arguments respect the engine's limits.** A compile-time-knowable value outside an engine bound (a path literal over 1024 bytes, a URL literal over 2 KiB, more than 8 headers, a header block over 1 KiB, a delay literal outside 1ms..one year) stops the build instead of shipping a guaranteed runtime rejection. Dynamic values stay the engine's to validate — they surface through the `err` arm.
359
- - **NS1033 wiring channel exports match their host event shapes.** `frameMsg`/`keyMsg` take their exact event records and return `Msg | null`; `appearanceMsg`/`chromeMsg` are string literals naming arms with those channels' record shapes; `envMsgs` entries carry `env` and a one-`Uint8Array`-field `msg` arm. The generated wiring builds these host events structurally from your declarations, so a wrong shape is taught here instead of surfacing as a Zig error inside generated code.
364
+ - **NS1033 wiring channel exports match their host event shapes.** `frameMsg`/`keyMsg`/`pinchMsg`/`dropMsg` take their exact event records and return `Msg | null`; `appearanceMsg`/`chromeMsg` are string literals naming arms with those channels' record shapes; `envMsgs` entries carry `env` and a one-`Uint8Array`-field `msg` arm. The generated wiring builds these host events structurally from your declarations, so a wrong shape is taught here instead of surfacing as a Zig error inside generated code.
360
365
  - **NS1034 core imports stay inside src/.** `../` escapes and absolute paths are rejected: the entry module's directory is the core's whole world - the build ships exactly that tree.
361
366
  - **NS1035 npm packages do not run inside a core.** No JS engine ships in the binary; vendor the logic under `src/` or make the import type-only.
362
367
  - **NS1036 core modules do not import in a cycle.** Runtime cycles only work through JS live-binding indirection; hoist shared declarations, or make the back-edge `import type` (which is exempt and idiomatic).
@@ -481,7 +486,7 @@ var app = Adapter.init(allocator, .{ .audio_cache_dir = resolved_cache_dir }, .{
481
486
  });
482
487
  ```
483
488
 
484
- - `update`/`update_fx`/`init_fx` belong to the adapter (it runs your `initialModel`, `update`, and `subscriptions` through the effect bridge), and the adapter wires `on_command`/`on_key`/`on_appearance`/`on_chrome`/`on_frame` from the core's channel exports automatically (a wiring that also sets one of those seams is a teaching panic). Everything else is ordinary wiring: `tokens_fn`/`windows_fn` derive from `*const core.Model`, and `CoreOptions` carries the adapter-owned knobs (`audio_cache_dir`, `boot_images`, `env_values`).
489
+ - `update`/`update_fx`/`init_fx` belong to the adapter (it runs your `initialModel`, `update`, and `subscriptions` through the effect bridge), and the adapter wires `on_command`/`on_key`/`on_pinch`/`on_drop`/`on_appearance`/`on_chrome`/`on_frame` from the core's channel exports automatically (a wiring that also sets one of those seams is a teaching panic). Everything else is ordinary wiring: `tokens_fn`/`windows_fn` derive from `*const core.Model`, and `CoreOptions` carries the adapter-owned knobs (`audio_cache_dir`, `boot_images`, `env_values`).
485
490
  - Markup binds your model's field names EXACTLY as you wrote them: `nextId` binds as `{nextId}` (the core's model keeps the TS spellings). Record arrays iterate with `<for each="tasks" as="t" key="id">` and items bind their fields (`{t.title}`); optional scalars gate with `<if test="{selected}">` (null is falsy); string-literal unions bind as their member name (`{filter}` renders `all` — compare against a quoted literal, `selected="{sortKey == 'cpu'}"`); exported single-model helpers bind as derived values (`{doneCount}`) and slice-returning ones drive `for each`. Markup `<chart>` series bind number arrays too — `<series kind="bar" values="{cpuSpark}" />` over a field or helper returning `readonly number[]` (f64, narrowed per sample into the chart pipeline); pad a filling window's leading gap with `NaN` samples, which draw nothing.
486
491
  - `Options.sync` does not exist for TS apps (a committed model cannot be mutated in place): keep continuous controls model-driven — bind the widget's value and echo `on-change`/`on-scroll` Msgs back into the model.
487
492
  - One live app per core module per process: two apps over the SAME core would share one committed root — and a process carries ONE compiled core (the archive owns a fixed-prefix C ABI symbol set).
@@ -38,7 +38,7 @@ pub fn main(init: std.process.Init) !void {
38
38
  }
39
39
  ```
40
40
 
41
- The CLI's own entry point is the live reference: `tools/native-sdk/main.zig`. Generated apps already have this shape — `main(init: std.process.Init)` passes `init` through to `runner.runWithOptions(app, options, init)` and `init.io` to the markup hot-reload watcher (see any `examples/*/src/main.zig`). `std.heap.page_allocator` still exists for allocations that live for the whole process. Library code that cannot take an `Init` builds its own `Io`: `var threaded = std.Io.Threaded.init(allocator, .{});` then `threaded.io()` (`src/platform/macos/root.zig`).
41
+ The CLI's own entry point is the live reference: `tools/native-sdk/main.zig`. Generated **Zig-core** apps have this shape — `main(init: std.process.Init)` passes `init` through to `runner.runWithOptions(app, options, init)` and `init.io` to the markup hot-reload watcher (see the older Zig-core examples' `src/main.zig`). Default TypeScript apps have no authored Zig entry point. `std.heap.page_allocator` still exists for allocations that live for the whole process. Library code that cannot take an `Init` builds its own `Io`: `var threaded = std.Io.Threaded.init(allocator, .{});` then `threaded.io()` (`src/platform/macos/root.zig`).
42
42
 
43
43
  ## error: struct 'fs' has no member named 'cwd' — file IO moved to `std.Io.Dir`
44
44