@native-sdk/cli 0.9.3 → 0.9.5
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 +3 -3
- package/build/app.zig +323 -76
- package/build/ts_run.mjs +15 -18
- package/build.zig +83 -8
- package/package.json +14 -10
- package/packages/core/compile-surface/core.ts +1 -0
- package/packages/core/package-lock.json +16 -13
- package/packages/core/package.json +5 -2
- package/packages/core/scripts/compiler_command.mjs +71 -0
- package/packages/core/scripts/compiler_typecheck.mjs +4 -4
- package/packages/core/scripts/embed_markup_c.mjs +25 -0
- package/packages/core/scripts/npm_static_spike.mjs +3 -3
- package/packages/core/scripts/run_external_core_compiler.mjs +21 -10
- package/packages/core/scripts/run_external_service_compiler.mjs +17 -7
- package/packages/core/scripts/vendor_service_packages.mjs +121 -8
- package/packages/core/sdk/core.ts +1 -0
- package/packages/core/sdk/events.d.ts +36 -4
- package/packages/core/sdk/events.ts +49 -6
- package/packages/core/src/checker.ts +106 -10
- package/packages/core/src/modules.ts +6 -2
- package/packages/core/src/sqlite_cli.ts +22 -2
- package/packages/core/src/typed_ast.ts +4 -2
- package/packages/core/src/types.ts +8 -8
- package/schemas/app.schema.json +435 -0
- package/skill-data/core/SKILL.md +53 -15
- package/skill-data/core/references/project-anatomy.md +6 -6
- package/skill-data/native-ui/SKILL.md +28 -6
- package/skill-data/ts-core/SKILL.md +9 -6
- package/skill-data/ts-services/references/service-surface.md +1 -1
- package/skills/native-sdk/SKILL.md +2 -2
- package/src/app_runner/ts_core_main.zig +12 -4
- package/src/app_runner/ts_core_mobile.zig +6 -2
- package/src/automation/snapshot.zig +91 -3
- package/src/platform/macos/appkit_host.h +41 -2
- package/src/platform/macos/appkit_host.m +198 -9
- package/src/platform/macos/cef_host.mm +191 -9
- package/src/platform/macos/root.zig +110 -3
- package/src/platform/null_platform.zig +50 -1
- package/src/platform/null_platform_tests.zig +53 -0
- package/src/platform/root.zig +9 -0
- package/src/platform/types.zig +58 -0
- package/src/platform/windows/root.zig +88 -15
- package/src/primitives/canvas/reference.zig +37 -15
- package/src/primitives/canvas/reference_tests.zig +63 -0
- package/src/primitives/canvas/ui.zig +9 -0
- package/src/primitives/canvas/ui_markup.zig +29 -0
- package/src/primitives/canvas/ui_markup_compiled.zig +32 -0
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +4 -2
- package/src/primitives/canvas/ui_markup_contract.zig +7 -0
- package/src/primitives/canvas/ui_markup_contract_tests.zig +21 -0
- package/src/primitives/canvas/ui_markup_tests.zig +6 -0
- package/src/primitives/canvas/ui_markup_view.zig +28 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +32 -3
- package/src/primitives/canvas/ui_schema.zig +9 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -3
- package/src/primitives/canvas/ui_tests.zig +4 -2
- package/src/primitives/canvas/widget_render.zig +7 -2
- package/src/primitives/canvas/widget_semantics_tests.zig +3 -1
- package/src/root.zig +4 -0
- package/src/runtime/automation_snapshot.zig +3 -0
- package/src/runtime/flow.zig +1 -1
- package/src/runtime/state.zig +14 -0
- package/src/runtime/system_services.zig +62 -0
- package/src/runtime/ts_ui_app.zig +181 -39
- package/src/runtime/ui_app.zig +40 -1
- package/src/runtime/ui_app_tests.zig +63 -0
- package/src/runtime/ui_app_window_tests.zig +23 -0
- package/src/runtime/validation.zig +87 -1
- package/src/tooling/android.zig +5 -4
- package/src/tooling/buildgraph.zig +24 -8
- package/src/tooling/db.zig +1 -1
- package/src/tooling/doctor.zig +1 -1
- package/src/tooling/ios.zig +5 -4
- package/src/tooling/json_to_zon.zig +136 -0
- package/src/tooling/manifest.zig +120 -33
- package/src/tooling/raw_manifest.zig +4 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +171 -118
- package/src/tooling/ts_core.zig +12 -8
- package/src/tooling/verbs.zig +233 -5
- package/src/tooling/web_engine.zig +17 -1
- package/tools/corewire/emit_profile.zig +20 -7
- package/tools/corewire/emit_service.zig +49 -24
- package/tools/corewire/main.zig +21 -2
package/skill-data/core/SKILL.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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. 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.
|
|
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.json and legacy 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
|
|
@@ -13,13 +13,13 @@ Agents should assume they do not know the Native SDK from general model knowledg
|
|
|
13
13
|
|
|
14
14
|
## Mental model
|
|
15
15
|
|
|
16
|
-
- The default app has three files of truth: `src/core.ts` (`Model`, `Msg`, `update`), `src/app.native` (UI), and `app.
|
|
16
|
+
- The default app has three files of truth: `src/core.ts` (`Model`, `Msg`, `update`), `src/app.native` (UI), and `app.json` (manifest).
|
|
17
17
|
- Native markup binds model values and dispatches typed messages; only `update` changes state.
|
|
18
18
|
- The TypeScript core compiles to native code. Node is a build/check/dev tool, not an app runtime.
|
|
19
19
|
- `App` is the lower-level product/runtime interface used by generated wiring, Zig-core apps, WebView shells, and extensions.
|
|
20
20
|
- `Runtime` owns the event loop, windows, bridge dispatch, security checks, automation, tracing, platform services, and window state.
|
|
21
21
|
- `WebViewSource` tells the runtime what to load: inline HTML, a URL, or packaged assets from a local app origin.
|
|
22
|
-
- `app.
|
|
22
|
+
- `app.json` is the default app manifest: identity, icons, windows, frontend assets, web engine, permissions, bridge policy, security policy, and packaging inputs. `app.zon` remains supported.
|
|
23
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.
|
|
24
24
|
- `frontend/` is normal web code. It talks to native Zig through `window.zero.invoke()` or builtin helpers when those are enabled.
|
|
25
25
|
|
|
@@ -48,13 +48,13 @@ cd my_app
|
|
|
48
48
|
native dev
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
This creates `src/core.ts`, `src/app.native`, and `app.
|
|
51
|
+
This creates `src/core.ts`, `src/app.native`, and `app.json`; 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.
|
|
52
52
|
|
|
53
53
|
## Workflow for existing apps
|
|
54
54
|
|
|
55
55
|
Before editing an existing Native SDK app:
|
|
56
56
|
|
|
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.
|
|
57
|
+
1. Read `app.json` or `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
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.
|
|
59
59
|
3. Follow the generated code and examples in the repository instead of inventing a new app layout.
|
|
60
60
|
4. Prefer exact security policy changes over broad allowances.
|
|
@@ -62,7 +62,7 @@ Before editing an existing Native SDK app:
|
|
|
62
62
|
|
|
63
63
|
Common file ownership:
|
|
64
64
|
|
|
65
|
-
- `app.zon`: app identity, version, icons, windows, permissions, capabilities, bridge command policy, allowed origins, frontend dist/dev config, web engine, CEF config.
|
|
65
|
+
- `app.json` / `app.zon`: app identity, version, icons, windows, permissions, capabilities, bridge command policy, allowed origins, frontend dist/dev config, web engine, CEF config.
|
|
66
66
|
- `src/core.ts`: default app state and behavior — `Model`, `Msg`, `update`, pure helpers, `Cmd`, and `Sub`.
|
|
67
67
|
- `src/app.native`: default app UI — elements, layout, bindings, and message dispatch.
|
|
68
68
|
- `src/main.zig`: explicitly chosen Zig-core logic or lower-level `App` behavior, source selection, lifecycle callbacks, and custom bridge handlers.
|
|
@@ -106,9 +106,47 @@ fn source(context: *anyopaque) anyerror!native_sdk.WebViewSource {
|
|
|
106
106
|
|
|
107
107
|
`sourceFromEnv` reads `NATIVE_SDK_FRONTEND_URL`; otherwise it serves the configured asset directory. Use it for most framework apps.
|
|
108
108
|
|
|
109
|
-
## app.
|
|
109
|
+
## app.json essentials
|
|
110
|
+
|
|
111
|
+
Keep `app.json` as the source of truth for app-level behavior. Existing `app.zon` projects use the same fields in ZON syntax.
|
|
112
|
+
|
|
113
|
+
```json
|
|
114
|
+
{
|
|
115
|
+
"$schema": "https://schema.native-sdk.dev/app/v1.json",
|
|
116
|
+
"id": "com.example.my-app",
|
|
117
|
+
"name": "my-app",
|
|
118
|
+
"display_name": "My App",
|
|
119
|
+
"description": "One line about the app, shown in the About panel.",
|
|
120
|
+
"version": "0.1.0",
|
|
121
|
+
"icons": ["assets/icon.png"],
|
|
122
|
+
"platforms": ["macos", "linux"],
|
|
123
|
+
"permissions": [],
|
|
124
|
+
"capabilities": ["webview"],
|
|
125
|
+
"frontend": {
|
|
126
|
+
"dist": "frontend/dist",
|
|
127
|
+
"entry": "index.html",
|
|
128
|
+
"spa_fallback": true,
|
|
129
|
+
"dev": {
|
|
130
|
+
"url": "http://127.0.0.1:5173/",
|
|
131
|
+
"command": ["npm", "--prefix", "frontend", "run", "dev", "--", "--host", "127.0.0.1"],
|
|
132
|
+
"ready_path": "/",
|
|
133
|
+
"timeout_ms": 30000
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
"security": {
|
|
137
|
+
"navigation": {
|
|
138
|
+
"allowed_origins": ["zero://app", "http://127.0.0.1:5173"],
|
|
139
|
+
"external_links": { "action": "deny" }
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
"web_engine": "system",
|
|
143
|
+
"windows": [
|
|
144
|
+
{ "label": "main", "title": "My App", "width": 960, "height": 640, "restore_state": true }
|
|
145
|
+
]
|
|
146
|
+
}
|
|
147
|
+
```
|
|
110
148
|
|
|
111
|
-
|
|
149
|
+
Legacy ZON equivalent:
|
|
112
150
|
|
|
113
151
|
```zig
|
|
114
152
|
.{
|
|
@@ -151,13 +189,13 @@ Use exact local origins for dev servers. Add `zero://inline` only for inline HTM
|
|
|
151
189
|
|
|
152
190
|
### Add a new framework app
|
|
153
191
|
|
|
154
|
-
Use `native init <path> --frontend <next|vite|react|svelte|vue>`. Then inspect the generated `app.
|
|
192
|
+
Use `native init <path> --frontend <next|vite|react|svelte|vue>`. Then inspect the generated `app.json`, `src/main.zig`, and `build.zig` before customizing. For framework behavior, keep frontend work in `frontend/` and use `sourceFromEnv` so development and packaged builds share one app shell.
|
|
155
193
|
|
|
156
194
|
### Add a native bridge command
|
|
157
195
|
|
|
158
196
|
1. Add state and a handler in `src/main.zig`.
|
|
159
197
|
2. Register the handler in `bridge()`.
|
|
160
|
-
3. Allow the command in
|
|
198
|
+
3. Allow the command in the app manifest and in the runtime bridge policy if the runner reads manifest policy into runtime.
|
|
161
199
|
4. Call it from JavaScript with `window.zero.invoke("namespace.command", payload)`.
|
|
162
200
|
5. Return valid JSON from Zig. Use `native_sdk.bridge.writeJsonStringValue()` for user-controlled strings.
|
|
163
201
|
|
|
@@ -182,11 +220,11 @@ native package --target macos --archive
|
|
|
182
220
|
|
|
183
221
|
On macOS, `--archive` adds a zero-config drag-to-Applications DMG with a generated 1×/2× Retina background. The optional `app.zon` `.dmg` block controls its volume name, PNG/JPEG/TIFF background, usable Finder canvas/icon geometry, and Applications link. An adjacent `name@2x.png`/`.jpg` is discovered automatically. Use `.dmg.items` only for a fully art-directed list: exactly one `app`, plus optional `applications`, project-relative `file`, and absolute `link` entries, each with its own icon-center position.
|
|
184
222
|
|
|
185
|
-
Apps that own their build (ejected or scaffolded `--full`) wire the same step into the build graph: keep package metadata in
|
|
223
|
+
Apps that own their build (ejected or scaffolded `--full`) wire the same step into the build graph: keep package metadata in the app manifest, build the frontend assets, build the native binary, then package:
|
|
186
224
|
|
|
187
225
|
```bash
|
|
188
226
|
zig build package
|
|
189
|
-
native doctor --manifest app.
|
|
227
|
+
native doctor --manifest app.json --strict
|
|
190
228
|
```
|
|
191
229
|
|
|
192
230
|
Use signing and CEF options only when the product requires them.
|
|
@@ -211,7 +249,7 @@ zig build dev
|
|
|
211
249
|
Or run the CLI directly after building the binary:
|
|
212
250
|
|
|
213
251
|
```bash
|
|
214
|
-
native dev --manifest app.
|
|
252
|
+
native dev --manifest app.json --binary zig-out/bin/MyApp
|
|
215
253
|
```
|
|
216
254
|
|
|
217
255
|
Vite usually uses `http://127.0.0.1:5173/`; Next.js usually uses `http://127.0.0.1:3000/`. The app WebView loads the dev URL directly, so framework HMR remains owned by Vite, Next.js, or the selected dev server.
|
|
@@ -247,8 +285,8 @@ zig build run
|
|
|
247
285
|
zig build dev
|
|
248
286
|
zig build test
|
|
249
287
|
zig build test-tooling
|
|
250
|
-
native validate app.
|
|
251
|
-
native doctor --manifest app.
|
|
288
|
+
native validate app.json
|
|
289
|
+
native doctor --manifest app.json --strict
|
|
252
290
|
zig build package
|
|
253
291
|
```
|
|
254
292
|
|
|
@@ -4,13 +4,13 @@ Use this when creating, orienting in, or restructuring a Native SDK app.
|
|
|
4
4
|
|
|
5
5
|
## Generated project files
|
|
6
6
|
|
|
7
|
-
A default zero-config app ships no build files at all. Its authored files are `app.
|
|
7
|
+
A default zero-config app ships no build files at all. Its authored files are `app.json`, `src/core.ts`, and `src/app.native` (+ `assets/`). Existing `app.zon` manifests remain fully supported. `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
8
|
|
|
9
9
|
Files by path:
|
|
10
10
|
|
|
11
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.
|
|
12
12
|
- `build.zig.zon`: Zig package manifest and dependency declaration.
|
|
13
|
-
- `app.
|
|
13
|
+
- `app.json`: default app manifest read by CLI/build/package/doctor tooling. `app.zon` is the supported alternative.
|
|
14
14
|
- `src/core.ts`: the default app core — `Model`, `Msg`, `update`, pure helpers, effects (`Cmd`), and subscriptions (`Sub`).
|
|
15
15
|
- `src/app.native`: the default app view — elements, layout, bindings, and typed message dispatch.
|
|
16
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.
|
|
@@ -18,9 +18,9 @@ Files by path:
|
|
|
18
18
|
- `assets/`: icons and other package resources.
|
|
19
19
|
- `frontend/`: framework app when using Next, Vite, React, Svelte, or Vue.
|
|
20
20
|
|
|
21
|
-
##
|
|
21
|
+
## App manifest responsibilities
|
|
22
22
|
|
|
23
|
-
Keep product-level metadata and policies in `app.zon
|
|
23
|
+
Keep product-level metadata and policies in `app.json` (or `app.zon` in an existing project):
|
|
24
24
|
|
|
25
25
|
```zig
|
|
26
26
|
.{
|
|
@@ -115,11 +115,11 @@ zig build test-package-cef-layout -Dplatform=macos
|
|
|
115
115
|
|
|
116
116
|
## Layering rule
|
|
117
117
|
|
|
118
|
-
- If changing app identity, packaging inputs, permissions, origins, windows, frontend dist/dev paths, or web engine, update
|
|
118
|
+
- If changing app identity, packaging inputs, permissions, origins, windows, frontend dist/dev paths, or web engine, update the app's manifest.
|
|
119
119
|
- If changing default app state, messages, transitions, effects, subscriptions, or derived bindings, update `src/core.ts` and follow the `ts-core` skill.
|
|
120
120
|
- If changing the default app UI, update `src/app.native` and follow the `native-ui` skill.
|
|
121
121
|
- If changing runtime services, platform setup, automation, logging, security wiring, or builtin bridge policy, update `src/runner.zig`.
|
|
122
122
|
- If an existing lower-level/Zig app changes native lifecycle callbacks, bridge handlers, source selection, or Zig-core behavior, update its `src/main.zig`.
|
|
123
123
|
- If changing UI, routes, CSS, or web calls, update `frontend/`.
|
|
124
124
|
|
|
125
|
-
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
|
|
125
|
+
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 manifest policy for convenience.
|
|
@@ -34,7 +34,7 @@ export function statusItem(model: Model): StatusItemState {
|
|
|
34
34
|
activationCommand: asciiBytes("app.refresh"),
|
|
35
35
|
alternateActivationCommand: asciiBytes("player.toggle"),
|
|
36
36
|
openCommand: asciiBytes("app.refresh"),
|
|
37
|
-
presentation: { title: model.playing ? utf8Bytes("MB PLAY") : utf8Bytes("MB"), width: 62, tone: "normal", iconOpacity: 1, monospaced: true },
|
|
37
|
+
presentation: { title: model.playing ? utf8Bytes("MB PLAY") : utf8Bytes("MB"), width: 62, tone: "normal", iconOpacity: 1, monospaced: true, fontSize: 13, fontWeight: "semibold" },
|
|
38
38
|
items: [
|
|
39
39
|
{ id: 1, label: utf8Bytes("Open"), command: asciiBytes("app.open"), separator: false, enabled: true, detail: asciiBytes(""), role: "command", key: asciiBytes(""), modifiers: { primary: false, command: false, control: false, option: false, shift: false } },
|
|
40
40
|
{ id: 0, label: asciiBytes(""), command: asciiBytes(""), separator: true, enabled: false, detail: asciiBytes(""), role: "command", key: asciiBytes(""), modifiers: { primary: false, command: false, control: false, option: false, shift: false } },
|
|
@@ -44,7 +44,7 @@ export function statusItem(model: Model): StatusItemState {
|
|
|
44
44
|
}
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
Presentation fields
|
|
47
|
+
Presentation fields style the persistent menu-bar item. Inside its dropdown, `metric` carries prominent primary/secondary text, `segmented` carries up to eight typed command options, and `chart` carries 1–32 bounded values with captions and accessibility. These are generic composable row payloads, not text conventions.
|
|
48
48
|
|
|
49
49
|
## App wiring (Zig cores and extensions only)
|
|
50
50
|
|
|
@@ -215,7 +215,7 @@ Automation drives the native path honestly: snapshots list every widget's declar
|
|
|
215
215
|
| `skeleton`, `spinner` | loading leaves | size `skeleton` with `width`/`height` |
|
|
216
216
|
| `icon` | vector icon leaf | `name` picks the icon: a bare literal is a curated built-in stroke icon (compile-checked; 49 names: search, plus, x, x-circle, check, check-circle, chevron-up/down/left/right, arrow-up/down/right, menu, panel-left, panel-right, settings, terminal, wrench, trash, edit, copy, external-link, play, pause, skip-back/forward, shuffle, repeat, music, volume, info, alert, download, save, folder, folder-open, file-text, sun, moon, eye, clock, git-pull-request, git-merge, git-branch, circle-dot, archive, refresh-cw, send); `app:<name>` reaches an icon the app registered at boot with `canvas.icons.registerAppIcons` (declare the table as `pub const app_icons` on the app root so `native check` verifies the name against the model contract), and one `{binding}` defers the choice to model data - an unknown resolved name draws the missing-icon fallback (a slashed circle) with a Debug warning naming the value, never a silent gap; tint with `foreground`, size with `width`/`height` |
|
|
217
217
|
| `media-surface` | media surface leaf | composites a texture produced OUTSIDE the widget tree (video decoder, camera, an external renderer like mpv) into the layout like any widget — clipped, z-ordered, rounded. `surface="{binding}"` (required) binds the model-owned u64 surface id a Zig-tier producer targets (`runtime.acquireMediaSurfaceProducer` pushes RGBA8 frames, latest-wins, paced by the presented-frame clock; 0 = unbound, draws nothing; usable ids are nonzero values below the reserved bit 63). No intrinsic size — give it `width`/`height` or `grow`; display-only (presses fall through); `label` it (pictorial content). Texture contents are presentation chrome: goldens, reference screenshots, and session replay show the deterministic id-derived placeholder, never producer frames |
|
|
218
|
-
| `image` | runtime image leaf | draws a RUNTIME-REGISTERED image by its model-owned u64 ImageId — the id `Cmd.imageLoad` (TS) or `fx.loadImage`/`fx.registerImageBytes` (Zig) registered pixels under. `image="{binding}"` (required) binds a model field/fn; ids are model data, never markup literals, and 0 draws nothing (store the id only when the load reports loaded — see the Images section). No intrinsic size — give it `width`/`height` or `grow`; display-only (presses fall through); `label` it (pictorial content) |
|
|
218
|
+
| `image` | runtime image leaf | draws a RUNTIME-REGISTERED image by its model-owned u64 ImageId — the id `Cmd.imageLoad` (TS) or `fx.loadImage`/`fx.registerImageBytes` (Zig) registered pixels under. `image="{binding}"` (required) binds a model field/fn; ids are model data, never markup literals, and 0 draws nothing (store the id only when the load reports loaded — see the Images section). `source-x`/`source-y`/`source-width`/`source-height` select one atlas region in decoded-image pixel coordinates (declare all four). No intrinsic size — give it `width`/`height` or `grow`; display-only (presses fall through); `label` it (pictorial content) |
|
|
219
219
|
| `code` | bare highlighted source/editor | `source="{binding}"` (required) provides source text and `language="tsx"` selects a literal lexer name; the component supplies no background, border, radius, shadow, or padding, so wrap it in a panel/card when chrome is wanted. It is read-only by default; `editable on-input="edit"` opts into multiline editing while retaining highlighting. It wraps by default, `line-numbers` opts into logical line numbers, `added-lines="5"` / `removed-lines="2-4"` add Geist-style diff rows without changing copied source, and `wrap="false"` preserves lines inside one horizontal scroll region. HTML-family highlighting distinguishes HTML/XML/SVG and JSX/TSX tags, attributes, strings, comments, and embedded expressions. Zig builder: `ui.code(CodeOptions, source)` |
|
|
220
220
|
| `markdown` | rendered markdown subtree | leaf; `source` is one `{binding}` — see "Markdown in markup" |
|
|
221
221
|
| `stepper` > `step` | composite stage track | `active="{index}"` (required) derives each step's completed/active/pending state; steps are text leaves (no attributes) joined by connectors; stepper also takes `key`, `global-key`, `label` |
|
|
@@ -224,7 +224,7 @@ Automation drives the native path honestly: snapshots list every widget's declar
|
|
|
224
224
|
| `context-menu` | consumed by its parent | right-click menu on its DIRECT parent (a hit-target kind or an element with `on-press`/`on-double-press`/`on-toggle`/`on-hold`/`on-drag`); metadata, never a flow child. Children: `menu-item`s (`on-press` required, `disabled` optional, no `icon`) and bare `separator`s, with `if`/`else`/`for` around them. Attribute-less; presents natively where the host has a menu presenter, as an anchored surface elsewhere — see "Context menus" |
|
|
225
225
|
| `input-group` > `textarea` + `input-group-actions` | composite grouped input | the composer shape: ONE bordered field wrapping exactly one `textarea` (first — document order is focus order) plus an optional `input-group-actions` row of controls inside the same border. The group wears the focus ring for its focused descendant and the textarea's own chrome dissolves automatically, so the whole group reads as one field; the textarea keeps its full behavior (`text`, `placeholder`, `on-input`, `on-submit`, `autofocus`, and optional `submit-on-enter`). Group takes `label`, `width`, `height`, `min-width`, `grow`, `key`, `global-key`; the actions row takes `gap` and holds ordinary elements (`if`/`else`/`for` work — swap send for stop while streaming) — put a `<spacer grow="1"/>` between leading and trailing controls (`Ui.inputGroup`/`Ui.inputGroupActions` are the Zig-view equivalents) |
|
|
226
226
|
|
|
227
|
-
Not markup-expressible (deliberately — write these as Zig view functions with `canvas.Ui`): `icon_button` (`<button icon="...">` with empty content is the declarative icon button), `data_grid` (per-column cell templates), `popover`/`menu_surface` (anchored to runtime geometry), `segmented_control` (use `tabs`/`toggle-group`: `<button>` children of `<tabs>` lower to segmented triggers automatically, so the active tab lifts per the house treatment). Charts ARE expressible: `<chart>` with `<series values="{binding}">` children binding model f32 iterables — see the Charts section (`.band` series and dynamic series composition stay with `ui.chart`). Built-in vector icons ARE expressible: `<icon name="search"/>` (closed, compile-checked name set; `Ui.icon` is the Zig-view equivalent). App-authored icons: `canvas.svg_icon.parseComptime(@embedFile("icons/logo.svg"))` parses any SVG in the common 24x24 stroke-icon dialect at comptime; register the parsed table once at boot with `canvas.icons.registerAppIcons(&table)` and draw by name via `ui.appIcon(.{...}, "logo")` or `ElementOptions.icon` — registered names render exactly like built-ins on every draw path. Markup `<icon>`/`<button icon>` stay built-in-only (the compiled engine validates names at comptime, where runtime registrations cannot exist — engine parity). Runtime images ARE expressible: `<image image="{cover}" width="120" height="80" label="Cover art"/>` and `<avatar image="{user_image}">CT</avatar>` bind a `u64` ImageId model field/fn (the id is just model data; 0 draws nothing / keeps the initials fallback) — see the Images section; the `image` binding is required on the leaf (an unbound `<image>` is dead markup) and stays avatar+image scoped.
|
|
227
|
+
Not markup-expressible (deliberately — write these as Zig view functions with `canvas.Ui`): `icon_button` (`<button icon="...">` with empty content is the declarative icon button), `data_grid` (per-column cell templates), `popover`/`menu_surface` (anchored to runtime geometry), `segmented_control` (use `tabs`/`toggle-group`: `<button>` children of `<tabs>` lower to segmented triggers automatically, so the active tab lifts per the house treatment). Charts ARE expressible: `<chart>` with `<series values="{binding}">` children binding model f32 iterables — see the Charts section (`.band` series and dynamic series composition stay with `ui.chart`). Built-in vector icons ARE expressible: `<icon name="search"/>` (closed, compile-checked name set; `Ui.icon` is the Zig-view equivalent). App-authored icons: `canvas.svg_icon.parseComptime(@embedFile("icons/logo.svg"))` parses any SVG in the common 24x24 stroke-icon dialect at comptime; register the parsed table once at boot with `canvas.icons.registerAppIcons(&table)` and draw by name via `ui.appIcon(.{...}, "logo")` or `ElementOptions.icon` — registered names render exactly like built-ins on every draw path. Markup `<icon>`/`<button icon>` stay built-in-only (the compiled engine validates names at comptime, where runtime registrations cannot exist — engine parity). Runtime images ARE expressible: `<image image="{cover}" width="120" height="80" label="Cover art"/>` and `<avatar image="{user_image}">CT</avatar>` bind a `u64` ImageId model field/fn (the id is just model data; 0 draws nothing / keeps the initials fallback) — see the Images section; the `image` binding is required on the leaf (an unbound `<image>` is dead markup) and stays avatar+image scoped. Add all four `source-x`/`source-y`/`source-width`/`source-height` attributes to draw one decoded-pixel sub-rectangle from a shared atlas.
|
|
228
228
|
|
|
229
229
|
## Attributes
|
|
230
230
|
|
|
@@ -878,7 +878,7 @@ The `.wake` platform event is how live platforms marshal worker completions onto
|
|
|
878
878
|
|
|
879
879
|
## Secondary windows
|
|
880
880
|
|
|
881
|
-
In the default TypeScript path, export `windows(model): readonly WindowDescriptor[]` and put each possible window's Native markup at `src/windows/<label>.native`. Spell each constructor identity as a literal `label: asciiBytes("<label>")`; `native check` and every build reject dynamic labels and missing roots. Those roots may import shared components nested under `src/windows/`; the generated launcher compiles and hot-reloads the full closure. Use `windowDescriptor` from `@native-sdk/core`; its `
|
|
881
|
+
In the default TypeScript path, export `windows(model): readonly WindowDescriptor[]` and put each possible window's Native markup at `src/windows/<label>.native`. Spell each constructor identity as a literal `label: asciiBytes("<label>")`; `native check` and every build reject dynamic labels and missing roots. Those roots may import shared components nested under `src/windows/`; the generated launcher compiles and hot-reloads the full closure. Use `windowDescriptor` from `@native-sdk/core`; its `restorePolicy` field accepts `"clamp_to_visible_screen"` or `"center_on_primary"` (centering is currently macOS-only), `closePolicy` accepts `"quit"` or `"hide"`, and `titlebar` includes `"chromeless"`. A `"quit"` user close routes `onCloseCommand` through `commandMsg`; a `"hide"` close preserves the window and view and dispatches no close command. The `ts-core` skill has the complete descriptor and example.
|
|
882
882
|
|
|
883
883
|
### Zig cores: `windows_fn` + `window_view`
|
|
884
884
|
|
|
@@ -905,6 +905,7 @@ fn windowView(ui: *App.Ui, model: *const Model, window_label: []const u8) App.Ui
|
|
|
905
905
|
Rules that matter:
|
|
906
906
|
- **Every canvas label must be unique across the app** (main + declared windows); input routes back by it, and automation verbs (`widget-click <canvas-label> <id>`, `screenshot`) address any window's canvas the same way.
|
|
907
907
|
- **Close policy**: `WindowDescriptor.close_policy` is `.quit` by default; a user close really closes and dispatches `on_close` (the dismissal precedent), so clear the open flag in `update` — or keep declaring the window and the next rebuild brings it back (source wins). `.hide` keeps the same window, slot, and views alive, dispatches no `on_close`, and `showWindow(label)` reveals it. A close the model itself initiated never echoes a Msg. Existing platform safeguards still apply: unsupported hosts refuse `.hide` rather than strand an unreachable window.
|
|
908
|
+
- **Restore policy**: `WindowDescriptor.restore_policy` is `.clamp_to_visible_screen` by default. On macOS, `.center_on_primary` centers a fresh descriptor with no authored `x`/`y`; Windows and Linux currently keep their native default placement. Model-declared windows deliberately do not restore persisted frames.
|
|
908
909
|
- **Budget**: at most `UiApp.max_ui_windows` (4) declared windows; excess warns and is ignored. Every dispatched Msg rebuilds every open window's view.
|
|
909
910
|
- **Present-before-show**: canvas windows (any `gpu_surface` view — startup, scene, and declared windows alike) are created ordered-out and become visible only after their first canvas frame presents, so opening one never flashes blank. Automatic (`WindowOptions.show = .on_first_present`, derived from the views); webview windows show immediately. The null platform records `window_show`, `window_visible`, and present/shown sequence numbers for ordering assertions; `NATIVE_SDK_WINDOW_TIMING=1` logs create→show latency on macOS.
|
|
910
911
|
- **Markup binds ONE window's content** — there is no `window` element in the closed grammar. A markup-authored secondary window is a `canvas.CompiledMarkupView` whose `build` `window_view` calls for that label.
|
|
@@ -978,6 +979,27 @@ The view binds that model-owned id in either tier; `0` is the no-image sentinel
|
|
|
978
979
|
<avatar image="{avatar}" label="Octocat">OC</avatar>
|
|
979
980
|
```
|
|
980
981
|
|
|
982
|
+
One registered image can be a texture atlas. The source rectangle uses
|
|
983
|
+
decoded-image pixel coordinates; declare all four markup attributes, or set
|
|
984
|
+
the equivalent `ElementOptions.image_src` `geometry.RectF` in a Zig view.
|
|
985
|
+
Cropped widgets use nearest sampling so adjacent atlas regions cannot bleed:
|
|
986
|
+
|
|
987
|
+
```html
|
|
988
|
+
<image image="{atlas}" source-x="64" source-y="32"
|
|
989
|
+
source-width="24" source-height="24" width="48" height="48"
|
|
990
|
+
label="Warning badge" />
|
|
991
|
+
```
|
|
992
|
+
|
|
993
|
+
```zig
|
|
994
|
+
ui.image(.{
|
|
995
|
+
.image = model.atlas_image,
|
|
996
|
+
.image_src = geometry.RectF.init(64, 32, 24, 24),
|
|
997
|
+
.width = 48,
|
|
998
|
+
.height = 48,
|
|
999
|
+
.semantics = .{ .label = "Warning badge" },
|
|
1000
|
+
})
|
|
1001
|
+
```
|
|
1002
|
+
|
|
981
1003
|
### Zig cores and extensions: direct registration
|
|
982
1004
|
|
|
983
1005
|
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):
|
|
@@ -994,7 +1016,7 @@ Image pixels are runtime-registered resources keyed by a caller-chosen `ImageId`
|
|
|
994
1016
|
```
|
|
995
1017
|
|
|
996
1018
|
```zig
|
|
997
|
-
// Zig views
|
|
1019
|
+
// Zig views:
|
|
998
1020
|
ui.avatar(.{ .image = model.avatar_image, .semantics = .{ .label = "Octocat" } }, "OC"),
|
|
999
1021
|
ui.image(.{ .image = model.chart_image, .width = 120, .height = 80, .semantics = .{ .label = "Chart" } }),
|
|
1000
1022
|
```
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: ts-core
|
|
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-NS1069), 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
|
|
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-NS1069), 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 manifest 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). Use ts-services alongside this guide for src/services work.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Author app cores in the TypeScript subset
|
|
7
7
|
|
|
8
8
|
TypeScript is the primary app-authoring language. An app core is a Native SDK app's deterministic logic: `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
|
-
A whole TS app starts as three files of truth and zero Zig: `src/core.ts` (this guide; plus core-class modules it imports under `src/`), `src/app.native` (the markup view over the core's model), and `app.
|
|
10
|
+
A whole TS app starts as three files of truth and zero Zig: `src/core.ts` (this guide; plus core-class modules it imports under `src/`), `src/app.native` (the markup view over the core's model), and `app.json` (windows, identity, permissions). Existing `app.zon` manifests remain supported. Optional ordinary-TypeScript service modules live under `src/services/` and are never imported by the core; load `native skills get ts-services` for that boundary. `native init` scaffolds the three-file base; 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
|
|
|
12
12
|
```sh
|
|
13
13
|
native dev --core # the fastest loop: run the core under node's virtual host —
|
|
@@ -15,7 +15,7 @@ native dev --core # the fastest loop: run the core under node's virtual host
|
|
|
15
15
|
# for bytes payloads, {"advance":1000} to run virtual timers),
|
|
16
16
|
# watch the model + effect transcript. Logic only, no renderer.
|
|
17
17
|
native dev # build and run the real app (markup hot reload)
|
|
18
|
-
native check # subset-check core.ts + validate markup + app.zon
|
|
18
|
+
native check # subset-check core.ts + validate markup + app.json/app.zon
|
|
19
19
|
native build # ReleaseFast binary; native test runs the app's tests
|
|
20
20
|
```
|
|
21
21
|
|
|
@@ -197,7 +197,7 @@ export function statusItem(model: Model): StatusItemState {
|
|
|
197
197
|
activationCommand: asciiBytes("app.refresh"),
|
|
198
198
|
alternateActivationCommand: asciiBytes("player.toggle"),
|
|
199
199
|
openCommand: asciiBytes("app.refresh"),
|
|
200
|
-
presentation: { title: model.playing ? utf8Bytes("MB PLAY") : utf8Bytes("MB"), width: 62, tone: "normal", iconOpacity: 1, monospaced: true },
|
|
200
|
+
presentation: { title: model.playing ? utf8Bytes("MB PLAY") : utf8Bytes("MB"), width: 62, tone: "normal", iconOpacity: 1, monospaced: true, fontSize: 13, fontWeight: "semibold" },
|
|
201
201
|
items: [
|
|
202
202
|
{ id: 1, label: utf8Bytes("Open"), command: asciiBytes("app.open"), separator: false, enabled: true, detail: asciiBytes(""), role: "command", key: asciiBytes(""), modifiers: { primary: false, command: false, control: false, option: false, shift: false } },
|
|
203
203
|
{ id: 0, label: asciiBytes(""), command: asciiBytes(""), separator: true, enabled: false, detail: asciiBytes(""), role: "command", key: asciiBytes(""), modifiers: { primary: false, command: false, control: false, option: false, shift: false } },
|
|
@@ -207,7 +207,7 @@ export function statusItem(model: Model): StatusItemState {
|
|
|
207
207
|
}
|
|
208
208
|
```
|
|
209
209
|
|
|
210
|
-
The canonical records live in `@native-sdk/core/events`. Shell fields are `iconPath`, `tooltip`, `activationCommand`, `alternateActivationCommand`, and `openCommand`; all commands route through `commandMsg(name): Msg | null`. Presentation
|
|
210
|
+
The canonical records live in `@native-sdk/core/events`. Shell fields are `iconPath`, `tooltip`, `activationCommand`, `alternateActivationCommand`, and `openCommand`; all commands route through `commandMsg(name): Msg | null`. Presentation requires `title`, `width` (0 = host default), `tone`, `iconOpacity`, and `monospaced`; optional `fontSize` (omitted/0 = platform default) and `fontWeight` (omitted = `regular`; otherwise `regular | medium | semibold | bold`) add typography without breaking older cores. Use `statusItems` to compose several persistent menu-bar text/icon items with independent typography; attach the dropdown rows to whichever descriptor should open it. Actionable rows need unique non-zero whole u32 ids, and the runtime cap is 32 rows per item. Linux does not implement status items today.
|
|
211
211
|
|
|
212
212
|
For multiple items export `statusItems(model): readonly StatusItemDescriptor[]` instead (never both helpers). A descriptor has the singular fields plus stable non-zero `id` identity and live `visible`. Presence creates, absence removes, and changed icon/title/tooltip/visibility/activation/menu fields patch only that id; one menu update never recreates any native item. macOS supports eight simultaneous items. Row ids are scoped to one menu, so different status items may reuse them. This is the Vercel-shaped spend-indicator plus persistent-control-item surface.
|
|
213
213
|
|
|
@@ -231,6 +231,7 @@ export function windows(model: Model): readonly WindowDescriptor[] {
|
|
|
231
231
|
title: asciiBytes("Settings"),
|
|
232
232
|
width: 420,
|
|
233
233
|
height: 240,
|
|
234
|
+
restorePolicy: "center_on_primary",
|
|
234
235
|
resizable: false,
|
|
235
236
|
closePolicy: "quit",
|
|
236
237
|
onCloseCommand: asciiBytes("app.settings-closed"),
|
|
@@ -240,6 +241,8 @@ export function windows(model: Model): readonly WindowDescriptor[] {
|
|
|
240
241
|
|
|
241
242
|
`closePolicy` is `"quit"` by default. Under `"quit"`, a user close really closes the window and routes `onCloseCommand` through `commandMsg`; map it to the Msg that clears the model's open flag. If the model keeps declaring the label, source wins and the next reconciliation recreates it. Under `"hide"`, the same native window and view stay alive, no close command fires, and `Cmd.showWindow("settings")` reveals it. Stopping the declaration always performs a real reconcile close. The platform safeguards for `hide` are the same as manifest windows. Model-declared secondary windows are desktop-only.
|
|
242
243
|
|
|
244
|
+
`restorePolicy` accepts `"clamp_to_visible_screen"` (the default) or `"center_on_primary"`. Model-declared windows do not restore persisted frames. On macOS, the latter centers a fresh descriptor with no `x`/`y` directly at native creation time; Windows and Linux currently keep their native default placement.
|
|
245
|
+
|
|
243
246
|
`titlebar` accepts `"standard"`, `"hidden_inset"`, `"hidden_inset_tall"`, and `"chromeless"`. The last removes all OS chrome and is required when a transparent model-declared window targets Windows; provide working app-drawn close/minimize controls for that fully skinned shape.
|
|
244
247
|
|
|
245
248
|
### The init command
|
|
@@ -393,7 +396,7 @@ export type Msg = /* ... */ | { readonly kind: "library_scrolled"; readonly scro
|
|
|
393
396
|
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.
|
|
394
397
|
|
|
395
398
|
- **`commandMsg(name: string): Msg | null`** — menus, shortcuts, and chrome tabs, by command id (string equality works on `string` values).
|
|
396
|
-
- **`statusItem(model: Model): StatusItemState` / `statusItems(model: Model): readonly StatusItemDescriptor[]`** — one complete menu-bar item, or a stable-id collection
|
|
399
|
+
- **`statusItem(model: Model): StatusItemState` / `statusItems(model: Model): readonly StatusItemDescriptor[]`** — one complete menu-bar item, or a stable-id collection. Presentation includes generic title typography. Dropdown rows include a typed `metric` block, typed segmented options, and bounded chart data; never encode these as text conventions. The generated launcher reconciles after committed updates.
|
|
397
400
|
- **`themeState(model: Model): ThemeState`** — the stock theme's model-owned pack, color scheme, and accent. Import `ThemeState` from `@native-sdk/core/events`; each field is optional (`pack`, `colorScheme`, `accent`). Omit a field to inherit app.zon, use `colorScheme: "system"` (or omit it) to follow the OS, and spell accents exactly `#rrggbb`. High contrast/reduced motion remain system-owned and high contrast suppresses accents. `themePack(model)` remains the pack-only compatibility helper; export one or the other, never both. Complete `tokens_fn`/`tokens` wiring takes precedence. Forced scheme applies to canvas tokens in v1; native chrome and WebViews remain OS-themed.
|
|
398
401
|
- **`windows(model: Model): readonly WindowDescriptor[]`** — the model-declared secondary-window set. The launcher compiles `src/windows/<label>.native`, reconciles descriptor presence after committed updates, projects `closePolicy`, and routes a `.quit` `onCloseCommand` through `commandMsg`.
|
|
399
402
|
- **`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.
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
Verify without writing:
|
|
7
7
|
node packages/core/scripts/gen_service_surface.mjs --check -->
|
|
8
8
|
|
|
9
|
-
# Service compile surface — scriptc 0.0.
|
|
9
|
+
# Service compile surface — scriptc 0.0.33
|
|
10
10
|
|
|
11
11
|
What TypeScript under `src/services/` can use, as stated by the pinned
|
|
12
12
|
compiler itself (surface manifest schema 1, 527 entries:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: native-sdk
|
|
3
|
-
description: Discovery skill for the Native SDK, the complete toolkit for building native desktop applications. Apps are authored in TypeScript + declarative Native markup (.native) by default and compiled to native code with no JS runtime in the binary; Zig cores are an explicit alternative, and WebViews are the optional web-content path. Use when the user asks what the Native SDK is, how to build a Native SDK app, author native UI, scaffold an app, configure app.zon, add bridge commands, embed web content, package an app, test a running app, or automate a Native SDK app.
|
|
3
|
+
description: Discovery skill for the Native SDK, the complete toolkit for building native desktop applications. Apps are authored in TypeScript + declarative Native markup (.native) by default and compiled to native code with no JS runtime in the binary; Zig cores are an explicit alternative, and WebViews are the optional web-content path. Use when the user asks what the Native SDK is, how to build a Native SDK app, author native UI, scaffold an app, configure app.json or legacy app.zon, add bridge commands, embed web content, package an app, test a running app, or automate a Native SDK app.
|
|
4
4
|
allowed-tools: Bash(native:*), Bash(npx @native-sdk/cli:*)
|
|
5
5
|
hidden: true
|
|
6
6
|
---
|
|
@@ -31,4 +31,4 @@ cd my_app
|
|
|
31
31
|
native dev
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
`native init my_app` generates the primary three-file app: `app.
|
|
34
|
+
`native init my_app` generates the primary three-file app: `app.json`, `src/app.native` (the markup view), and `src/core.ts` (`Model`, `Msg`, `update`). Existing `app.zon` manifests remain supported. Inspect the tree before editing an existing app and preserve the core language it already uses. `src/main.zig` means the app explicitly uses the Zig-core template; web-frontend shells additionally carry `frontend/` and usually owned build/runtime wiring.
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
//! The generated wiring for a TypeScript app core — staged (never written
|
|
2
2
|
//! into the app) by the framework build when the tree carries src/core.ts:
|
|
3
|
-
//! the build transpiles the core beside this file as core.zig,
|
|
4
|
-
//! app's src/app.native
|
|
3
|
+
//! the build transpiles the core beside this file as core.zig, links the
|
|
4
|
+
//! app's src/app.native as an isolated data object, and roots the app module
|
|
5
|
+
//! here. The
|
|
5
6
|
//! app tree stays three files of truth — core.ts (logic), app.native
|
|
6
7
|
//! (view), app.zon (manifest) — and every value below derives from them at
|
|
7
8
|
//! comptime:
|
|
@@ -79,7 +80,14 @@ const App = Adapter.App;
|
|
|
79
80
|
|
|
80
81
|
const shell_scene = native_sdk.app_manifest.shellConfigFrom(manifest);
|
|
81
82
|
const canvas_label = native_sdk.app_manifest.firstGpuSurfaceLabel(shell_scene);
|
|
82
|
-
|
|
83
|
+
extern const native_sdk_app_markup: u8;
|
|
84
|
+
extern const native_sdk_app_markup_len: usize;
|
|
85
|
+
|
|
86
|
+
/// Primary markup is linked as a data object so changing it does not dirty
|
|
87
|
+
/// this Zig module's already-compiled SDK/app graph.
|
|
88
|
+
pub fn appMarkup() []const u8 {
|
|
89
|
+
return @as([*]const u8, @ptrCast(&native_sdk_app_markup))[0..native_sdk_app_markup_len];
|
|
90
|
+
}
|
|
83
91
|
|
|
84
92
|
const app_permissions = manifestStringList(manifest, "permissions");
|
|
85
93
|
const allowed_origins = manifestAllowedOrigins();
|
|
@@ -90,7 +98,7 @@ pub fn main(init: std.process.Init) !void {
|
|
|
90
98
|
.name = manifest.name,
|
|
91
99
|
.scene = shell_scene,
|
|
92
100
|
.canvas_label = canvas_label,
|
|
93
|
-
.markup = .{ .source =
|
|
101
|
+
.markup = .{ .source = appMarkup(), .watch_path = "src/app.native", .io = init.io },
|
|
94
102
|
// app.zon's theme pack; unthemed manifests get the house register.
|
|
95
103
|
// The stock tokens compose the pack with the LIVE system
|
|
96
104
|
// appearance, so TS apps follow the OS light/dark flip with no
|
|
@@ -46,7 +46,11 @@ const Adapter = native_sdk.TsUiApp(core);
|
|
|
46
46
|
pub const Model = core.Model;
|
|
47
47
|
pub const Msg = core.Msg;
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
extern const native_sdk_app_markup: u8;
|
|
50
|
+
extern const native_sdk_app_markup_len: usize;
|
|
51
|
+
pub fn appMarkup() []const u8 {
|
|
52
|
+
return @as([*]const u8, @ptrCast(&native_sdk_app_markup))[0..native_sdk_app_markup_len];
|
|
53
|
+
}
|
|
50
54
|
|
|
51
55
|
comptime {
|
|
52
56
|
// The build graph resolves the carrier before staging this file; a
|
|
@@ -97,7 +101,7 @@ pub fn mobileOptions() Adapter.Options {
|
|
|
97
101
|
.name = manifest.name,
|
|
98
102
|
.scene = mobile_scene,
|
|
99
103
|
.canvas_label = native_sdk.embed.mobile_gpu_surface_label,
|
|
100
|
-
.markup = .{ .source =
|
|
104
|
+
.markup = .{ .source = appMarkup() },
|
|
101
105
|
// app.zon's theme pack and one-accent override, same as desktop.
|
|
102
106
|
.theme = comptime manifestThemePack(),
|
|
103
107
|
.theme_accent = comptime manifestThemeAccent(),
|
|
@@ -228,6 +228,9 @@ pub const TrayItem = struct {
|
|
|
228
228
|
role: platform.TrayItemRole = .command,
|
|
229
229
|
key: []const u8 = "",
|
|
230
230
|
modifiers: platform.ShortcutModifiers = .{},
|
|
231
|
+
segmented: ?platform.TraySegmentedRow = null,
|
|
232
|
+
metric: ?platform.TrayMetricRow = null,
|
|
233
|
+
chart: ?platform.TrayChartRow = null,
|
|
231
234
|
};
|
|
232
235
|
|
|
233
236
|
/// The live status item (tray): current button title + dropdown items.
|
|
@@ -643,6 +646,42 @@ pub fn writeText(input: Input, writer: anytype) !void {
|
|
|
643
646
|
try writer.writeAll(" tray-item separator\n");
|
|
644
647
|
continue;
|
|
645
648
|
}
|
|
649
|
+
if (item.segmented) |segmented| {
|
|
650
|
+
try writer.print(" tray-item #{d} role=segmented options={d}\n", .{ item.id, segmented.options.len });
|
|
651
|
+
for (segmented.options) |option| {
|
|
652
|
+
try writer.print(" tray-segment #{d} label=", .{option.id});
|
|
653
|
+
try writeQuotedSnapshotText(option.label, writer);
|
|
654
|
+
try writer.writeAll(" command=");
|
|
655
|
+
try writeQuotedSnapshotText(option.command, writer);
|
|
656
|
+
try writer.print(" selected={any} enabled={any}\n", .{ option.selected, option.enabled });
|
|
657
|
+
}
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
if (item.metric) |metric| {
|
|
661
|
+
try writer.print(" tray-item #{d} role=metric primary=", .{item.id});
|
|
662
|
+
try writeQuotedSnapshotText(metric.primary_text, writer);
|
|
663
|
+
try writer.writeAll(" secondary=");
|
|
664
|
+
try writeQuotedSnapshotText(metric.secondary_text, writer);
|
|
665
|
+
try writer.writeAll(" accessibility=");
|
|
666
|
+
try writeQuotedSnapshotText(metric.accessibility_label, writer);
|
|
667
|
+
try writer.writeByte('\n');
|
|
668
|
+
continue;
|
|
669
|
+
}
|
|
670
|
+
if (item.chart) |chart| {
|
|
671
|
+
try writer.print(" tray-item #{d} role=chart caption=", .{item.id});
|
|
672
|
+
try writeQuotedSnapshotText(chart.leading_caption, writer);
|
|
673
|
+
try writer.writeAll(" summary=");
|
|
674
|
+
try writeQuotedSnapshotText(chart.trailing_summary, writer);
|
|
675
|
+
try writer.writeAll(" accessibility=");
|
|
676
|
+
try writeQuotedSnapshotText(chart.accessibility_label, writer);
|
|
677
|
+
try writer.print(" domain=({d},{d}) values=", .{ chart.min_value, chart.max_value });
|
|
678
|
+
for (chart.values, 0..) |value, index| {
|
|
679
|
+
if (index > 0) try writer.writeByte(',');
|
|
680
|
+
try writer.print("{d}", .{value});
|
|
681
|
+
}
|
|
682
|
+
try writer.writeByte('\n');
|
|
683
|
+
continue;
|
|
684
|
+
}
|
|
646
685
|
try writer.print(" tray-item #{d} label=\"{s}\" command=\"{s}\" enabled={any} detail=\"{s}\" role={s} key=\"{s}\" modifiers=(primary={any},command={any},control={any},option={any},shift={any})\n", .{
|
|
647
686
|
item.id,
|
|
648
687
|
item.label,
|
|
@@ -982,24 +1021,36 @@ test "snapshot emits the frame_profile line only while profiling" {
|
|
|
982
1021
|
try std.testing.expect(std.mem.indexOf(u8, off_writer.buffered(), "frame_profile") == null);
|
|
983
1022
|
}
|
|
984
1023
|
|
|
985
|
-
test "snapshot emits tray title and dropdown items" {
|
|
986
|
-
var buffer: [
|
|
1024
|
+
test "snapshot emits tray title and typed dropdown items" {
|
|
1025
|
+
var buffer: [2048]u8 = undefined;
|
|
987
1026
|
var writer = std.Io.Writer.fixed(&buffer);
|
|
988
1027
|
const windows = [_]Window{.{ .title = "Test", .bounds = geometry.RectF.init(0, 0, 100, 100) }};
|
|
1028
|
+
const segments = [_]platform.TraySegmentOption{
|
|
1029
|
+
.{ .id = 20, .label = "Day", .command = "range.day", .selected = true },
|
|
1030
|
+
.{ .id = 21, .label = "Week", .command = "range.week", .enabled = false },
|
|
1031
|
+
};
|
|
1032
|
+
const chart_values = [_]f32{ 0.25, 0.5, 1 };
|
|
989
1033
|
const items = [_]TrayItem{
|
|
990
1034
|
.{ .id = 1, .label = "Refresh", .command = "app.refresh" },
|
|
1035
|
+
.{ .role = .hero, .metric = .{ .primary_text = "2,494 requests", .secondary_text = "Today · production", .accessibility_label = "2,494 requests today in production" } },
|
|
991
1036
|
.{ .separator = true },
|
|
992
1037
|
.{ .id = 10, .label = "Fix crash on resize", .command = "issue.select.0", .enabled = false, .detail = "warning ⚠", .role = .agent, .key = "q", .modifiers = .{ .command = true } },
|
|
1038
|
+
.{ .role = .segmented, .segmented = .{ .options = &segments } },
|
|
1039
|
+
.{ .role = .chart, .chart = .{ .values = &chart_values, .min_value = 0, .max_value = 1, .leading_caption = "CPU", .trailing_summary = "50%", .accessibility_label = "CPU history, 50 percent" } },
|
|
993
1040
|
};
|
|
994
1041
|
try writeText(.{
|
|
995
1042
|
.windows = &windows,
|
|
996
1043
|
.trays = &.{.{ .id = 7, .title = "ZN 3", .visible = false, .items = &items }},
|
|
997
1044
|
}, &writer);
|
|
998
1045
|
const text = writer.buffered();
|
|
999
|
-
try std.testing.expect(std.mem.indexOf(u8, text, "\ntray #7 title=\"ZN 3\" visible=false items=
|
|
1046
|
+
try std.testing.expect(std.mem.indexOf(u8, text, "\ntray #7 title=\"ZN 3\" visible=false items=6\n") != null);
|
|
1000
1047
|
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #1 label=\"Refresh\" command=\"app.refresh\" enabled=true detail=\"\" role=command key=\"\" modifiers=(primary=false,command=false,control=false,option=false,shift=false)\n") != null);
|
|
1001
1048
|
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item separator\n") != null);
|
|
1049
|
+
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #0 role=metric primary=\"2,494 requests\" secondary=\"Today · production\" accessibility=\"2,494 requests today in production\"\n") != null);
|
|
1002
1050
|
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #10 label=\"Fix crash on resize\" command=\"issue.select.0\" enabled=false detail=\"warning ⚠\" role=agent key=\"q\" modifiers=(primary=false,command=true,control=false,option=false,shift=false)\n") != null);
|
|
1051
|
+
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #0 role=segmented options=2\n") != null);
|
|
1052
|
+
try std.testing.expect(std.mem.indexOf(u8, text, " tray-segment #20 label=\"Day\" command=\"range.day\" selected=true enabled=true\n") != null);
|
|
1053
|
+
try std.testing.expect(std.mem.indexOf(u8, text, " tray-item #0 role=chart caption=\"CPU\" summary=\"50%\" accessibility=\"CPU history, 50 percent\" domain=(0,1) values=0.25,0.5,1\n") != null);
|
|
1003
1054
|
|
|
1004
1055
|
// No tray -> no tray lines.
|
|
1005
1056
|
var empty_buffer: [512]u8 = undefined;
|
|
@@ -1008,6 +1059,43 @@ test "snapshot emits tray title and dropdown items" {
|
|
|
1008
1059
|
try std.testing.expect(std.mem.indexOf(u8, empty_writer.buffered(), "tray") == null);
|
|
1009
1060
|
}
|
|
1010
1061
|
|
|
1062
|
+
test "snapshot escapes hostile typed tray row text" {
|
|
1063
|
+
var buffer: [4096]u8 = undefined;
|
|
1064
|
+
var writer = std.Io.Writer.fixed(&buffer);
|
|
1065
|
+
const windows = [_]Window{.{ .title = "Test", .bounds = geometry.RectF.init(0, 0, 100, 100) }};
|
|
1066
|
+
const segments = [_]platform.TraySegmentOption{.{
|
|
1067
|
+
.id = 20,
|
|
1068
|
+
.label = "Day\"\nnext\\",
|
|
1069
|
+
.command = "range.\"day\n",
|
|
1070
|
+
}};
|
|
1071
|
+
const chart_values = [_]f32{0.5};
|
|
1072
|
+
const items = [_]TrayItem{
|
|
1073
|
+
.{ .role = .segmented, .segmented = .{ .options = &segments } },
|
|
1074
|
+
.{ .role = .hero, .metric = .{
|
|
1075
|
+
.primary_text = "2\"\nrequests",
|
|
1076
|
+
.secondary_text = "Today\r\\production",
|
|
1077
|
+
.accessibility_label = "metric\t\x01",
|
|
1078
|
+
} },
|
|
1079
|
+
.{ .role = .chart, .chart = .{
|
|
1080
|
+
.values = &chart_values,
|
|
1081
|
+
.leading_caption = "CPU\"\n",
|
|
1082
|
+
.trailing_summary = "50%\\\r",
|
|
1083
|
+
.accessibility_label = "chart\t\x7f",
|
|
1084
|
+
} },
|
|
1085
|
+
};
|
|
1086
|
+
try writeText(.{
|
|
1087
|
+
.windows = &windows,
|
|
1088
|
+
.trays = &.{.{ .items = &items }},
|
|
1089
|
+
}, &writer);
|
|
1090
|
+
const text = writer.buffered();
|
|
1091
|
+
try std.testing.expect(std.mem.indexOf(u8, text, "tray-segment #20 label=\"Day\\\"\\nnext\\\\\" command=\"range.\\\"day\\n\"") != null);
|
|
1092
|
+
try std.testing.expect(std.mem.indexOf(u8, text, "role=metric primary=\"2\\\"\\nrequests\" secondary=\"Today\\r\\\\production\" accessibility=\"metric\\t\\u0001\"") != null);
|
|
1093
|
+
try std.testing.expect(std.mem.indexOf(u8, text, "role=chart caption=\"CPU\\\"\\n\" summary=\"50%\\\\\\r\" accessibility=\"chart\\t\\u007f\"") != null);
|
|
1094
|
+
// Header, window, tray, segmented wrapper, segment, metric, and chart:
|
|
1095
|
+
// hostile values inject no additional line-oriented records.
|
|
1096
|
+
try std.testing.expectEqual(@as(usize, 7), std.mem.count(u8, text, "\n"));
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1011
1099
|
test "snapshot emits configured command and app-menu catalogs" {
|
|
1012
1100
|
var buffer: [2048]u8 = undefined;
|
|
1013
1101
|
var writer = std.Io.Writer.fixed(&buffer);
|