@native-sdk/cli 0.8.0 → 0.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- package/build.zig +49 -23
- package/package.json +10 -10
- package/packages/core/compile-surface/core.ts +16 -0
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/sdk/core.d.ts +11 -0
- package/packages/core/sdk/core.ts +29 -2
- package/packages/core/sdk/events.d.ts +10 -0
- package/packages/core/sdk/events.ts +24 -4
- package/packages/core/src/checker.ts +1 -1
- package/packages/core/src/contract.ts +4 -1
- package/packages/core/src/devhost.ts +10 -1
- package/packages/core/src/diagnostics.ts +1 -1
- package/skill-data/core/SKILL.md +48 -20
- package/skill-data/core/references/app-model-runtime.md +2 -2
- package/skill-data/core/references/project-anatomy.md +22 -6
- package/skill-data/native-ui/SKILL.md +71 -29
- package/skill-data/ts-core/SKILL.md +13 -8
- package/skill-data/zig/SKILL.md +1 -1
- package/skills/native-sdk/SKILL.md +6 -5
- package/src/app_runner/ts_core_main.zig +2 -1
- package/src/embed/tests.zig +3 -1
- package/src/platform/macos/appkit_host.h +4 -4
- package/src/platform/macos/appkit_host.m +24 -4
- package/src/platform/macos/cef_host.mm +22 -6
- package/src/platform/macos/root.zig +2 -2
- package/src/primitives/canvas/events.zig +8 -0
- package/src/primitives/canvas/markdown.zig +2010 -57
- package/src/primitives/canvas/markdown_hostile_tests.zig +40 -0
- package/src/primitives/canvas/markdown_tests.zig +778 -3
- package/src/primitives/canvas/root.zig +2 -0
- package/src/primitives/canvas/test_support.zig +1 -0
- package/src/primitives/canvas/ui.zig +53 -8
- package/src/primitives/canvas/ui_markup.zig +10 -1
- package/src/primitives/canvas/ui_markup_compiled.zig +61 -3
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +27 -0
- package/src/primitives/canvas/ui_markup_contract.zig +31 -3
- package/src/primitives/canvas/ui_markup_reflect.zig +41 -0
- package/src/primitives/canvas/ui_markup_view.zig +49 -3
- package/src/primitives/canvas/ui_markup_view_tests.zig +61 -2
- package/src/primitives/canvas/ui_schema.zig +8 -1
- package/src/primitives/canvas/ui_schema_tests.zig +7 -6
- package/src/primitives/canvas/ui_tests.zig +14 -0
- package/src/primitives/canvas/widget_access.zig +4 -3
- package/src/primitives/canvas/widget_invalidation.zig +11 -0
- package/src/primitives/canvas/widget_layout.zig +26 -3
- package/src/primitives/canvas/widget_metrics.zig +21 -3
- package/src/primitives/canvas/widget_render.zig +87 -1
- package/src/primitives/canvas/widget_routing.zig +12 -7
- package/src/primitives/canvas/widget_runtime_tests.zig +132 -0
- package/src/primitives/canvas/widgets.zig +40 -0
- package/src/root.zig +1 -0
- package/src/runtime/automation_widget_dispatch.zig +19 -0
- package/src/runtime/canvas_limits.zig +5 -0
- package/src/runtime/canvas_widget_event_tests.zig +424 -8
- package/src/runtime/canvas_widget_events.zig +254 -7
- package/src/runtime/canvas_widget_state.zig +123 -1
- package/src/runtime/core.zig +6 -0
- package/src/runtime/effects.zig +36 -1
- package/src/runtime/effects_fetch_tests.zig +21 -0
- package/src/runtime/effects_notification_tests.zig +65 -0
- package/src/runtime/gpu_surface_events.zig +60 -14
- package/src/runtime/tests.zig +1 -0
- package/src/runtime/ts_core_host.zig +16 -0
- package/src/runtime/ts_ui_app.zig +55 -2
- package/src/runtime/ui_app.zig +112 -0
- package/src/runtime/ui_app_tests.zig +356 -0
- package/src/runtime/view.zig +35 -0
- package/src/runtime/view_widget_tree.zig +12 -0
- package/tools/corewire/core_abi.zig +1 -0
- package/tools/corewire/emit.zig +55 -8
- package/tools/corewire/emit_facade.zig +63 -2
- package/tools/corewire/emit_profile.zig +4 -1
- package/tools/corewire/sidecar.zig +36 -6
package/skill-data/core/SKILL.md
CHANGED
|
@@ -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.
|
|
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
|
|
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
|
-
|
|
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
|
-
-
|
|
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`
|
|
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
|
|
46
|
+
native init my_app
|
|
41
47
|
cd my_app
|
|
42
|
-
|
|
48
|
+
native dev
|
|
43
49
|
```
|
|
44
50
|
|
|
45
|
-
|
|
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
|
|
52
|
-
2. Identify whether the
|
|
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/
|
|
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
|
-
##
|
|
73
|
+
## Lower-level WebView app model (advanced)
|
|
66
74
|
|
|
67
|
-
|
|
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
|
|
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
|
-
|
|
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,
|
|
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/
|
|
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
|
-
|
|
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
|
|
1
|
+
# Lower-level App and Runtime
|
|
2
2
|
|
|
3
|
-
Use
|
|
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
|
|
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/
|
|
13
|
-
- `src/
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
6
|
+
# Author native UI with Native markup
|
|
7
7
|
|
|
8
|
-
A native-rendered Native SDK app is a markup view plus
|
|
8
|
+
A native-rendered Native SDK app is a markup view plus an app core. The primary authoring path is:
|
|
9
9
|
|
|
10
|
-
- `src
|
|
11
|
-
- `src/
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
|
@@ -991,15 +1030,16 @@ Bare source-bound highlighted content shared with Markdown fences:
|
|
|
991
1030
|
A leaf element that renders a markdown string (the GFM subset below) as ordinary widgets, wiring `native_sdk.markdown` for you — both engines implement it identically:
|
|
992
1031
|
|
|
993
1032
|
```html
|
|
994
|
-
<markdown source="{issue_body}" on-link="open_url" on-details="toggle_details" details-expanded="{details_expanded}" />
|
|
1033
|
+
<markdown source="{issue_body}" images="{markdownImages}" on-link="open_url" on-details="toggle_details" details-expanded="{details_expanded}" />
|
|
995
1034
|
```
|
|
996
1035
|
|
|
997
1036
|
- `source` (required): one `{binding}` producing the markdown text — a `[]const u8` field, zero-arg fn, or arena-taking fn (compose the document into the build arena at view time).
|
|
1037
|
+
- `images` (optional): one `{binding}` producing `[]const canvas.markdown.ResolvedImage`. Give `canvas.markdown.collectImageSources` caller-owned `[]canvas.markdown.CollectedImageSource` storage, consume each canonical source through `value()` while that storage is alive, load it through `fx.loadImage`, and retain the source, successful id, and decoded dimensions in the model. Return mappings from a model or arena-taking fn. The view never performs I/O; missing mappings keep the safe alt-text fallback.
|
|
998
1038
|
- `on-link` (optional): a BARE Msg tag — no `:{payload}` — whose payload is the pressed link URL; declare `open_url: []const u8` in `Msg`.
|
|
999
1039
|
- `on-details` (optional): a bare Msg tag whose payload is the `<details>` block's document-order index; declare `toggle_details: usize`.
|
|
1000
1040
|
- `details-expanded` (optional): one `{binding}` naming a `[]const bool` iterable (a model field, pub decl, or fn — the same sources `for each` accepts); flags are read in details-block document order. Keep a bounded `details_expanded: [8]bool` in the model and toggle it in `update`.
|
|
1001
1041
|
- `issue-link-base` (optional): a literal URL prefix or one `{binding}` producing it; `#123` references at word boundaries become links to base ++ number (`issue-link-base="ghissue://"` links `#123` to `ghissue://123` — an app scheme your `on-link` handler intercepts, or a web base like `https://github.com/owner/repo/issues/`). Off by default: resolving a ref needs repo context.
|
|
1002
|
-
- No children
|
|
1042
|
+
- No children and no text content (teaching errors point at misuse). Without the details wiring, `<details>` blocks render collapsed and inert; without `on-link`, links render styled but inert.
|
|
1003
1043
|
|
|
1004
1044
|
## Pipeline composites: stepper, timeline, nav
|
|
1005
1045
|
|
|
@@ -1123,9 +1163,11 @@ Tests that touch files or clocks get their `Io` from `std.testing.io`. The full
|
|
|
1123
1163
|
|
|
1124
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).
|
|
1125
1165
|
|
|
1126
|
-
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
|
|
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)
|
|
1127
1169
|
|
|
1128
|
-
|
|
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.
|
|
1129
1171
|
|
|
1130
1172
|
Unit tests exercise the real dispatch path — no GUI needed:
|
|
1131
1173
|
|