@native-sdk/cli 0.9.4 → 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 +68 -57
- package/build.zig +12 -1
- package/package.json +10 -9
- package/packages/core/package-lock.json +2 -2
- package/packages/core/package.json +1 -1
- package/packages/core/scripts/run_external_core_compiler.mjs +19 -9
- package/packages/core/scripts/run_external_service_compiler.mjs +17 -8
- package/packages/core/scripts/vendor_service_packages.mjs +121 -8
- package/packages/core/sdk/events.d.ts +33 -4
- package/packages/core/sdk/events.ts +45 -6
- package/packages/core/src/checker.ts +103 -8
- 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 +26 -5
- package/skill-data/ts-core/SKILL.md +6 -6
- package/skills/native-sdk/SKILL.md +2 -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 +161 -33
- package/src/runtime/ui_app.zig +33 -1
- package/src/runtime/ui_app_tests.zig +63 -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 +165 -116
- package/src/tooling/ts_core.zig +11 -7
- package/src/tooling/verbs.zig +7 -6
- package/src/tooling/web_engine.zig +17 -1
|
@@ -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
|
|
|
@@ -979,6 +979,27 @@ The view binds that model-owned id in either tier; `0` is the no-image sentinel
|
|
|
979
979
|
<avatar image="{avatar}" label="Octocat">OC</avatar>
|
|
980
980
|
```
|
|
981
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
|
+
|
|
982
1003
|
### Zig cores and extensions: direct registration
|
|
983
1004
|
|
|
984
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):
|
|
@@ -995,7 +1016,7 @@ Image pixels are runtime-registered resources keyed by a caller-chosen `ImageId`
|
|
|
995
1016
|
```
|
|
996
1017
|
|
|
997
1018
|
```zig
|
|
998
|
-
// Zig views
|
|
1019
|
+
// Zig views:
|
|
999
1020
|
ui.avatar(.{ .image = model.avatar_image, .semantics = .{ .label = "Octocat" } }, "OC"),
|
|
1000
1021
|
ui.image(.{ .image = model.chart_image, .width = 120, .height = 80, .semantics = .{ .label = "Chart" } }),
|
|
1001
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
|
|
|
@@ -396,7 +396,7 @@ export type Msg = /* ... */ | { readonly kind: "library_scrolled"; readonly scro
|
|
|
396
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.
|
|
397
397
|
|
|
398
398
|
- **`commandMsg(name: string): Msg | null`** — menus, shortcuts, and chrome tabs, by command id (string equality works on `string` values).
|
|
399
|
-
- **`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.
|
|
400
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.
|
|
401
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`.
|
|
402
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.
|
|
@@ -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.
|
|
@@ -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);
|
|
@@ -705,6 +705,44 @@ typedef struct {
|
|
|
705
705
|
|
|
706
706
|
typedef void (*native_sdk_appkit_tray_callback_t)(void *context, uint32_t status_item_id, uint32_t item_id);
|
|
707
707
|
|
|
708
|
+
typedef struct {
|
|
709
|
+
uint32_t item_id;
|
|
710
|
+
const char *label;
|
|
711
|
+
size_t label_len;
|
|
712
|
+
int selected;
|
|
713
|
+
int enabled;
|
|
714
|
+
} native_sdk_appkit_tray_segment_option_t;
|
|
715
|
+
|
|
716
|
+
typedef struct {
|
|
717
|
+
size_t row_index;
|
|
718
|
+
const native_sdk_appkit_tray_segment_option_t *options;
|
|
719
|
+
size_t option_count;
|
|
720
|
+
} native_sdk_appkit_tray_segmented_row_t;
|
|
721
|
+
|
|
722
|
+
typedef struct {
|
|
723
|
+
size_t row_index;
|
|
724
|
+
const char *primary_text;
|
|
725
|
+
size_t primary_text_len;
|
|
726
|
+
const char *secondary_text;
|
|
727
|
+
size_t secondary_text_len;
|
|
728
|
+
const char *accessibility_label;
|
|
729
|
+
size_t accessibility_label_len;
|
|
730
|
+
} native_sdk_appkit_tray_metric_row_t;
|
|
731
|
+
|
|
732
|
+
typedef struct {
|
|
733
|
+
size_t row_index;
|
|
734
|
+
const float *values;
|
|
735
|
+
size_t value_count;
|
|
736
|
+
double min_value;
|
|
737
|
+
double max_value;
|
|
738
|
+
const char *leading_caption;
|
|
739
|
+
size_t leading_caption_len;
|
|
740
|
+
const char *trailing_summary;
|
|
741
|
+
size_t trailing_summary_len;
|
|
742
|
+
const char *accessibility_label;
|
|
743
|
+
size_t accessibility_label_len;
|
|
744
|
+
} native_sdk_appkit_tray_chart_row_t;
|
|
745
|
+
|
|
708
746
|
/* One native scroll driver's desired state (see PlatformServices
|
|
709
747
|
* set_gpu_surface_scroll_drivers_fn). Frame coordinates are view-local
|
|
710
748
|
* canvas points (top-left origin, y-down); the host flips to AppKit
|
|
@@ -772,15 +810,16 @@ int native_sdk_appkit_show_context_menu(native_sdk_appkit_host_t *host, uint64_t
|
|
|
772
810
|
native_sdk_appkit_open_dialog_result_t native_sdk_appkit_show_open_dialog(native_sdk_appkit_host_t *host, const native_sdk_appkit_open_dialog_opts_t *opts, char *buffer, size_t buffer_len);
|
|
773
811
|
size_t native_sdk_appkit_show_save_dialog(native_sdk_appkit_host_t *host, const native_sdk_appkit_save_dialog_opts_t *opts, char *buffer, size_t buffer_len);
|
|
774
812
|
int native_sdk_appkit_show_message_dialog(native_sdk_appkit_host_t *host, const native_sdk_appkit_message_dialog_opts_t *opts);
|
|
775
|
-
void native_sdk_appkit_create_tray(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *icon_path, size_t icon_path_len, const char *title, size_t title_len, const char *tooltip, size_t tooltip_len, int visible, double width, int tone, double icon_opacity, int monospaced, const char *activation_command, size_t activation_command_len, const char *alternate_activation_command, size_t alternate_activation_command_len, const char *open_command, size_t open_command_len);
|
|
813
|
+
void native_sdk_appkit_create_tray(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *icon_path, size_t icon_path_len, const char *title, size_t title_len, const char *tooltip, size_t tooltip_len, int visible, double width, int tone, double icon_opacity, int monospaced, double font_size, int font_weight, const char *activation_command, size_t activation_command_len, const char *alternate_activation_command, size_t alternate_activation_command_len, const char *open_command, size_t open_command_len);
|
|
776
814
|
void native_sdk_appkit_update_tray_shell(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *icon_path, size_t icon_path_len, const char *tooltip, size_t tooltip_len, int visible, const char *activation_command, size_t activation_command_len, const char *alternate_activation_command, size_t alternate_activation_command_len, const char *open_command, size_t open_command_len);
|
|
777
815
|
void native_sdk_appkit_update_tray_menu(native_sdk_appkit_host_t *host, uint32_t status_item_id, const uint32_t *item_ids, const char *const *labels, const size_t *label_lens, const int *separators, const int *enabled_flags, const char *const *details, const size_t *detail_lens, const int *roles, const char *const *keys, const size_t *key_lens, const uint32_t *modifiers, size_t count);
|
|
816
|
+
void native_sdk_appkit_update_tray_rich_rows(native_sdk_appkit_host_t *host, uint32_t status_item_id, const native_sdk_appkit_tray_segmented_row_t *segmented_rows, size_t segmented_count, const native_sdk_appkit_tray_metric_row_t *metric_rows, size_t metric_count, const native_sdk_appkit_tray_chart_row_t *chart_rows, size_t chart_count);
|
|
778
817
|
/* Retitle the live status item's button without re-creating it (create
|
|
779
818
|
* would flicker and reshuffle the menu bar). Empty title falls back to
|
|
780
819
|
* the icon-only square well, or the app-name initial when there is no
|
|
781
820
|
* icon either — the same fallbacks as create. */
|
|
782
821
|
void native_sdk_appkit_update_tray_title(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *title, size_t title_len);
|
|
783
|
-
void native_sdk_appkit_update_tray_presentation(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *title, size_t title_len, double width, int tone, double icon_opacity, int monospaced);
|
|
822
|
+
void native_sdk_appkit_update_tray_presentation(native_sdk_appkit_host_t *host, uint32_t status_item_id, const char *title, size_t title_len, double width, int tone, double icon_opacity, int monospaced, double font_size, int font_weight);
|
|
784
823
|
void native_sdk_appkit_remove_tray(native_sdk_appkit_host_t *host, uint32_t status_item_id);
|
|
785
824
|
void native_sdk_appkit_set_tray_callback(native_sdk_appkit_host_t *host, native_sdk_appkit_tray_callback_t callback, void *context);
|
|
786
825
|
|