@native-sdk/cli 0.4.3 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/app.zig +308 -72
- package/build/ts_run.mjs +63 -0
- package/build.zig +336 -7
- package/build.zig.zon +1 -0
- package/package.json +15 -10
- package/packages/core/package-lock.json +43 -0
- package/packages/core/package.json +37 -0
- package/packages/core/rt/rt.zig +1579 -0
- package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
- package/packages/core/sdk/core.ts +694 -0
- package/packages/core/sdk/events.ts +137 -0
- package/packages/core/sdk/text.ts +519 -0
- package/packages/core/src/checker.ts +1869 -0
- package/packages/core/src/cli.ts +68 -0
- package/packages/core/src/devhost.ts +291 -0
- package/packages/core/src/devhost_resolver.mjs +22 -0
- package/packages/core/src/diagnostics.ts +417 -0
- package/packages/core/src/emitter.ts +8815 -0
- package/packages/core/src/infer.ts +1515 -0
- package/packages/core/src/modules.ts +173 -0
- package/packages/core/src/ownership.ts +740 -0
- package/packages/core/src/text_polyfill.ts +337 -0
- package/packages/core/src/text_tables.ts +408 -0
- package/packages/core/src/transpile.ts +146 -0
- package/packages/core/src/typed_ast.ts +536 -0
- package/packages/core/src/types.ts +815 -0
- package/skill-data/core/SKILL.md +3 -0
- package/skill-data/native-ui/SKILL.md +30 -0
- package/skill-data/ts-core/SKILL.md +493 -0
- package/skill-data/zig/SKILL.md +208 -0
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/root.zig +75 -9
- package/src/app_runner/ts_core_main.zig +231 -0
- package/src/platform/linux/gtk_host.c +226 -21
- package/src/platform/windows/webview2_host.cpp +16 -10
- package/src/primitives/app_manifest/comptime_scene.zig +341 -0
- package/src/primitives/app_manifest/root.zig +13 -0
- package/src/primitives/app_manifest/types.zig +14 -0
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/app_manifest/web_layer.zig +366 -0
- package/src/primitives/canvas/commands.zig +14 -7
- package/src/primitives/canvas/lazy_tls.zig +73 -0
- package/src/primitives/canvas/render_generic_resources.zig +22 -15
- package/src/primitives/canvas/root.zig +6 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +40 -32
- package/src/primitives/canvas/text_layout_cache.zig +29 -22
- package/src/primitives/canvas/text_measure_cache.zig +56 -41
- package/src/primitives/canvas/text_spans.zig +39 -26
- package/src/primitives/canvas/tokens.zig +54 -0
- package/src/primitives/canvas/ui.zig +125 -0
- package/src/primitives/canvas/ui_markup.zig +22 -3
- package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
- package/src/primitives/canvas/ui_markup_contract.zig +68 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
- package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
- package/src/primitives/canvas/ui_markup_view.zig +105 -1
- package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
- package/src/primitives/canvas/ui_schema.zig +8 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -4
- package/src/primitives/canvas/widget_invalidation.zig +14 -7
- package/src/primitives/canvas/widget_render.zig +25 -15
- package/src/primitives/canvas/widget_render_controls.zig +15 -9
- package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
- package/src/root.zig +7 -0
- package/src/runtime/api.zig +7 -0
- package/src/runtime/bridge_responses.zig +2 -0
- package/src/runtime/builtin_bridge.zig +6 -0
- package/src/runtime/canvas_frame.zig +57 -36
- package/src/runtime/canvas_images.zig +9 -3
- package/src/runtime/canvas_widget_control_tests.zig +5 -6
- package/src/runtime/canvas_widget_runtime.zig +7 -4
- package/src/runtime/effects.zig +490 -2
- package/src/runtime/effects_host_tests.zig +594 -0
- package/src/runtime/flow.zig +8 -0
- package/src/runtime/platform_bridge_tests.zig +1 -0
- package/src/runtime/root.zig +18 -0
- package/src/runtime/session_replay.zig +7 -1
- package/src/runtime/session_tests.zig +35 -8
- package/src/runtime/tests.zig +2 -0
- package/src/runtime/ts_core_host.zig +1505 -0
- package/src/runtime/ts_core_host_tests.zig +1408 -0
- package/src/runtime/ts_ui_app.zig +469 -0
- package/src/runtime/ui_app.zig +58 -0
- package/src/runtime/view_canvas.zig +24 -17
- package/src/runtime/view_widget_tree.zig +2 -2
- package/src/runtime/web_layer_gate_tests.zig +242 -0
- package/src/runtime/window_storage.zig +5 -0
- package/src/runtime/window_view_runtime.zig +1 -0
- package/src/tooling/buildgraph.zig +7 -1
- package/src/tooling/codesign.zig +212 -105
- package/src/tooling/doctor.zig +78 -0
- package/src/tooling/manifest.zig +314 -1
- package/src/tooling/package.zig +722 -18
- package/src/tooling/raw_manifest.zig +16 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +911 -88
- package/src/tooling/ts_core.zig +486 -0
- package/src/tooling/verbs.zig +22 -0
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: zig
|
|
3
|
+
description: Zig 0.16 idioms for Native SDK code, indexed by compile error. Load when `zig build` fails on std APIs with errors like "struct 'fs' has no member named 'cwd'", "struct 'array_list.Aligned(u8,null)' has no member named 'init'", "struct 'std' has no member named 'io'", "no member named 'GeneralPurposeAllocator'", "no member named 'getEnvMap'", or "invalid format string" - the signature of code written for Zig 0.15 or earlier. Covers main(std.process.Init), std.Io file IO and writers, ArrayList, process spawning, environment, clocks and sleep, sockets, custom formatting, and build.zig module shapes, each as this SDK writes them.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Zig 0.16 for Native SDK code
|
|
7
|
+
|
|
8
|
+
The Native SDK requires Zig 0.16.0 (`minimum_zig_version` in `build.zig.zon`; the CLI pins the same version and offers a checksum-verified download into `~/.native/toolchains/` when the `zig` on PATH does not match). Training data and older guides teach Zig 0.15 idioms, and 0.16 moved everything that touches the outside world — files, stdout, clocks, sleeping, process spawning, sockets — behind an explicit `std.Io` value, while containers became allocator-per-call. Each section below is headed by the exact compile error the old idiom produces, so search this file by error text.
|
|
9
|
+
|
|
10
|
+
Two rules resolve most failures:
|
|
11
|
+
|
|
12
|
+
- Operations on the outside world take a `std.Io` first (or right after the receiver). Get one from `init.io` in `main(init: std.process.Init)`, from `std.testing.io` in tests, or from `std.Io.Threaded` in code with no `Init` to thread through.
|
|
13
|
+
- Containers are unmanaged: initialize with `.empty` and pass the allocator to every mutating call.
|
|
14
|
+
|
|
15
|
+
In a UiApp, `update` never sees an `Io` — persistence, subprocesses, HTTP, clocks, and timers go through the typed effects channel (`fx.readFile`, `fx.spawn`, `fx.fetch`, `fx.wallMs`, `fx.startTimer`; see `native skills get native-ui`). Raw `std.Io` belongs in `main`, tests, and standalone tools. And because Zig analyzes lazily, a 0.15-ism can hide in code only one build path references: run BOTH `zig build` and `zig build test` before calling a change done.
|
|
16
|
+
|
|
17
|
+
## error: struct 'heap' has no member named 'GeneralPurposeAllocator' — allocators come from `main(init: std.process.Init)`
|
|
18
|
+
|
|
19
|
+
Zig 0.15 and earlier:
|
|
20
|
+
|
|
21
|
+
```zig
|
|
22
|
+
pub fn main() !void {
|
|
23
|
+
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
|
24
|
+
defer _ = gpa.deinit();
|
|
25
|
+
const allocator = gpa.allocator();
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Zig 0.16: `main` takes `std.process.Init`, which carries the process-wide allocators, the `Io`, the environment, and the args — nothing to construct or deinit:
|
|
30
|
+
|
|
31
|
+
```zig
|
|
32
|
+
pub fn main(init: std.process.Init) !void {
|
|
33
|
+
const gpa = init.gpa; // general purpose, leak-checked in Debug
|
|
34
|
+
const arena = init.arena.allocator(); // process-lifetime arena, freed on exit
|
|
35
|
+
const io = init.io; // the Io every std call below wants
|
|
36
|
+
const args = try init.minimal.args.toSlice(arena);
|
|
37
|
+
if (init.environ_map.get("HOME")) |home| { ... }
|
|
38
|
+
}
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The CLI's own entry point is the live reference: `tools/native-sdk/main.zig`. Generated apps already have this shape — `main(init: std.process.Init)` passes `init` through to `runner.runWithOptions(app, options, init)` and `init.io` to the markup hot-reload watcher (see any `examples/*/src/main.zig`). `std.heap.page_allocator` still exists for allocations that live for the whole process. Library code that cannot take an `Init` builds its own `Io`: `var threaded = std.Io.Threaded.init(allocator, .{});` then `threaded.io()` (`src/platform/macos/root.zig`).
|
|
42
|
+
|
|
43
|
+
## error: struct 'fs' has no member named 'cwd' — file IO moved to `std.Io.Dir`
|
|
44
|
+
|
|
45
|
+
`std.fs.cwd()`, `std.fs.File`, and `std.fs.selfExePath` are gone (`std.fs` retains only `path` helpers and deprecated aliases). The directory handle is `std.Io.Dir`, and every operation takes `io` right after the receiver:
|
|
46
|
+
|
|
47
|
+
```zig
|
|
48
|
+
const cwd = std.Io.Dir.cwd();
|
|
49
|
+
const content = try cwd.readFileAlloc(io, "app.zon", allocator, .limited(1024 * 1024));
|
|
50
|
+
defer allocator.free(content);
|
|
51
|
+
try cwd.writeFile(io, .{ .sub_path = "out.txt", .data = bytes });
|
|
52
|
+
var file = try cwd.openFile(io, path, .{});
|
|
53
|
+
defer file.close(io);
|
|
54
|
+
try cwd.deleteTree(io, "zig-out/tmp");
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
Note the `readFileAlloc` argument order (`io`, path, allocator, limit) and the size limit as `std.Io.Limit` — `.limited(n)` or `.unlimited`. Live references: `tools/native-sdk/skills.zig` (readFileAlloc), `src/tooling/manifest.zig` (openFile), `src/tooling/cef.zig` tests (writeFile with `std.testing.io`). Path buffers size with `std.Io.Dir.max_path_bytes`. For the executable's own path, `std.fs.selfExePath(&buf)` became `std.process.executablePath(io, &buf)`, returning the length (`tools/native-sdk/skills.zig`).
|
|
58
|
+
|
|
59
|
+
## error: struct 'std' has no member named 'io' — writers are `std.Io.Writer`, stdout is `std.Io.File.stdout()`
|
|
60
|
+
|
|
61
|
+
`std.io.getStdOut().writer()` and `std.io.fixedBufferStream` are gone. Stdout takes `io` plus a caller-owned buffer, and the printable interface lives one field deep:
|
|
62
|
+
|
|
63
|
+
```zig
|
|
64
|
+
var stdout_buffer: [4096]u8 = undefined;
|
|
65
|
+
var stdout_writer = std.Io.File.stdout().writer(io, &stdout_buffer);
|
|
66
|
+
const stdout = &stdout_writer.interface;
|
|
67
|
+
defer stdout.flush() catch {};
|
|
68
|
+
try stdout.print("{s}\n", .{message});
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Forgetting `flush()` means no output — the buffer is yours. `std.debug.print` is unchanged and needs no `io`; prefer it for diagnostics. The `fixedBufferStream` replacement is a fixed writer over a stack buffer, and the written bytes come back from `buffered()`:
|
|
72
|
+
|
|
73
|
+
```zig
|
|
74
|
+
var buf: [256]u8 = undefined;
|
|
75
|
+
var writer = std.Io.Writer.fixed(&buf);
|
|
76
|
+
try writer.print("n={d}", .{42});
|
|
77
|
+
const written = writer.buffered();
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
For building a string of unknown size, use an allocating writer instead of an ArrayList writer: `var w = std.Io.Writer.Allocating.init(allocator); defer w.deinit();` then print through `w.writer` (`src/automation/server.zig`). One-shot formatting still has `std.fmt.bufPrint` and `std.fmt.allocPrint`, unchanged. Functions that accept a writer take `*std.Io.Writer`, not `anytype` (`tools/native-sdk/skills.zig`; fixed-writer reference: `src/tooling/doctor.zig`).
|
|
81
|
+
|
|
82
|
+
## error: struct 'array_list.Aligned(u8,null)' has no member named 'init' — ArrayList is unmanaged
|
|
83
|
+
|
|
84
|
+
`std.ArrayList(T).init(allocator)` is gone; the list no longer stores its allocator. Initialize with `.empty` and pass the allocator to every call that can allocate or free:
|
|
85
|
+
|
|
86
|
+
```zig
|
|
87
|
+
var list: std.ArrayList(u8) = .empty;
|
|
88
|
+
defer list.deinit(allocator);
|
|
89
|
+
try list.append(allocator, 'a');
|
|
90
|
+
try list.appendSlice(allocator, "bc");
|
|
91
|
+
const owned = try list.toOwnedSlice(allocator);
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
This is everywhere in the SDK — `src/tooling/templates.zig` builds every generated file this way, `tools/native-sdk/skills.zig` collects skills this way. Passing a managed-style call (`list.append('a')`) fails with "member function expected 2 argument(s), found 1". `std.StringHashMap`/`std.AutoHashMap` still have managed `.init(allocator)` forms; only explicitly `Unmanaged` maps take `.empty` (`tools/native-sdk/markup_lsp.zig`).
|
|
95
|
+
|
|
96
|
+
## error: invalid format string 's' for type — enums print with `{t}`, format methods with `{f}`
|
|
97
|
+
|
|
98
|
+
`{s}` is for strings only. Enums and tagged unions print their tag name with `{t}` (equivalent to `@tagName`, which also still works):
|
|
99
|
+
|
|
100
|
+
```zig
|
|
101
|
+
std.debug.print("native {t}: `zig build` step failed (exit code {d})\n", .{ verb, code });
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
(`src/tooling/verbs.zig`.) Custom format methods changed shape twice over: the old four-parameter signature no longer compiles (`error: struct 'fmt' has no member named 'FormatOptions'`), and `{}` no longer calls a `format` method at all — it prints the default field dump silently. Declare the 0.16 signature and print with `{f}`:
|
|
105
|
+
|
|
106
|
+
```zig
|
|
107
|
+
pub fn format(self: Point, writer: *std.Io.Writer) std.Io.Writer.Error!void {
|
|
108
|
+
try writer.print("({d},{d})", .{ self.x, self.y });
|
|
109
|
+
}
|
|
110
|
+
// call site
|
|
111
|
+
try writer.print("{f}\n", .{point});
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## error: struct 'time' has no member named 'sleep' / 'milliTimestamp' — clocks live on Io
|
|
115
|
+
|
|
116
|
+
`std.time` keeps only the unit constants (`ns_per_ms`, `ms_per_s`, ...) and epoch helpers. Sleeping and reading clocks take `io` and typed durations:
|
|
117
|
+
|
|
118
|
+
```zig
|
|
119
|
+
try std.Io.sleep(io, std.Io.Duration.fromMilliseconds(50), .awake);
|
|
120
|
+
const now_ns: i128 = std.Io.Timestamp.now(io, .real).nanoseconds;
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
(`src/runtime/automation_liveness_tests.zig`, `src/automation/server.zig`.) In app code, do not reach for either: `native_sdk.nowMs()` / `native_sdk.monotonicMs()` are the facade, `fx.wallMs()` is the journaled read inside `update`, and `model.clock` is the testable seam — the native-ui skill's Time section owns that pattern.
|
|
124
|
+
|
|
125
|
+
## error: struct 'process.Child' has no member named 'init' — spawning is `std.process.spawn(io, ...)`
|
|
126
|
+
|
|
127
|
+
The two-step `Child.init` + `child.spawn()` collapsed into one call, and lifecycle methods take `io`:
|
|
128
|
+
|
|
129
|
+
```zig
|
|
130
|
+
var child = try std.process.spawn(io, .{
|
|
131
|
+
.argv = &.{ "npm", "run", "build" },
|
|
132
|
+
.stdin = .ignore,
|
|
133
|
+
.stdout = .inherit,
|
|
134
|
+
.stderr = .inherit,
|
|
135
|
+
});
|
|
136
|
+
const term = try child.wait(io); // child.kill(io) to stop it
|
|
137
|
+
```
|
|
138
|
+
|
|
139
|
+
(`src/tooling/verbs.zig`, `src/tooling/dev.zig` — the latter also shows passing a custom environment via `.environ_map`.) Inside a UiApp, spawn through the effects channel (`fx.spawn`) instead — it is bounded, journaled, and delivers exit/output as Msgs.
|
|
140
|
+
|
|
141
|
+
## error: struct 'process' has no member named 'getEnvMap' / 'argsAlloc' — environment and args come from Init
|
|
142
|
+
|
|
143
|
+
`std.process.getEnvMap`, `argsAlloc`, and `argsWithAllocator` are gone. `main` already has both: `init.environ_map` (a `*std.process.Environ.Map`) and `init.minimal.args.toSlice(allocator)` (`tools/native-sdk/main.zig`). Building an environment from scratch — for a child process, or in tests — is `var env = std.process.Environ.Map.init(allocator); defer env.deinit(); try env.put("KEY", "value");` (`src/tooling/dev.zig`).
|
|
144
|
+
|
|
145
|
+
## error: struct 'mem' has no member named 'trimRight' / 'trimLeft' — renamed `trimEnd` / `trimStart`
|
|
146
|
+
|
|
147
|
+
The directional trims renamed to match the JS/string convention; arguments are unchanged:
|
|
148
|
+
|
|
149
|
+
```zig
|
|
150
|
+
const line = std.mem.trimEnd(u8, raw, "\r\n"); // was trimRight
|
|
151
|
+
const body = std.mem.trimStart(u8, line, " \t"); // was trimLeft
|
|
152
|
+
const both = std.mem.trim(u8, text, " "); // unchanged
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## error: struct 'std' has no member named 'net' — sockets live on `std.Io.net`
|
|
156
|
+
|
|
157
|
+
`std.net.Address` became `std.Io.net.IpAddress`, and connect/listen take `io`: `std.Io.net.IpAddress.resolve(io, host, port)`, then `IpAddress.connect(&address, io, .{ .mode = .stream, .protocol = .tcp })`; stream readers/writers follow the buffered-writer shape (`std.Io.net.Stream.writer(stream, io, &buffer)` then `.interface`). Live reference: `src/tooling/dev.zig` (`waitUntilReady`/`httpReady`). App-level HTTP belongs in `fx.fetch`, not hand-rolled sockets.
|
|
158
|
+
|
|
159
|
+
## error: no field named 'root_source_file' in struct 'Build.ExecutableOptions' — build.zig artifacts take modules
|
|
160
|
+
|
|
161
|
+
Zero-config apps have no `build.zig` — the CLI owns the build graph, so this only appears in apps that ejected or scaffolded `--full`. Artifacts take a module, and the module owns root source, target, and optimize:
|
|
162
|
+
|
|
163
|
+
```zig
|
|
164
|
+
const exe = b.addExecutable(.{
|
|
165
|
+
.name = "app",
|
|
166
|
+
.root_module = b.createModule(.{
|
|
167
|
+
.root_source_file = b.path("src/main.zig"),
|
|
168
|
+
.target = target,
|
|
169
|
+
.optimize = optimize,
|
|
170
|
+
}),
|
|
171
|
+
});
|
|
172
|
+
const tests = b.addTest(.{ .root_module = app_mod });
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
The generated ejected `build.zig` is the reference shape (`native eject`, emitted by `src/tooling/templates.zig`); the SDK's own `build.zig` uses the same pattern throughout.
|
|
176
|
+
|
|
177
|
+
## Reading files and streams incrementally
|
|
178
|
+
|
|
179
|
+
`file.reader()` with no arguments is gone. A reader takes `io` and a buffer, and the stream interface lives on `.interface`:
|
|
180
|
+
|
|
181
|
+
```zig
|
|
182
|
+
var read_buffer: [4096]u8 = undefined;
|
|
183
|
+
var reader = file.reader(io, &read_buffer);
|
|
184
|
+
const bytes = try reader.interface.allocRemaining(allocator, .limited(1024 * 1024));
|
|
185
|
+
const line = try reader.interface.takeDelimiterExclusive('\n');
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
(`src/tooling/manifest.zig` for allocRemaining, `src/tooling/toolchain.zig` for line reading from stdin.) For whole-file reads, prefer `readFileAlloc` above.
|
|
189
|
+
|
|
190
|
+
## Tests: the Io is `std.testing.io`
|
|
191
|
+
|
|
192
|
+
Tests never construct an `Io` — `std.testing.io` is the canonical one, next to `std.testing.allocator`:
|
|
193
|
+
|
|
194
|
+
```zig
|
|
195
|
+
test "reads the manifest" {
|
|
196
|
+
var tmp = std.testing.tmpDir(.{});
|
|
197
|
+
defer tmp.cleanup();
|
|
198
|
+
try tmp.dir.writeFile(std.testing.io, .{ .sub_path = "app.zon", .data = source });
|
|
199
|
+
const content = try tmp.dir.readFileAlloc(std.testing.io, "app.zon", std.testing.allocator, .limited(4096));
|
|
200
|
+
defer std.testing.allocator.free(content);
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
(`src/tooling/cef.zig` and `src/tooling/manifest.zig` tests.) Model/Msg/update tests need no `Io` at all — the markup-view testing pattern in the native-ui skill is pure.
|
|
205
|
+
|
|
206
|
+
## Unchanged — do not "migrate" these
|
|
207
|
+
|
|
208
|
+
`std.fmt.bufPrint` / `allocPrint` / `parseInt` / `parseFloat`, `std.mem.*`, `std.debug.print`, `std.heap.page_allocator`, `std.time.ns_per_*` and `ms_per_*` constants, `@embedFile`, `std.testing.expect*`, and managed `std.StringHashMap` / `std.AutoHashMap` all work as before. If code using only these fails, the problem is elsewhere.
|
|
@@ -19,7 +19,7 @@ native skills get core
|
|
|
19
19
|
native skills get core --full
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
Use `native skills get core` for initial orientation. Use `native skills get core --full` for implementation tasks because it includes the reference files for project anatomy, runtime, frontend assets, bridge/security/native capabilities, packaging, and debugging. Use `native skills get automation` when testing a running app, taking snapshots, requesting reloads, or using the built-in automation server.
|
|
22
|
+
Use `native skills get core` for initial orientation. Use `native skills get core --full` for implementation tasks because it includes the reference files for project anatomy, runtime, frontend assets, bridge/security/native capabilities, packaging, and debugging. Use `native skills get automation` when testing a running app, taking snapshots, requesting reloads, or using the built-in automation server. Use `native skills get zig` when `zig build` fails with "no member named" errors on std APIs — the SDK requires Zig 0.16.0, and that skill maps each pre-0.16 idiom's compile error to the current one.
|
|
23
23
|
|
|
24
24
|
## Quick orientation
|
|
25
25
|
|
package/src/app_runner/root.zig
CHANGED
|
@@ -254,17 +254,78 @@ pub fn manifestThemePack() native_sdk.canvas.ThemePack {
|
|
|
254
254
|
@compileError("unknown app.zon theme \"" ++ name ++ "\" — expected one of: house, geist");
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
-
///
|
|
258
|
-
///
|
|
259
|
-
///
|
|
260
|
-
///
|
|
257
|
+
/// The manifest's ONE-accent brand override (`theme_accent = "#df2670"`),
|
|
258
|
+
/// resolved at comptime so a malformed value is a build error naming the
|
|
259
|
+
/// field — never a silent fallback. Absent means the pack's own accent.
|
|
260
|
+
/// Apps hand this to their `UiApp` options' `theme_accent` field; the
|
|
261
|
+
/// runtime layers `canvas.accentOverrides` over the resolved pack (and
|
|
262
|
+
/// skips it under high contrast — accessibility beats brand).
|
|
263
|
+
pub fn manifestThemeAccent() ?native_sdk.canvas.Color {
|
|
264
|
+
if (comptime !@hasField(@TypeOf(app_manifest), "theme_accent")) return null;
|
|
265
|
+
const value: []const u8 = app_manifest.theme_accent;
|
|
266
|
+
return comptime parseHexColor(value) orelse
|
|
267
|
+
@compileError("invalid app.zon theme_accent \"" ++ value ++ "\" — expected a #rrggbb hex color");
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
fn parseHexColor(comptime value: []const u8) ?native_sdk.canvas.Color {
|
|
271
|
+
comptime {
|
|
272
|
+
if (value.len != 7 or value[0] != '#') return null;
|
|
273
|
+
var channels: [3]u8 = undefined;
|
|
274
|
+
for (&channels, 0..) |*channel, index| {
|
|
275
|
+
channel.* = std.fmt.parseInt(u8, value[1 + index * 2 .. 3 + index * 2], 16) catch return null;
|
|
276
|
+
}
|
|
277
|
+
return native_sdk.canvas.Color.rgb8(channels[0], channels[1], channels[2]);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
/// Whether app.zon declares web content — the shared declare-to-use
|
|
282
|
+
/// contract (`native_sdk.app_manifest.web_layer`) over the comptime
|
|
283
|
+
/// manifest import: a `.frontend` block, the `"webview"` capability, a
|
|
284
|
+
/// `.shell` webview view, or `.web_engine = "chromium"`. Hosts build
|
|
285
|
+
/// honest default menus from this — web items like Reload only exist
|
|
286
|
+
/// when a webview can answer them, so canvas-only apps never ship dead
|
|
287
|
+
/// menu items.
|
|
261
288
|
fn manifestHasWebContent() bool {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
289
|
+
return manifestWebDeclaration() != null;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/// The first web declaration visible in app.zon, evaluated at comptime.
|
|
293
|
+
/// The engine input here is the MANIFEST engine: the runner never sees
|
|
294
|
+
/// the `-Dweb-engine` flag, so an engine resolved to Chromium by flag
|
|
295
|
+
/// alone is out of this boundary's reach — the standard build graph
|
|
296
|
+
/// (build/app.zig), which does see the flag, owns that configure-time
|
|
297
|
+
/// error. See the contract's module doc for the full ownership split.
|
|
298
|
+
fn manifestWebDeclaration() ?native_sdk.app_manifest.web_layer.Declaration {
|
|
299
|
+
const engine: native_sdk.app_manifest.WebEngine = comptime blk: {
|
|
300
|
+
if (!@hasField(@TypeOf(app_manifest), "web_engine")) break :blk .system;
|
|
301
|
+
break :blk native_sdk.app_manifest.web_layer.parseWebEngine(app_manifest.web_engine) orelse .system;
|
|
302
|
+
};
|
|
303
|
+
return comptime native_sdk.app_manifest.web_layer.webDeclaration(app_manifest, engine);
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/// Whether this build ships the embedded web layer. The standard build
|
|
307
|
+
/// graph (build/app.zig) infers it from app.zon and passes it through
|
|
308
|
+
/// build options; an options module from an older hand-rolled build.zig
|
|
309
|
+
/// that predates the option keeps the layer — over-inclusion is safe.
|
|
310
|
+
fn webLayerEnabled() bool {
|
|
311
|
+
if (comptime !@hasDecl(build_options, "web_layer")) return true;
|
|
312
|
+
return build_options.web_layer;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
// The runner-side half of the reject-conflicts contract: a build that
|
|
316
|
+
// excludes the web layer while app.zon declares web use must fail at
|
|
317
|
+
// compile time here too, so a hand-rolled build graph that bypasses the
|
|
318
|
+
// standard configure-time error still cannot ship an app whose declared
|
|
319
|
+
// webviews would fail at runtime. The guard covers every declaration
|
|
320
|
+
// visible in the manifest; only a Chromium engine resolved from the
|
|
321
|
+
// `-Dweb-engine` flag is invisible here, and that conflict is already a
|
|
322
|
+
// configure-time error in the graph that resolved the flag.
|
|
323
|
+
comptime {
|
|
324
|
+
if (!webLayerEnabled()) {
|
|
325
|
+
if (manifestWebDeclaration()) |declaration| {
|
|
326
|
+
@compileError("this build excludes the web layer (-Dweb-layer=exclude or a custom build graph) but app.zon declares web use (" ++ declaration.text() ++ "); remove the exclude or drop the web declaration");
|
|
327
|
+
}
|
|
266
328
|
}
|
|
267
|
-
return false;
|
|
268
329
|
}
|
|
269
330
|
|
|
270
331
|
fn windowLabel(comptime window: anytype, comptime index: usize) []const u8 {
|
|
@@ -374,6 +435,7 @@ fn runNull(app: native_sdk.App, options: RunOptions, init: std.process.Init) !vo
|
|
|
374
435
|
.bridge = options.bridge,
|
|
375
436
|
.builtin_bridge = options.builtin_bridge,
|
|
376
437
|
.js_window_api = options.js_window_api,
|
|
438
|
+
.web_layer = webLayerEnabled(),
|
|
377
439
|
.gpu_surface_frame_diagnostics = false,
|
|
378
440
|
.security = options.security,
|
|
379
441
|
.menus = options.menus,
|
|
@@ -428,6 +490,7 @@ fn runMacos(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
|
|
|
428
490
|
.bridge = options.bridge,
|
|
429
491
|
.builtin_bridge = options.builtin_bridge,
|
|
430
492
|
.js_window_api = options.js_window_api,
|
|
493
|
+
.web_layer = webLayerEnabled(),
|
|
431
494
|
.gpu_surface_frame_diagnostics = false,
|
|
432
495
|
.security = options.security,
|
|
433
496
|
.menus = options.menus,
|
|
@@ -479,6 +542,7 @@ fn runLinux(app: native_sdk.App, options: RunOptions, init: std.process.Init) !v
|
|
|
479
542
|
.bridge = options.bridge,
|
|
480
543
|
.builtin_bridge = options.builtin_bridge,
|
|
481
544
|
.js_window_api = options.js_window_api,
|
|
545
|
+
.web_layer = webLayerEnabled(),
|
|
482
546
|
.gpu_surface_frame_diagnostics = false,
|
|
483
547
|
.security = options.security,
|
|
484
548
|
.menus = options.menus,
|
|
@@ -529,6 +593,7 @@ fn runWindows(app: native_sdk.App, options: RunOptions, init: std.process.Init)
|
|
|
529
593
|
.bridge = options.bridge,
|
|
530
594
|
.builtin_bridge = options.builtin_bridge,
|
|
531
595
|
.js_window_api = options.js_window_api,
|
|
596
|
+
.web_layer = webLayerEnabled(),
|
|
532
597
|
.gpu_surface_frame_diagnostics = false,
|
|
533
598
|
.security = options.security,
|
|
534
599
|
.menus = options.menus,
|
|
@@ -643,6 +708,7 @@ fn runSessionReplay(app: native_sdk.App, options: RunOptions, init: std.process.
|
|
|
643
708
|
.bridge = options.bridge,
|
|
644
709
|
.builtin_bridge = options.builtin_bridge,
|
|
645
710
|
.js_window_api = options.js_window_api,
|
|
711
|
+
.web_layer = webLayerEnabled(),
|
|
646
712
|
.security = options.security,
|
|
647
713
|
.menus = options.menus,
|
|
648
714
|
});
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
//! The generated wiring for a TypeScript app core — staged (never written
|
|
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, copies the
|
|
4
|
+
//! app's src/app.native beside it too, and roots the app module here. The
|
|
5
|
+
//! app tree stays three files of truth — core.ts (logic), app.native
|
|
6
|
+
//! (view), app.zon (manifest) — and every value below derives from them at
|
|
7
|
+
//! comptime:
|
|
8
|
+
//!
|
|
9
|
+
//! scene / canvas app.zon's `.shell` through `shellConfigFrom`; the
|
|
10
|
+
//! canvas is the scene's first gpu_surface view.
|
|
11
|
+
//! identity app.zon's `.id`/`.name`/`.display_name`.
|
|
12
|
+
//! security app.zon's `.permissions` and navigation origins.
|
|
13
|
+
//! theme app.zon's `.theme` pack; the stock tokens compose
|
|
14
|
+
//! it with the live system appearance. `.theme_accent`
|
|
15
|
+
//! layers the manifest's one-accent brand override
|
|
16
|
+
//! (`canvas.accentOverrides`) over the pack.
|
|
17
|
+
//! audio cache the platform caches directory (app_dirs `.cache`),
|
|
18
|
+
//! resolved at launch so a core's URL audio playback
|
|
19
|
+
//! caches under the conventional content-addressed
|
|
20
|
+
//! path with no `cachePath` in the core.
|
|
21
|
+
//! update loop the transpiled core through `TsUiApp(core)` — the
|
|
22
|
+
//! committed TS model IS the app model.
|
|
23
|
+
//! view app.native over the model's own field names (the
|
|
24
|
+
//! emitted Zig keeps the TS spellings), hot-reloaded
|
|
25
|
+
//! from src/app.native in Debug.
|
|
26
|
+
//! menus/shortcuts a core exporting `commandMsg(name): Msg | null`
|
|
27
|
+
//! receives command events (menus, shortcuts, chrome
|
|
28
|
+
//! tabs) as ordinary Msgs; without the export command
|
|
29
|
+
//! events stay host-handled only.
|
|
30
|
+
//! host events the adapter wires the core's opt-in channels from
|
|
31
|
+
//! its exports (export exists -> wired): `frameMsg`
|
|
32
|
+
//! (presented frames), `keyMsg` (the app-level key
|
|
33
|
+
//! fallback), `appearanceMsg`/`chromeMsg` (Msg arms
|
|
34
|
+
//! the host fills structurally).
|
|
35
|
+
//! images app.zon's `.assets.images` entries (`.{ .id = 1,
|
|
36
|
+
//! .path = "assets/..." }`) are read once at launch
|
|
37
|
+
//! and registered on the installing frame — the ids
|
|
38
|
+
//! are the `ImageId`s markup avatar bindings use. A
|
|
39
|
+
//! missing file or failed decode skips the entry
|
|
40
|
+
//! (views keep the initials fallback).
|
|
41
|
+
//! environment a core exporting `envMsgs` receives each named
|
|
42
|
+
//! variable present at launch as one journaled Msg on
|
|
43
|
+
//! its bytes arm, right after the boot command — the
|
|
44
|
+
//! core itself never reads the environment (NS1005),
|
|
45
|
+
//! and replay carries the recorded values.
|
|
46
|
+
//!
|
|
47
|
+
//! Editing this file is never core-level work: it carries no app logic and
|
|
48
|
+
//! regenerates from the SDK on every build.
|
|
49
|
+
|
|
50
|
+
const std = @import("std");
|
|
51
|
+
const runner = @import("runner");
|
|
52
|
+
const native_sdk = @import("native_sdk");
|
|
53
|
+
const manifest = @import("app_manifest_zon");
|
|
54
|
+
pub const core = @import("core.zig");
|
|
55
|
+
|
|
56
|
+
pub const panic = std.debug.FullPanic(native_sdk.debug.capturePanic);
|
|
57
|
+
|
|
58
|
+
/// Re-exported so the model-contract step (and any test) reflects the
|
|
59
|
+
/// core's real surface: `native check` verifies app.native against it.
|
|
60
|
+
pub const Model = core.Model;
|
|
61
|
+
pub const Msg = core.Msg;
|
|
62
|
+
|
|
63
|
+
const Adapter = native_sdk.TsUiApp(core);
|
|
64
|
+
const App = Adapter.App;
|
|
65
|
+
|
|
66
|
+
const shell_scene = native_sdk.app_manifest.shellConfigFrom(manifest);
|
|
67
|
+
const canvas_label = native_sdk.app_manifest.firstGpuSurfaceLabel(shell_scene);
|
|
68
|
+
pub const app_markup = @embedFile("app.native");
|
|
69
|
+
|
|
70
|
+
const app_permissions = manifestStringList(manifest, "permissions");
|
|
71
|
+
const allowed_origins = manifestAllowedOrigins();
|
|
72
|
+
|
|
73
|
+
pub fn main(init: std.process.Init) !void {
|
|
74
|
+
var options: Adapter.Options = .{
|
|
75
|
+
.name = manifest.name,
|
|
76
|
+
.scene = shell_scene,
|
|
77
|
+
.canvas_label = canvas_label,
|
|
78
|
+
.markup = .{ .source = app_markup, .watch_path = "src/app.native", .io = init.io },
|
|
79
|
+
// app.zon's theme pack; unthemed manifests get the house register.
|
|
80
|
+
// The stock tokens compose the pack with the LIVE system
|
|
81
|
+
// appearance, so TS apps follow the OS light/dark flip with no
|
|
82
|
+
// core code. `theme_accent` is the manifest's one-accent brand
|
|
83
|
+
// override, layered over the pack by the runtime (skipped under
|
|
84
|
+
// high contrast — accessibility beats brand).
|
|
85
|
+
.theme = comptime runner.manifestThemePack(),
|
|
86
|
+
.theme_accent = comptime runner.manifestThemeAccent(),
|
|
87
|
+
};
|
|
88
|
+
if (comptime @hasDecl(core, "commandMsg")) {
|
|
89
|
+
// Menus, shortcuts, and chrome tabs dispatch through the core's
|
|
90
|
+
// exported command mapper.
|
|
91
|
+
options.on_command = core.commandMsg;
|
|
92
|
+
}
|
|
93
|
+
// The platform caches directory for this app: when the core's
|
|
94
|
+
// `Cmd.audioPlay` names a URL with no cachePath, the bridge derives
|
|
95
|
+
// the conventional content-addressed path under this directory —
|
|
96
|
+
// resolved once at launch (never inside update), so replay's
|
|
97
|
+
// deterministic-init contract holds. Resolution failure just disables
|
|
98
|
+
// the cache: streams still play, they re-download.
|
|
99
|
+
var cache_dir_buffer: [512]u8 = undefined;
|
|
100
|
+
const audio_cache_dir = native_sdk.app_dirs.resolveOne(
|
|
101
|
+
.{ .name = manifest.name },
|
|
102
|
+
native_sdk.app_dirs.currentPlatform(),
|
|
103
|
+
native_sdk.debug.envFromMap(init.environ_map),
|
|
104
|
+
.cache,
|
|
105
|
+
&cache_dir_buffer,
|
|
106
|
+
) catch "";
|
|
107
|
+
// app.zon-declared images, read once at launch (bounded; a missing or
|
|
108
|
+
// over-bound file skips its entry and the views keep their fallback)
|
|
109
|
+
// and registered by the adapter on the installing frame.
|
|
110
|
+
const manifest_images = comptime manifestImages();
|
|
111
|
+
var boot_images_buffer: [manifest_images.len]Adapter.BootImage = undefined;
|
|
112
|
+
var boot_image_count: usize = 0;
|
|
113
|
+
inline for (manifest_images) |asset| {
|
|
114
|
+
if (std.Io.Dir.cwd().readFileAlloc(init.io, asset.path, std.heap.page_allocator, .limited(max_boot_image_bytes))) |bytes| {
|
|
115
|
+
boot_images_buffer[boot_image_count] = .{ .id = asset.id, .bytes = bytes };
|
|
116
|
+
boot_image_count += 1;
|
|
117
|
+
} else |_| {}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// The core's launch-time environment channel (`envMsgs`): read each
|
|
121
|
+
// named variable once, here at the boundary — never inside update —
|
|
122
|
+
// and hand the present values to the adapter, which dispatches them
|
|
123
|
+
// as ordinary journaled Msgs right after the boot command.
|
|
124
|
+
var env_values_buffer: [envMsgsLen()]Adapter.EnvValue = undefined;
|
|
125
|
+
var env_value_count: usize = 0;
|
|
126
|
+
if (comptime @hasDecl(core, "envMsgs")) {
|
|
127
|
+
inline for (core.envMsgs) |entry| {
|
|
128
|
+
if (init.environ_map.get(entry.env)) |value| {
|
|
129
|
+
env_values_buffer[env_value_count] = .{ .msg = entry.msg, .value = value };
|
|
130
|
+
env_value_count += 1;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
// The app struct (and any real model) is multi-MB: `create`
|
|
136
|
+
// heap-allocates and constructs in place, so neither rides the stack.
|
|
137
|
+
const app_state = try Adapter.create(std.heap.page_allocator, .{
|
|
138
|
+
.audio_cache_dir = audio_cache_dir,
|
|
139
|
+
.boot_images = boot_images_buffer[0..boot_image_count],
|
|
140
|
+
.env_values = env_values_buffer[0..env_value_count],
|
|
141
|
+
}, options);
|
|
142
|
+
defer app_state.destroy();
|
|
143
|
+
|
|
144
|
+
try runner.runWithOptions(app_state.app(), .{
|
|
145
|
+
.app_name = manifest.name,
|
|
146
|
+
.window_title = comptime windowTitle(),
|
|
147
|
+
.bundle_id = manifest.id,
|
|
148
|
+
.icon_path = "assets/icon.png",
|
|
149
|
+
.default_frame = comptime defaultFrame(),
|
|
150
|
+
.restore_state = comptime startupRestoreState(),
|
|
151
|
+
.js_window_api = false,
|
|
152
|
+
.security = .{
|
|
153
|
+
.permissions = app_permissions,
|
|
154
|
+
.navigation = .{ .allowed_origins = allowed_origins },
|
|
155
|
+
},
|
|
156
|
+
}, init);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/// The startup window title: the scene's first window title, else the
|
|
160
|
+
/// manifest display name, else the app name.
|
|
161
|
+
fn windowTitle() []const u8 {
|
|
162
|
+
if (shell_scene.windows.len > 0) {
|
|
163
|
+
if (shell_scene.windows[0].title) |title| return title;
|
|
164
|
+
}
|
|
165
|
+
if (@hasField(@TypeOf(manifest), "display_name")) return manifest.display_name;
|
|
166
|
+
return manifest.name;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
fn defaultFrame() native_sdk.geometry.RectF {
|
|
170
|
+
if (shell_scene.windows.len > 0) {
|
|
171
|
+
const window = shell_scene.windows[0];
|
|
172
|
+
return native_sdk.geometry.RectF.init(window.x orelse 0, window.y orelse 0, window.width, window.height);
|
|
173
|
+
}
|
|
174
|
+
return native_sdk.geometry.RectF.init(0, 0, 720, 480);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
fn startupRestoreState() bool {
|
|
178
|
+
if (shell_scene.windows.len > 0) return shell_scene.windows[0].restore_state;
|
|
179
|
+
return true;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
/// One app.zon `.assets.images` entry: the encoded file the wiring reads
|
|
183
|
+
/// at launch and the `ImageId` markup avatar bindings reference.
|
|
184
|
+
const ImageAsset = struct {
|
|
185
|
+
id: u64,
|
|
186
|
+
path: []const u8,
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
/// Encoded-size bound for one boot image: over-bound files skip their
|
|
190
|
+
/// entry (the views keep the initials fallback) instead of holding the
|
|
191
|
+
/// launch path hostage to a mis-sized asset.
|
|
192
|
+
const max_boot_image_bytes: usize = 4 * 1024 * 1024;
|
|
193
|
+
|
|
194
|
+
fn manifestImages() []const ImageAsset {
|
|
195
|
+
comptime {
|
|
196
|
+
if (!@hasField(@TypeOf(manifest), "assets")) return &.{};
|
|
197
|
+
if (!@hasField(@TypeOf(manifest.assets), "images")) return &.{};
|
|
198
|
+
var out: []const ImageAsset = &.{};
|
|
199
|
+
for (manifest.assets.images) |entry| {
|
|
200
|
+
out = out ++ &[_]ImageAsset{.{ .id = entry.id, .path = entry.path }};
|
|
201
|
+
}
|
|
202
|
+
return out;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
fn envMsgsLen() usize {
|
|
207
|
+
comptime {
|
|
208
|
+
if (!@hasDecl(core, "envMsgs")) return 0;
|
|
209
|
+
return core.envMsgs.len;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
fn manifestStringList(comptime m: anytype, comptime field: []const u8) []const []const u8 {
|
|
214
|
+
comptime {
|
|
215
|
+
if (!@hasField(@TypeOf(m), field)) return &.{};
|
|
216
|
+
var out: []const []const u8 = &.{};
|
|
217
|
+
for (@field(m, field)) |entry| {
|
|
218
|
+
const name: []const u8 = entry;
|
|
219
|
+
out = out ++ &[_][]const u8{name};
|
|
220
|
+
}
|
|
221
|
+
return out;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
fn manifestAllowedOrigins() []const []const u8 {
|
|
226
|
+
comptime {
|
|
227
|
+
if (!@hasField(@TypeOf(manifest), "security")) return &.{};
|
|
228
|
+
if (!@hasField(@TypeOf(manifest.security), "navigation")) return &.{};
|
|
229
|
+
return manifestStringList(manifest.security.navigation, "allowed_origins");
|
|
230
|
+
}
|
|
231
|
+
}
|