@native-sdk/cli 0.9.0 → 0.9.1
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 +331 -24
- package/build.zig +179 -11
- package/native-sdk.d.ts +8 -0
- package/package.json +10 -10
- package/packages/core/compile-surface/core.ts +70 -1
- package/packages/core/package-lock.json +11 -11
- package/packages/core/package.json +2 -2
- package/packages/core/scripts/merge_static_archives.mjs +78 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +52 -7
- package/packages/core/scripts/run_external_service_compiler.mjs +53 -13
- package/packages/core/scripts/stage_external_services.mjs +1 -1
- package/packages/core/sdk/core.d.ts +75 -0
- package/packages/core/sdk/core.ts +167 -12
- package/packages/core/sdk/events.d.ts +53 -0
- package/packages/core/sdk/events.ts +78 -7
- package/packages/core/src/checker.ts +470 -2
- package/packages/core/src/cli.ts +13 -0
- package/packages/core/src/contract.ts +3 -1
- package/packages/core/src/devhost.ts +30 -1
- package/packages/core/src/devhost_journal.mjs +10 -8
- package/packages/core/src/diagnostics.ts +99 -8
- package/packages/core/src/frontend.ts +6 -0
- package/packages/core/src/infer.ts +24 -0
- package/skill-data/automation/SKILL.md +1 -1
- package/skill-data/native-ui/SKILL.md +11 -5
- package/skill-data/ts-core/SKILL.md +53 -20
- package/skill-data/ts-services/SKILL.md +4 -4
- package/skill-data/ts-services/references/service-surface.md +2 -1
- package/skill-data/zig/SKILL.md +1 -1
- package/src/app_runner/root.zig +29 -0
- package/src/app_runner/ts_core_main.zig +5 -0
- package/src/app_runner/ts_core_mobile.zig +241 -0
- package/src/automation/protocol.zig +5 -1
- package/src/automation/snapshot.zig +8 -6
- package/src/embed/app_exports.zig +1 -0
- package/src/embed/root.zig +1 -0
- package/src/embed/tests.zig +28 -0
- package/src/embed/ui_host.zig +68 -2
- package/src/platform/linux/cef_host.cpp +7 -1
- package/src/platform/linux/gtk_host.c +200 -5
- package/src/platform/linux/gtk_host.h +2 -1
- package/src/platform/linux/root.zig +69 -4
- package/src/platform/macos/appkit_host.h +11 -7
- package/src/platform/macos/appkit_host.m +210 -88
- package/src/platform/macos/cef_host.mm +210 -88
- package/src/platform/macos/root.zig +77 -30
- package/src/platform/null_platform.zig +234 -51
- package/src/platform/null_platform_tests.zig +39 -0
- package/src/platform/root.zig +10 -0
- package/src/platform/types.zig +105 -16
- package/src/platform/windows/root.zig +20 -6
- package/src/platform/windows/webview2_host.cpp +41 -5
- package/src/root.zig +7 -0
- package/src/runtime/api.zig +8 -0
- package/src/runtime/automation_commands.zig +35 -2
- package/src/runtime/automation_snapshot.zig +32 -24
- package/src/runtime/bridge_permission_tests.zig +35 -1
- package/src/runtime/bridge_responses.zig +1 -1
- package/src/runtime/builtin_bridge.zig +11 -1
- package/src/runtime/core.zig +12 -6
- package/src/runtime/effects.zig +1323 -35
- package/src/runtime/effects_file_tests.zig +587 -0
- package/src/runtime/effects_notification_tests.zig +11 -0
- package/src/runtime/file_access.zig +400 -0
- package/src/runtime/file_effect_crash_helper.zig +28 -0
- package/src/runtime/file_effect_crash_tests.zig +37 -0
- package/src/runtime/flow.zig +21 -9
- package/src/runtime/native_command_event_tests.zig +44 -2
- package/src/runtime/pty.zig +5 -2
- package/src/runtime/root.zig +5 -0
- package/src/runtime/session_blobs.zig +4 -1
- package/src/runtime/session_journal.zig +56 -5
- package/src/runtime/session_record.zig +38 -0
- package/src/runtime/session_replay.zig +97 -7
- package/src/runtime/session_tests.zig +81 -0
- package/src/runtime/state.zig +10 -0
- package/src/runtime/system_services.zig +129 -36
- package/src/runtime/ts_core_host.zig +281 -11
- package/src/runtime/ts_core_host_tests.zig +95 -1
- package/src/runtime/ts_ui_app.zig +461 -8
- package/src/runtime/ui_app.zig +321 -109
- package/src/runtime/ui_app_tests.zig +132 -6
- package/src/runtime/ui_app_window_tests.zig +61 -7
- package/src/runtime/validation.zig +20 -0
- package/src/tooling/templates.zig +28 -0
- package/src/tooling/ts_core.zig +83 -0
- package/tools/corewire/emit.zig +3 -3
- package/tools/corewire/emit_facade.zig +65 -5
- package/tools/corewire/emit_profile.zig +2 -2
- package/tools/corewire/emit_service.zig +2 -2
- package/tools/corewire/service_contract.zig +4 -4
- package/tools/corewire/sidecar.zig +4 -4
|
@@ -3,8 +3,10 @@ import fs from "node:fs";
|
|
|
3
3
|
// Kept in lockstep with `zig build print-pins`; the Node test suite checks
|
|
4
4
|
// both values so a runtime wire change cannot silently strand dev-host
|
|
5
5
|
// recordings.
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
// EffectFileOp appended `delete`; the reflected journal layout fingerprint
|
|
7
|
+
// moves so older recordings refuse cleanly instead of decoding op 8 wrongly.
|
|
8
|
+
export const journalFormatFingerprint = 0xb3bd2e83971de44dn;
|
|
9
|
+
export const automationProtocolFingerprint = 0x59d66f39803fd602n;
|
|
8
10
|
|
|
9
11
|
const requestKeyBase = 0x5453525100000000n;
|
|
10
12
|
const textEncoder = new TextEncoder();
|
|
@@ -39,10 +41,10 @@ function defaultEffect(kind, key, payload, options = {}) {
|
|
|
39
41
|
return concat([
|
|
40
42
|
new Uint8Array([kind]), u64(key), stringBytes(payload), stringBytes(new Uint8Array(0)),
|
|
41
43
|
new Uint8Array([0]), u32(options.dropped ?? 0), i32(options.code ?? 0), new Uint8Array([0, 0, 0]), u16(0),
|
|
42
|
-
// fetch outcome
|
|
43
|
-
new Uint8Array([0, 0, 0, 1, 0]), u64(0), new Uint8Array([0]), i64(0),
|
|
44
|
-
// audio defaults: position, zero timing/state
|
|
45
|
-
new Uint8Array([1]), u64(0), u64(0), new Uint8Array([0, 0]), new Uint8Array(32),
|
|
44
|
+
// fetch outcome; file op/event/outcome + total/mtime/exists; clipboard op/outcome; timer outcome
|
|
45
|
+
new Uint8Array([0, 0, 0, 0]), u64(0), i64(0), new Uint8Array([0, 0, 1, 0]), u64(0), new Uint8Array([0]), i64(0),
|
|
46
|
+
// audio defaults: position, zero timing/state; file blob address; 32 zero bands
|
|
47
|
+
new Uint8Array([1]), u64(0), u64(0), new Uint8Array([0, 0]), new Uint8Array(16), u64(0), new Uint8Array(32),
|
|
46
48
|
// image defaults + 16-byte blob hash
|
|
47
49
|
new Uint8Array([0]), u64(0), u64(0), new Uint8Array(16), u64(0),
|
|
48
50
|
// channel event + cumulative drops
|
|
@@ -121,8 +123,8 @@ function decodeEffect(payload) {
|
|
|
121
123
|
const dropped = r.u32();
|
|
122
124
|
const code = r.i32();
|
|
123
125
|
r.byte(); r.byte(); r.byte(); r.u16();
|
|
124
|
-
r.byte(); r.byte(); r.byte(); r.byte(); r.byte(); r.u64(); r.byte(); r.i64();
|
|
125
|
-
r.byte(); r.u64(); r.u64(); r.byte(); r.byte(); r.take(32);
|
|
126
|
+
r.byte(); r.byte(); r.byte(); r.byte(); r.u64(); r.i64(); r.byte(); r.byte(); r.byte(); r.byte(); r.u64(); r.byte(); r.i64();
|
|
127
|
+
r.byte(); r.u64(); r.u64(); r.byte(); r.byte(); r.take(16); r.u64(); r.take(32);
|
|
126
128
|
r.byte(); r.u64(); r.u64(); r.take(16); r.u64();
|
|
127
129
|
const channelKind = r.byte();
|
|
128
130
|
const channelDroppedTotal = r.u32();
|
|
@@ -13,12 +13,20 @@ export interface SubsetDiagnostic {
|
|
|
13
13
|
readonly column: number; // 1-based
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
+
/// Every rule is one of two classes. A `guarantee` rule protects a core
|
|
17
|
+
/// invariant — determinism and replay, fixed shapes, immutability of shared
|
|
18
|
+
/// data, the one text representation — and is permanent. A `deferred` rule
|
|
19
|
+
/// bans nothing the invariants require; the capability waits on a deliberate
|
|
20
|
+
/// easing decision, and its diagnostic says so.
|
|
21
|
+
export type RuleClass = "guarantee" | "deferred";
|
|
22
|
+
|
|
16
23
|
export interface RuleCopy {
|
|
17
24
|
readonly id: string;
|
|
18
25
|
readonly title: string;
|
|
19
26
|
/// `fix` and `why` are joined after the site-specific lead-in.
|
|
20
27
|
readonly fix: string;
|
|
21
28
|
readonly why: string;
|
|
29
|
+
readonly class: RuleClass;
|
|
22
30
|
}
|
|
23
31
|
|
|
24
32
|
export const rules = {
|
|
@@ -27,444 +35,525 @@ export const rules = {
|
|
|
27
35
|
title: "shared data is immutable; your own scratch is yours",
|
|
28
36
|
fix: "Build the next value instead (`{ ...model, tasks: [...model.tasks, task] }`), or take a copy you own first (`const copy = xs.slice();`) — arrays this function creates itself (literals, `.slice()`/`.map()`/`.filter()`/`.concat()`/`.toSorted()` copies) mutate freely until they escape, `xs[xs.length] = v` appends like `.push`, a `let` whose EVERY assignment is a fresh construction stays owned, and passing to a `readonly T[]` parameter of a reading helper keeps ownership.",
|
|
29
37
|
why: "The previous model stays live for rendering and undo, and a caller's array outlives the call; native builds share unchanged parts without copying, so the immutable style is not slower — while a locally-created array has exactly one holder, which is what makes mutating it deterministic and safe.",
|
|
38
|
+
class: "guarantee",
|
|
30
39
|
},
|
|
31
40
|
NS1002: {
|
|
32
41
|
id: "NS1002",
|
|
33
42
|
title: "updates are synchronous",
|
|
34
|
-
fix: "Return the work as a command: `[model, Cmd.host(\"fetch_profile\", userId)]
|
|
43
|
+
fix: "Return the work as a command: `[model, Cmd.host(\"fetch_profile\", userId)]`; network and other ordinary async work runs in a `src/services/` module called through its generated `@native-sdk/services` client.",
|
|
35
44
|
why: "The runtime performs the effect after commit and dispatches your message with the result.",
|
|
45
|
+
class: "guarantee",
|
|
36
46
|
},
|
|
37
47
|
NS1003: {
|
|
38
48
|
id: "NS1003",
|
|
39
49
|
title: "models hold data, not functions",
|
|
40
50
|
fix: "Name the behavior as a message (`{ kind: \"tick\" }`) and handle it in update.",
|
|
41
51
|
why: "The model is data; commit walkers cannot (and should not) copy closures.",
|
|
52
|
+
class: "guarantee",
|
|
42
53
|
},
|
|
43
54
|
NS1004: {
|
|
44
55
|
id: "NS1004",
|
|
45
56
|
title: "text is not indexable",
|
|
46
57
|
fix: "Store text as `Uint8Array` bytes and index those; turn user-visible literals/templates into bytes with `utf8Bytes` from \"@native-sdk/core\" (`asciiBytes` is the narrower machine-text form).",
|
|
47
58
|
why: "Code-unit reads behave differently in JS (UTF-16) and native (UTF-8); with them gone the encodings are indistinguishable.",
|
|
59
|
+
class: "guarantee",
|
|
48
60
|
},
|
|
49
61
|
NS1005: {
|
|
50
62
|
id: "NS1005",
|
|
51
63
|
title: "update is deterministic",
|
|
52
|
-
fix: "Take the value as input instead: time via `[model, Cmd.now(\"tick\")]`; randomness rides in as a Msg payload from the host.",
|
|
64
|
+
fix: "Take the value as input instead: time via `[model, Cmd.now(\"tick\")]`; randomness rides in as a Msg payload from the host; a `src/services/` module may read the clock directly and return the value as a Msg.",
|
|
53
65
|
why: "Ambient time, randomness, and I/O make replay and testing lie.",
|
|
66
|
+
class: "guarantee",
|
|
54
67
|
},
|
|
55
68
|
NS1006: {
|
|
56
69
|
id: "NS1006",
|
|
57
70
|
title: "classes are data classes, declared at module level",
|
|
58
71
|
fix: "Declare the class at module level — annotated fields, one constructor, plain methods (`class Task { title: Uint8Array; constructor(...) {...} rename(...) {...} }`) — and construct it with `new Task(...)`; everything else stays records and functions.",
|
|
59
72
|
why: "A data class emits as a plain struct plus module-level functions; a class expression, a `this` outside a member body, or `new` of an arbitrary expression would need runtime prototypes and object identity the fixed native layout does not carry.",
|
|
73
|
+
class: "guarantee",
|
|
60
74
|
},
|
|
61
75
|
NS1007: {
|
|
62
76
|
id: "NS1007",
|
|
63
77
|
title: "implicit builtin throws stay out",
|
|
64
78
|
fix: "Give the operation its explicit form (`.reduce(f, init)` — the starting accumulator makes the empty array well-defined); your own `throw` of a subset value is supported, deterministic control flow.",
|
|
65
79
|
why: "JS builtins throw engine TypeError objects mid-operation; a user `throw` carries a subset value the native payload slot can hold, but a builtin's implicit throw has no such value and no native mapping.",
|
|
80
|
+
class: "guarantee",
|
|
66
81
|
},
|
|
67
82
|
NS1008: {
|
|
68
83
|
id: "NS1008",
|
|
69
84
|
title: "only erasable TypeScript syntax compiles",
|
|
70
85
|
fix: "Replace `enum` with a string-literal union; drop namespaces, decorators, and parameter properties.",
|
|
71
86
|
why: "The same file must run unmodified under node (`erasableSyntaxOnly`); these constructs generate code.",
|
|
87
|
+
class: "guarantee",
|
|
72
88
|
},
|
|
73
89
|
NS1009: {
|
|
74
90
|
id: "NS1009",
|
|
75
91
|
title: "for/in does not compile",
|
|
76
92
|
fix: "Model the data as an array and walk it with a classic `for (let i = 0; ...)` loop.",
|
|
77
93
|
why: "`for`/`in` walks the prototype chain; the subset has fixed shapes and no prototypes.",
|
|
94
|
+
class: "guarantee",
|
|
78
95
|
},
|
|
79
96
|
NS1010: {
|
|
80
97
|
id: "NS1010",
|
|
81
98
|
title: "module state lives in the Model",
|
|
82
99
|
fix: "Move the mutable value into the Model and update it through messages; module-level `const` is fine.",
|
|
83
100
|
why: "Mutable globals escape the dispatch/commit lifecycle and break replay.",
|
|
101
|
+
class: "guarantee",
|
|
84
102
|
},
|
|
85
103
|
NS1011: {
|
|
86
104
|
id: "NS1011",
|
|
87
105
|
title: "Map and Set are not part of v1",
|
|
88
|
-
fix: "Model the data as an id-keyed array of records (`readonly Item[]` with a `readonly id: number` field) and look items up with a loop or `.filter
|
|
106
|
+
fix: "Model the data as an id-keyed array of records (`readonly Item[]` with a `readonly id: number` field) and look items up with a loop or `.filter`; transform-heavy work may use `Map`/`Set` inside a `src/services/` module and return plain records.",
|
|
89
107
|
why: "Hashed containers need identity and hashing machinery the commit walkers do not carry in v1; id-keyed arrays give the same access pattern with plain data.",
|
|
108
|
+
class: "deferred",
|
|
90
109
|
},
|
|
91
110
|
NS1012: {
|
|
92
111
|
id: "NS1012",
|
|
93
112
|
title: "object shapes are fixed",
|
|
94
113
|
fix: "Model optional data with `T | null` fields; build new objects instead of deleting fields.",
|
|
95
114
|
why: "Sparse arrays, `delete`, getters/setters, `Proxy`, and `Symbol` break the fixed native layouts the compiler emits.",
|
|
115
|
+
class: "guarantee",
|
|
96
116
|
},
|
|
97
117
|
NS1013: {
|
|
98
118
|
id: "NS1013",
|
|
99
119
|
title: "app cores are a closed world",
|
|
100
120
|
fix: "Remove `eval` / `new Function` / dynamic `import()`; express the logic as ordinary functions.",
|
|
101
121
|
why: "No JS engine ships in the binary, so code cannot be created at runtime.",
|
|
122
|
+
class: "guarantee",
|
|
102
123
|
},
|
|
103
124
|
NS1014: {
|
|
104
125
|
id: "NS1014",
|
|
105
126
|
title: "the core's entry points live in core.ts",
|
|
106
127
|
fix: "Move this export into src/core.ts (imported modules may hold the helpers it calls and the types it uses).",
|
|
107
128
|
why: "The build wires `update`, `initialModel`, `subscriptions`, the host-event channels, `themePack`, and `viewUnbound` from the entry module only, so an entry export in an imported file would be silently ignored.",
|
|
129
|
+
class: "guarantee",
|
|
108
130
|
},
|
|
109
131
|
NS1015: {
|
|
110
132
|
id: "NS1015",
|
|
111
133
|
title: "exhaustive switch required on message unions",
|
|
112
134
|
fix: "Add a case for every `kind` (no `default` needed once all arms are present).",
|
|
113
135
|
why: "Exhaustiveness is what lets the compiler emit a closed native switch with no fallback path.",
|
|
136
|
+
class: "guarantee",
|
|
114
137
|
},
|
|
115
138
|
NS1016: {
|
|
116
139
|
id: "NS1016",
|
|
117
140
|
title: "integer and fractional values cannot share a number slot",
|
|
118
141
|
fix: "Split the value into two fields, or keep every value on this path whole (no fractional literals or fractional math flowing into it).",
|
|
119
142
|
why: "Native code gives each `number` slot one machine type; this slot must be an integer where it is used, but a fractional value also flows in, and an integer type cannot hold both.",
|
|
143
|
+
class: "guarantee",
|
|
120
144
|
},
|
|
121
145
|
NS1017: {
|
|
122
146
|
id: "NS1017",
|
|
123
147
|
title: "commands are issued in update's return, not stored",
|
|
124
148
|
fix: "Construct the Cmd inline in update's return: `return [next, Cmd.persist()]` (several at once via `Cmd.batch([...])`).",
|
|
125
149
|
why: "A Cmd describes effects for the runtime to perform after this dispatch commits; a command that lives in the model, a message, a local, or a helper escapes the dispatch cycle and breaks replay.",
|
|
150
|
+
class: "guarantee",
|
|
126
151
|
},
|
|
127
152
|
NS1018: {
|
|
128
153
|
id: "NS1018",
|
|
129
154
|
title: "text builds with templates and bytes, not +",
|
|
130
155
|
fix: "Build the text as bytes: `utf8Bytes(`${count} items`)` from \"@native-sdk/core\", or stitch byte buffers with `new Uint8Array(n)` + `.set`.",
|
|
131
156
|
why: "Runtime string concatenation would need a JS string heap the native binary does not carry; bytes in the frame arena are the one dynamic-text representation.",
|
|
157
|
+
class: "guarantee",
|
|
132
158
|
},
|
|
133
159
|
NS1019: {
|
|
134
160
|
id: "NS1019",
|
|
135
161
|
title: "functions have fixed arity",
|
|
136
162
|
fix: "Pass every argument explicitly at every call site: drop parameter defaults (`= value`), rest parameters (`...xs`), `arguments`, and call spreads (`f(...xs)`) — take and pass an array instead.",
|
|
137
163
|
why: "Emitted native functions have exact signatures; a dynamic argument list would be materialized invisibly at each call site, and a missed site diverges from node instead of failing loudly.",
|
|
164
|
+
class: "deferred",
|
|
138
165
|
},
|
|
139
166
|
NS1020: {
|
|
140
167
|
id: "NS1020",
|
|
141
168
|
title: "host command arguments are numbers or one bytes payload",
|
|
142
169
|
fix: "Pass numbers (`Cmd.host(\"beep\", model.count)`), or exactly one payload — a `Uint8Array` or a flat record of number/boolean/`Uint8Array` fields (`Cmd.host(\"save\", model.draft)`).",
|
|
143
170
|
why: "The Cmd wire format encodes f64 scalars or one bytes payload per record; a value smuggled past the type with `as` has no encoding and would corrupt the effect stream.",
|
|
171
|
+
class: "guarantee",
|
|
144
172
|
},
|
|
145
173
|
NS1021: {
|
|
146
174
|
id: "NS1021",
|
|
147
175
|
title: "optional chains end in ?? or a value use, not a null test",
|
|
148
176
|
fix: "Normalize with `??` (`model.sel?.tag ?? null`) or guard the base first (`model.sel !== null && model.sel.tag === null`).",
|
|
149
177
|
why: "A short-circuiting `?.` yields JS `undefined` while the field's own empty value is `null`; native folds both into one null, so a null test on the chain would disagree with node.",
|
|
178
|
+
class: "guarantee",
|
|
150
179
|
},
|
|
151
180
|
NS1022: {
|
|
152
181
|
id: "NS1022",
|
|
153
182
|
title: "shared arrays sort by copy, not in place",
|
|
154
183
|
fix: "Sort a copy you own — `const copy = xs.slice(); copy.sort((a, b) => a - b);` — or inline with `.toSorted((a, b) => a - b)` and use the returned copy.",
|
|
155
184
|
why: "`.sort()` mutates the array it is called on; model data stays live for rendering and undo, so an in-place sort would corrupt the previous model. A local `.slice()` copy is yours, and sorting it in place is legal.",
|
|
185
|
+
class: "guarantee",
|
|
156
186
|
},
|
|
157
187
|
NS1023: {
|
|
158
188
|
id: "NS1023",
|
|
159
189
|
title: "sort comparators return a sign, not a boolean",
|
|
160
190
|
fix: "Return a number whose sign orders the pair: `(a, b) => a - b` for ascending numbers, or explicit -1/0/1 branches.",
|
|
161
191
|
why: "JS reads the comparator numerically — `true` coerces to 1 but `false` coerces to 0, which claims the pair is already ordered, so a boolean comparator leaves data unsorted under node too.",
|
|
192
|
+
class: "guarantee",
|
|
162
193
|
},
|
|
163
194
|
NS1024: {
|
|
164
195
|
id: "NS1024",
|
|
165
196
|
title: "model text is bytes",
|
|
166
197
|
fix: "Type the field `Uint8Array` and build user-visible values with `utf8Bytes` from \"@native-sdk/core\" (`asciiBytes` is for guaranteed-ASCII machine text), or use a string-literal union (`\"low\" | \"high\"`) when the field holds one of a closed set of tags.",
|
|
167
198
|
why: "A `string` model field would need a JS string heap at every commit; bytes have exactly one representation under node and native, and literal-union tags compile to a native enum.",
|
|
199
|
+
class: "guarantee",
|
|
168
200
|
},
|
|
169
201
|
NS1025: {
|
|
170
202
|
id: "NS1025",
|
|
171
203
|
title: "subscriptions are declared in subscriptions' return, not stored",
|
|
172
204
|
fix: "Derive the descriptors from the model and return them from `subscriptions`: `return model.running ? Sub.timer(\"tick\", 1000, \"tick\") : Sub.none;`.",
|
|
173
205
|
why: "A Sub describes recurring effects the host reconciles against the committed model after every dispatch; a descriptor stored in the model, a message, a local, or a helper escapes that reconciliation and breaks replay.",
|
|
206
|
+
class: "guarantee",
|
|
174
207
|
},
|
|
175
208
|
NS1026: {
|
|
176
209
|
id: "NS1026",
|
|
177
210
|
title: "host payloads are bytes or a flat scalar record",
|
|
178
211
|
fix: "For a raw host call, pass one `Uint8Array` (build text with `asciiBytes`) or one inline scalar record. For nested/typed service data, declare one exported shared shape and call its generated constructor from `@native-sdk/services`.",
|
|
179
212
|
why: "Raw host commands carry one primitive bytes payload. Generated service clients are the deliberate record-valued arm: their sidecar-derived codec carries the wider boundary vocabulary identically under node and native.",
|
|
213
|
+
class: "guarantee",
|
|
180
214
|
},
|
|
181
215
|
NS1027: {
|
|
182
216
|
id: "NS1027",
|
|
183
217
|
title: "effect results route to Msg arms by name",
|
|
184
218
|
fix: "Spell the routing as data — string-literal arm names, optionally keyed: `{ key: \"load\", ok: \"loaded\", err: \"load_failed\" }` — where each named arm carries exactly the payload the effect produces (one `Uint8Array` field for host results; one number field for timer fires).",
|
|
185
219
|
why: "The runtime builds the result Msg itself from the arm's declared shape, so the decoding derives from your types at build time; a callback would run outside the dispatch cycle and could capture state replay cannot see.",
|
|
220
|
+
class: "guarantee",
|
|
186
221
|
},
|
|
187
222
|
NS1028: {
|
|
188
223
|
id: "NS1028",
|
|
189
224
|
title: "Cmd.persist and its capability must agree",
|
|
190
225
|
fix: "Add `\"persist\"` to app.zon's `capabilities` and configure `.persist = .{ .version = 1, .restore = .{ .ok = \"restored\", .none = \"fresh_boot\", .err = \"restore_failed\" } }`; or remove the unused capability/command.",
|
|
191
226
|
why: "The persist capability controls whether the engine-owned snapshot store and `core.persist` binding are linked into the app. Keeping the declaration and command in lockstep prevents a silently unperformed write and sheds storage code from apps that do not use it.",
|
|
227
|
+
class: "guarantee",
|
|
192
228
|
},
|
|
193
229
|
NS1029: {
|
|
194
230
|
id: "NS1029",
|
|
195
231
|
title: "effect op arguments have a fixed shape",
|
|
196
232
|
fix: "Spell the built-in op exactly: paths/URLs/bodies are `Uint8Array`, `method` is a closed verb literal, `timeoutMs` is a number literal, and `headers` is an inline flat record. For an app service, use its generated `@native-sdk/services` constructor; its request and route shape come from the shared contract.",
|
|
197
233
|
why: "Every effect encodes to one fixed wire record. Built-ins own their hand-written shape; service operations own a generated shape and codec projected from services.contract.json.",
|
|
234
|
+
class: "guarantee",
|
|
198
235
|
},
|
|
199
236
|
NS1030: {
|
|
200
237
|
id: "NS1030",
|
|
201
238
|
title: "effect arguments respect the engine's limits",
|
|
202
239
|
fix: "Keep the value inside the engine bound this diagnostic names (shorter path/URL/header block, fewer headers, a delay between 1ms and one year).",
|
|
203
240
|
why: "The host effect engine enforces fixed capacities and would reject the op at runtime through the err arm; a bound that is knowable at compile time should stop the build instead of shipping a guaranteed rejection.",
|
|
241
|
+
class: "guarantee",
|
|
204
242
|
},
|
|
205
243
|
NS1031: {
|
|
206
244
|
id: "NS1031",
|
|
207
245
|
title: "exported model helpers join the model's binding surface",
|
|
208
246
|
fix: "Rename the helper or the colliding member so their emitted names differ.",
|
|
209
247
|
why: "An exported helper taking exactly one Model parameter also emits as a Model declaration markup binds by the helper's own name (`doneCount` binds as `{doneCount}`); two members with one emitted name would be ambiguous to every binding engine.",
|
|
248
|
+
class: "guarantee",
|
|
210
249
|
},
|
|
211
250
|
NS1032: {
|
|
212
251
|
id: "NS1032",
|
|
213
252
|
title: "viewUnbound names update-only model state",
|
|
214
253
|
fix: "Export a const array of string literals naming Model fields, exported model helpers, or Msg kinds: `export const viewUnbound = [\"nextId\", \"tick\"] as const;`.",
|
|
215
254
|
why: "The list emits as the `view_unbound` opt-out `native check` reads, keeping the unbound-state lint honest for state only update logic touches; a name outside the model surface would silence nothing and hide a typo.",
|
|
255
|
+
class: "guarantee",
|
|
216
256
|
},
|
|
217
257
|
NS1033: {
|
|
218
258
|
id: "NS1033",
|
|
219
259
|
title: "wiring exports match their runtime shapes",
|
|
220
|
-
fix: "Declare the channel exactly: `commandMsg(name: string)` / `keyMsg(key: KeyEvent)` / `frameMsg(model: Model, frame: FrameEvent)` / `pinchMsg(pinch: PinchEvent)` / `dropMsg(drop: FileDropEvent)` returning `Msg | null`; `themePack(model: Model): ThemePack`; `statusItem(model: Model): StatusItemState`; `appearanceMsg` / `chromeMsg` naming an arm with that channel's record shape; `envMsgs` entries targeting one-`Uint8Array`-field arms; and persistence ok/none routes naming void arms while err names a one-`Uint8Array`-field arm. Import canonical records from
|
|
221
|
-
why: "The generated wiring builds host events, persistence restore results, model-derived theme
|
|
260
|
+
fix: "Declare the channel exactly: `commandMsg(name: string)` / `keyMsg(key: KeyEvent)` / `frameMsg(model: Model, frame: FrameEvent)` / `pinchMsg(pinch: PinchEvent)` / `dropMsg(drop: FileDropEvent)` returning `Msg | null`; `themePack(model: Model): ThemePack`; singular `statusItem(model: Model): StatusItemState` or collection `statusItems(model: Model): readonly StatusItemDescriptor[]`; `windows(model: Model): readonly WindowDescriptor[]`, with each entry constructed by `windowDescriptor` and a literal `label: asciiBytes(\"name\")` matching `src/windows/name.native`; `appearanceMsg` / `chromeMsg` naming an arm with that channel's record shape; `envMsgs` entries targeting one-`Uint8Array`-field arms; and persistence ok/none routes naming void arms while err names a one-`Uint8Array`-field arm. Import canonical records from the SDK modules.",
|
|
261
|
+
why: "The generated wiring builds host events, persistence restore results, model-derived theme/status/window declarations, and their typed callbacks structurally at build time; a wrong shape would otherwise surface as a Zig compile error inside generated code instead of a teaching diagnostic here.",
|
|
262
|
+
class: "guarantee",
|
|
222
263
|
},
|
|
223
264
|
NS1034: {
|
|
224
265
|
id: "NS1034",
|
|
225
266
|
title: "core imports stay inside src/",
|
|
226
267
|
fix: "Move the module under the app's src/ directory and import it relatively (`./parsers.ts`, `./util/bytes.ts`).",
|
|
227
268
|
why: "The entry module's directory is the core's whole world — the build ships exactly that tree, so a file above it (`../`) or at an absolute path would exist on your machine but not in the app the build compiles.",
|
|
269
|
+
class: "guarantee",
|
|
228
270
|
},
|
|
229
271
|
NS1035: {
|
|
230
272
|
id: "NS1035",
|
|
231
273
|
title: "npm packages do not run inside a core",
|
|
232
274
|
fix: "Move ordinary TypeScript work into `src/services/` and call it through `Cmd.request`, vendor subset-legal core logic under src/ and import it relatively, or make the import type-only (`import type`); only \"@native-sdk/core\" modules carry runtime meaning in the core class.",
|
|
233
275
|
why: "No JS engine ships in the binary — the deterministic core carries only its closed subset, while service modules compile separately through scriptc's ordinary static tier and results return as messages.",
|
|
276
|
+
class: "guarantee",
|
|
234
277
|
},
|
|
235
278
|
NS1036: {
|
|
236
279
|
id: "NS1036",
|
|
237
280
|
title: "runtime modules do not import in a cycle",
|
|
238
281
|
fix: "Hoist the shared declarations into a module both sides import, or make the back-edge type-only (`import type { Model } from \"./core.ts\"` is fine).",
|
|
239
282
|
why: "A runtime import cycle only works through JS's live-binding indirection, which the emitted native module (and plain reading order) cannot represent; type-only edges erase and are exempt.",
|
|
283
|
+
class: "guarantee",
|
|
240
284
|
},
|
|
241
285
|
NS1037: {
|
|
242
286
|
id: "NS1037",
|
|
243
287
|
title: "an import names a real module file",
|
|
244
288
|
fix: "Point the specifier at an existing .ts file, spelled with its extension (`./parsers.ts` — node's module loader resolves real filenames, not bare stems).",
|
|
245
289
|
why: "The import graph is the build's whole input: a specifier that resolves to nothing would fail under node and silently vanish natively.",
|
|
290
|
+
class: "guarantee",
|
|
246
291
|
},
|
|
247
292
|
NS1038: {
|
|
248
293
|
id: "NS1038",
|
|
249
294
|
title: "module-scope names are unique across a core's files",
|
|
250
295
|
fix: "Rename one side, or declare the shared thing once and import it where it is used.",
|
|
251
296
|
why: "The core emits as one native module with one namespace: two types (or two exported values) with one name would collide there, and which one markup or a caller meant would be ambiguous.",
|
|
297
|
+
class: "guarantee",
|
|
252
298
|
},
|
|
253
299
|
NS1039: {
|
|
254
300
|
id: "NS1039",
|
|
255
301
|
title: "a namespace import is a compile-time alias",
|
|
256
302
|
fix: "Reference members through the alias (`ns.helper(x)`, `ns.Config`) or import them by name; the SDK intrinsics are always named imports — `import { Cmd, Sub, asciiBytes, utf8Bytes } from \"@native-sdk/core\"`.",
|
|
257
303
|
why: "The core emits as one flat namespace, so `ns` is dot-syntax that erases at build time — it is not an object value that can be stored or passed — and the effect purity rules recognize the SDK factories by their imported names.",
|
|
304
|
+
class: "guarantee",
|
|
258
305
|
},
|
|
259
306
|
NS1040: {
|
|
260
307
|
id: "NS1040",
|
|
261
308
|
title: "regular expressions are not part of v1",
|
|
262
|
-
fix: "Scan the bytes with the byte-text methods (`.includes`/`.indexOf`/`.startsWith`/`.split` on `Uint8Array`), a loop, or the SDK text helpers (`containsIgnoreCase` from \"@native-sdk/core/text\").",
|
|
309
|
+
fix: "Scan the bytes with the byte-text methods (`.includes`/`.indexOf`/`.startsWith`/`.split` on `Uint8Array`), a loop, or the SDK text helpers (`containsIgnoreCase` from \"@native-sdk/core/text\"); or run the match in a `src/services/` module, where regexes are ordinary TypeScript.",
|
|
263
310
|
why: "A regex is a runtime engine (backtracking, unicode tables) the native binary does not carry, and it reads text as UTF-16 code units where the core's text is bytes.",
|
|
311
|
+
class: "deferred",
|
|
264
312
|
},
|
|
265
313
|
NS1041: {
|
|
266
314
|
id: "NS1041",
|
|
267
315
|
title: "types are static: no runtime type or shape tests",
|
|
268
|
-
fix: "Model alternatives as a discriminated union and switch on its `kind`; optional data is `T | null` tested against null; walk arrays, not object keys.",
|
|
316
|
+
fix: "Model alternatives as a discriminated union and switch on its `kind`; optional data is `T | null` tested against null; walk arrays, not object keys; parse JSON in a `src/services/` module that returns a typed record.",
|
|
269
317
|
why: "Emitted values are fixed native layouts with no runtime tags to inspect (a union's `kind` is the one tag that exists), so `typeof`/`in`/`instanceof`/`Object.keys` have nothing to read.",
|
|
318
|
+
class: "guarantee",
|
|
270
319
|
},
|
|
271
320
|
NS1042: {
|
|
272
321
|
id: "NS1042",
|
|
273
322
|
title: "generators are not part of v1",
|
|
274
323
|
fix: "Build the sequence as an array — the push-builder (`const out: T[] = []` + `out.push(x)`) or `.map`/`.filter` — and return it whole.",
|
|
275
324
|
why: "A generator is a resumable stack frame with hidden state; the subset's collections are materialized arrays built by pure code, which replay and the commit walkers can see.",
|
|
325
|
+
class: "deferred",
|
|
276
326
|
},
|
|
277
327
|
NS1043: {
|
|
278
328
|
id: "NS1043",
|
|
279
329
|
title: "statements stay statements",
|
|
280
330
|
fix: "Write each step as its own statement. A classic for-loop may step several counters (`i++, j--`), and a number `++`/`--`/assignment may sit in a value position when it is the variable's only mention in the statement and JS cannot skip it (`arr[i++]`, `const n = ++count`); everywhere else a comma hides a statement and `void` manufactures a JS undefined (spell the empty `null`).",
|
|
281
331
|
why: "Comma, `void`, and the mixed read-write forms exist to squeeze statements into expression position; the emitted native code splits them back into statements, which is only JS-order-exact in the pinned positions.",
|
|
332
|
+
class: "guarantee",
|
|
282
333
|
},
|
|
283
334
|
NS1044: {
|
|
284
335
|
id: "NS1044",
|
|
285
336
|
title: "BigInt and Symbol are not part of v1",
|
|
286
337
|
fix: "Keep integer math in `number` (exact to 2^53, and integer-classed slots emit as native i64); model identities as number ids.",
|
|
287
338
|
why: "A core's numbers are IEEE f64 slots; arbitrary-precision integers and engine-allocated symbol identities have no native representation.",
|
|
339
|
+
class: "deferred",
|
|
288
340
|
},
|
|
289
341
|
NS1045: {
|
|
290
342
|
id: "NS1045",
|
|
291
343
|
title: "destructuring binds record fields into const locals",
|
|
292
344
|
fix: "Destructure records only: `const { total, done } = stats;` (rename with `{ done: doneCount }`). Bind array elements by index (`const first = xs[0];`), parameters by name, and drop defaults/rest.",
|
|
293
345
|
why: "A record field is always present, so the binding is a compile-time alias; array positions, rest, and defaults can be silently absent in JS (`undefined`), which a bounds-checked native read cannot mean.",
|
|
346
|
+
class: "guarantee",
|
|
294
347
|
},
|
|
295
348
|
NS1046: {
|
|
296
349
|
id: "NS1046",
|
|
297
350
|
title: "functions live at module level",
|
|
298
351
|
fix: "Move the function to module scope (or bind it once: `const helper = (x: number): number => ...` — a capture-free const helper hoists) and pass what it captured as parameters; inline arrow callbacks stay where they are — as call arguments (`xs.map((x) => x * 2)`).",
|
|
299
352
|
why: "A nested declaration, a non-const function value, or a `?.()` call treats a function as a runtime value closing over the enclosing frame; emitted native functions are plain module-level code with explicit inputs, so the capture has no representation.",
|
|
353
|
+
class: "guarantee",
|
|
300
354
|
},
|
|
301
355
|
NS1047: {
|
|
302
356
|
id: "NS1047",
|
|
303
357
|
title: "modules export their declarations by name",
|
|
304
358
|
fix: "Export by name: `export` on the declaration, an export list (`export { doneCount, helper as visible }`), or a named value re-export (`export { parsePs } from \"./parsers.ts\"`); what stays out is `export default`, `export =`, `export * from`, and bindings over things with no single emitted value (renamed generics/classes, wiring config, names from outside the core).",
|
|
305
359
|
why: "Every consumer — markup bindings, the generated wiring, imports across the core's modules — resolves the flat emitted namespace by NAME: an export list binds real names over real declarations (NS1038 keeps them unique), while a default has no name and a star re-export names nothing.",
|
|
360
|
+
class: "guarantee",
|
|
306
361
|
},
|
|
307
362
|
NS1048: {
|
|
308
363
|
id: "NS1048",
|
|
309
364
|
title: "equality is strict",
|
|
310
365
|
fix: "Compare with `===` / `!==`.",
|
|
311
366
|
why: "`==` applies JS's coercion table (\"1\" == 1 is true); the subset's typed values never coerce, so the loose forms are either identical to `===` or depend on string/number coercions that do not exist natively.",
|
|
367
|
+
class: "guarantee",
|
|
312
368
|
},
|
|
313
369
|
NS1049: {
|
|
314
370
|
id: "NS1049",
|
|
315
371
|
title: "locals declare with const and let",
|
|
316
372
|
fix: "Replace `var` with `const` (or `let` where the local is reassigned).",
|
|
317
373
|
why: "`var` hoists to function scope and reads as `undefined` before its line — behavior the emitted block-scoped native locals cannot have, so the subset keeps the two forms whose semantics map exactly.",
|
|
374
|
+
class: "guarantee",
|
|
318
375
|
},
|
|
319
376
|
NS1050: {
|
|
320
377
|
id: "NS1050",
|
|
321
378
|
title: "generics live on module-level declarations",
|
|
322
379
|
fix: "Make the generic a module-level `function`, `interface`, or `type` (those monomorphize per concrete use — `pick<Task>` emits `pick__Task`); the dispatch entry points (update/initialModel/subscriptions) and function values stay concrete.",
|
|
323
380
|
why: "A monomorphized generic needs a declaration the emitter can instantiate per call site; an entry point has one host-facing ABI signature, and a function value hoists as one concrete fn, so neither can vary by type parameter.",
|
|
381
|
+
class: "guarantee",
|
|
324
382
|
},
|
|
325
383
|
NS1051: {
|
|
326
384
|
id: "NS1051",
|
|
327
385
|
title: "a local array is yours until it escapes",
|
|
328
386
|
fix: "Finish mutating before the value escapes: move the mutation above the return/store/call, pass the array only after the last mutation, or mutate inside the callee instead — a call whose parameter is `readonly T[]` and only READS it (no return, no store, no onward pass into a mutable position) is a borrow, not an escape.",
|
|
329
387
|
why: "Once an array is returned, stored, passed where the callee could retain or mutate it, or aliased, other code can hold the same reference; JS would show it your later mutations through that reference, while the native value was shared structurally at the escape — so ownership (and with it mutability) ends there.",
|
|
388
|
+
class: "guarantee",
|
|
330
389
|
},
|
|
331
390
|
NS1052: {
|
|
332
391
|
id: "NS1052",
|
|
333
392
|
title: "spread array locals declare their array type",
|
|
334
393
|
fix: "Annotate the local with its array type: `const turns: readonly Turn[] = [...model.turns, next];`.",
|
|
335
394
|
why: "An array literal lowers against a declared slice target (the element type sizes the copy the spread allocates); an un-annotated spread local leaves that type unknown, so the emitter has nothing to lower against.",
|
|
395
|
+
class: "guarantee",
|
|
336
396
|
},
|
|
337
397
|
NS1053: {
|
|
338
398
|
id: "NS1053",
|
|
339
399
|
title: "generics instantiate per concrete call site",
|
|
340
400
|
fix: "Give the call site concrete types the emitter can name — resolved records, unions, arrays, optionals, numbers, booleans, or bytes (`pick<Task>(tasks)` or plain inference from typed arguments); a call whose type argument stays abstract (an empty `[]`, an `any`/`unknown`/`never`, an unnamed literal union) needs an annotation or a named alias.",
|
|
341
401
|
why: "A generic helper emits one monomorphic Zig function per distinct instantiation (`pick__Task`, `pick__f64`) from tsc's resolved type arguments; a type argument with no concrete native name has nothing to instantiate against.",
|
|
402
|
+
class: "guarantee",
|
|
342
403
|
},
|
|
343
404
|
NS1054: {
|
|
344
405
|
id: "NS1054",
|
|
345
406
|
title: "function values stay local helpers",
|
|
346
407
|
fix: "Bind the function once (`const helper = (x: number): number => x * 2;`), spell its full signature, take everything it needs as parameters (module constants are fine), and use it only by calling it directly or passing it where an inline callback is legal (`xs.map(helper)`).",
|
|
347
408
|
why: "A const-bound, capture-free, fully-annotated function value hoists to an ordinary module-level native function; captures, reassignment, storing or returning the value, and function-typed fields would make it a runtime closure, which has no native representation.",
|
|
409
|
+
class: "guarantee",
|
|
348
410
|
},
|
|
349
411
|
NS1055: {
|
|
350
412
|
id: "NS1055",
|
|
351
413
|
title: "classes hold data, not hierarchies",
|
|
352
414
|
fix: "Drop `extends`/`super`/`abstract`: compose (a field holding the other record or class), or model the variants as a `kind`-discriminated union and switch on it.",
|
|
353
415
|
why: "Emitted classes are flat structs with static dispatch; a subclass would need vtables, prototype chains, and layout subtyping that neither the native mapping nor the commit walkers carry.",
|
|
416
|
+
class: "guarantee",
|
|
354
417
|
},
|
|
355
418
|
NS1056: {
|
|
356
419
|
id: "NS1056",
|
|
357
420
|
title: "class members are annotated fields, one constructor, and plain methods",
|
|
358
421
|
fix: "Spell state as annotated fields (`count: number = 0`) and behavior as ordinary methods — `static` methods, `static readonly` consts, and erased `private`/`protected` keywords included; replace getters/setters with methods, `#`-privates with `private` (or module boundaries), and use `this` only to reach instance fields and methods (`this.count`, `this.step()` — statics go by the class name: `Task.LIMIT`).",
|
|
359
422
|
why: "A data class emits as a struct plus module-level functions (statics under the class's mangled names); accessors, runtime `#` privacy brands, and a `this` that escapes as a value are prototype/closure machinery with no struct representation — and a record-shaped instance must stay exactly its fields.",
|
|
423
|
+
class: "guarantee",
|
|
360
424
|
},
|
|
361
425
|
NS1057: {
|
|
362
426
|
id: "NS1057",
|
|
363
427
|
title: "thrown values are kind-tagged subset shapes",
|
|
364
428
|
fix: "Throw kind-discriminated record values (`throw { kind: \"parse\", at: i } as ParseError;` — several distinct shapes may throw; the checker collects them into the core's thrown union) and read the catch binding in place: test `e.kind` to narrow, read the arm's fields, rethrow bare (`throw e;`), or narrow a single-shape core once with `const err = e as YourError;`.",
|
|
365
429
|
why: "Every `throw` unwinds through one native payload slot typed as the union of the core's thrown shapes, and the `kind` tags are what let a catch narrow that slot exactly — so a thrown value with no subset shape, two shapes sharing one tag, or an error value smuggled out untyped has no sound reading.",
|
|
430
|
+
class: "guarantee",
|
|
366
431
|
},
|
|
367
432
|
NS1058: {
|
|
368
433
|
id: "NS1058",
|
|
369
434
|
title: "finally never redirects control flow",
|
|
370
435
|
fix: "Keep `finally` to cleanup statements; move `return`/`break`/`continue`/`throw` decisions into the `try` or `catch` blocks.",
|
|
371
436
|
why: "A `finally` that exits overrides the pending return or exception (JS's own no-unsafe-finally lint rule exists because that is almost always a bug); the native lowering runs finally on every path through a scoped defer, which cannot carry control flow out.",
|
|
437
|
+
class: "guarantee",
|
|
372
438
|
},
|
|
373
439
|
NS1059: {
|
|
374
440
|
id: "NS1059",
|
|
375
441
|
title: "arrays build from literals, spreads, and loops",
|
|
376
442
|
fix: "Spell the construction directly: `Array.of(a, b)` is the literal `[a, b]`, `Array.from(xs)` is the spread copy `[...xs]`, and `Array.from({ length: n }, f)` is a classic loop pushing `f(i)` into `const out: T[] = []`.",
|
|
377
443
|
why: "The `Array` statics consume iterables and array-like objects — runtime protocols (`Symbol.iterator`, dynamic `length` probing) the fixed native layouts do not carry — while the literal, spread, and push-builder forms construct the same arrays from data the emitter can see.",
|
|
444
|
+
class: "guarantee",
|
|
378
445
|
},
|
|
379
446
|
NS1060: {
|
|
380
447
|
id: "NS1060",
|
|
381
448
|
title: "byte text speaks the byte-honest method set",
|
|
382
449
|
fix: "Use the byte surface: case with `.toUpperCase()`/`.toLowerCase()` (Unicode simple case mapping, locale-free), search with `.includes`/`.indexOf`/`.lastIndexOf`/`.startsWith`/`.endsWith` (bytes needles), measure and pad in bytes (`.length`, `.padStart`), read bytes with `b[i]`/`.at(i)`, and rebuild text with `.split`, slices, and a push-builder.",
|
|
383
450
|
why: "Core text is UTF-8 bytes with exactly one representation under node and native; UTF-16 code-unit reads and Unicode normalization would reintroduce the encoding seam the bytes model exists to close, so their spellings teach the byte-honest form instead.",
|
|
451
|
+
class: "guarantee",
|
|
384
452
|
},
|
|
385
453
|
NS1061: {
|
|
386
454
|
id: "NS1061",
|
|
387
455
|
title: "value records stay scalar where the model keeps them",
|
|
388
456
|
fix: "Declare the record as an interface (reference storage) to hold heap-backed fields, sit in a model array, carry identity under `===`, or reference itself; an object-literal alias (value storage) in the model tree carries scalar fields only (numbers, booleans, literal-union tags).",
|
|
389
457
|
why: "An object-literal alias pins by-value storage — the contract projection's value-record spelling. The model's commit machinery copies by-value records shallowly, so heap-backed fields would dangle across frames, arrays of them have no commit walk, equality has no identity to compare, and a self-reference has no finite layout; each of those needs reference storage, which the interface form declares.",
|
|
458
|
+
class: "guarantee",
|
|
390
459
|
},
|
|
391
460
|
NS1062: {
|
|
392
461
|
id: "NS1062",
|
|
393
462
|
title: "the entry roots keep their contract shapes",
|
|
394
463
|
fix: "Declare `Model` as an interface record (`export interface Model { ... }`) and `Msg` as a kind-tagged union (`export type Msg = { kind: \"...\" } | ...`).",
|
|
395
464
|
why: "The generated wiring commits `Model` as the reference-stored record root and dispatches `Msg` by its declaration-order kind tags; any other shape under those names has no dispatch or commit path and would fail deep inside the emitted module instead of teaching here.",
|
|
465
|
+
class: "guarantee",
|
|
396
466
|
},
|
|
397
467
|
NS1063: {
|
|
398
468
|
id: "NS1063",
|
|
399
469
|
title: "the contract sidecar carries every crossing shape",
|
|
400
470
|
fix: "Spell the crossing in a schema-carried form: value-stored records (object-literal aliases) for message payloads, named records around optional or array payloads, and integer aliases whose values reach past 255.",
|
|
401
471
|
why: "The contract sidecar is the machine-readable twin of the core's surface, and a shape its schema cannot state would silently drop from every consumer — so the build stops here with the spelling that carries it instead.",
|
|
472
|
+
class: "guarantee",
|
|
402
473
|
},
|
|
403
474
|
NS1064: {
|
|
404
475
|
id: "NS1064",
|
|
405
476
|
title: "asciiBytes is ASCII-only",
|
|
406
477
|
fix: "Use `utf8Bytes(...)` for user-visible or Unicode text; keep `asciiBytes(...)` for guaranteed-ASCII command names, keys, paths, URLs, and protocol values.",
|
|
407
478
|
why: "JavaScript strings are UTF-16 while the native text boundary is UTF-8; naming the encoding explicitly prevents a non-ASCII code unit from being truncated into a different byte sequence.",
|
|
479
|
+
class: "guarantee",
|
|
408
480
|
},
|
|
409
481
|
NS1065: {
|
|
410
482
|
id: "NS1065",
|
|
411
483
|
title: "the core does not import services",
|
|
412
484
|
fix: "Import the generated constructor from `@native-sdk/services` and return it from update; raw `Cmd.request(\"module.operation\", bytes, { ok, err })` remains the low-level form. Shared boundary shapes live in a core module that the service imports, but the core-to-service edge is always an effect.",
|
|
413
485
|
why: "A direct import would run ambient, non-deterministic service authority inside update and erase the command/result boundary that journaling and replay depend on.",
|
|
486
|
+
class: "guarantee",
|
|
414
487
|
},
|
|
415
488
|
NS1066: {
|
|
416
489
|
id: "NS1066",
|
|
417
490
|
title: "service package imports are exact vendored facts",
|
|
418
491
|
fix: "Run `native vendor . package@X.Y.Z`, check in `src/services/vendor/` and the generated app.zon `service_packages` facts, then import that exact package name; or vendor a local source module and import it relatively.",
|
|
419
492
|
why: "Service builds have no package-manager or network input: scriptc sees only manifest-declared, hash-verified checked-in sources through an explicit `--npm-static` allowlist.",
|
|
493
|
+
class: "guarantee",
|
|
420
494
|
},
|
|
421
495
|
NS1067: {
|
|
422
496
|
id: "NS1067",
|
|
423
497
|
title: "service calls match the generated typed contract",
|
|
424
498
|
fix: "Export a synchronous, non-default named function with zero or one explicitly typed, contract-encodable request and a contract-encodable result. For a stream, add a last `emit: (chunk: SharedChunk) => void` parameter. Keep boundary records/enums/unions exported in a shared core-class module, let only `{ kind: \"...\", message: <string> }` escape, and call through `@native-sdk/services`.",
|
|
425
499
|
why: "The host codecs, runner registry, and typed client are projections of `services.contract.json`; every crossing data shape, stream declaration, deadline, and operation name must be stated there once.",
|
|
500
|
+
class: "guarantee",
|
|
426
501
|
},
|
|
427
502
|
NS1068: {
|
|
428
503
|
id: "NS1068",
|
|
429
504
|
title: "persistent model shapes advance monotonically",
|
|
430
505
|
fix: "Increase app.zon's `.persist.version` when the `Model` shape changes, and never decrease or reuse a version number.",
|
|
431
506
|
why: "The version selects the app's pure migration path while the model fingerprint rejects accidental shape drift; reusing a version would make old bytes ambiguous and could restore them into the wrong model layout.",
|
|
507
|
+
class: "guarantee",
|
|
432
508
|
},
|
|
433
509
|
NS1069: {
|
|
434
510
|
id: "NS1069",
|
|
435
511
|
title: "Cmd.store and its capability must agree",
|
|
436
512
|
fix: "Add `\"store\"` to app.zon's `capabilities`, or remove the unused capability/command.",
|
|
437
513
|
why: "The store capability controls whether SQLite and the engine-owned record-store binding are linked into the app. Keeping the declaration and command in lockstep prevents a rejected effect and sheds the storage engine from apps that do not use it.",
|
|
514
|
+
class: "guarantee",
|
|
438
515
|
},
|
|
439
516
|
NS1070: {
|
|
440
517
|
id: "NS1070",
|
|
441
518
|
title: "Cmd.db and its capability must agree",
|
|
442
519
|
fix: "Add `\"sqlite\"` to app.zon's `capabilities`, or remove the unused capability/command.",
|
|
443
520
|
why: "The sqlite capability controls whether the relational database and its effect binding are linked into the app. Keeping the declaration and command in lockstep prevents a rejected effect and sheds SQLite from apps that do not use either storage tier.",
|
|
521
|
+
class: "guarantee",
|
|
444
522
|
},
|
|
445
523
|
NS1071: {
|
|
446
524
|
id: "NS1071",
|
|
447
525
|
title: "Cmd.credentials and its capability must agree",
|
|
448
526
|
fix: "Add `\"credentials\"` to app.zon's `capabilities`, or remove the unused capability/command.",
|
|
449
527
|
why: "The credentials capability controls whether the core keychain path is linked into the app; keeping it in lockstep prevents a guaranteed denied effect and sheds the path from apps that do not use it.",
|
|
528
|
+
class: "guarantee",
|
|
450
529
|
},
|
|
451
530
|
NS1072: {
|
|
452
531
|
id: "NS1072",
|
|
453
532
|
title: "core credentials require explicit permission",
|
|
454
533
|
fix: "Add `\"credentials\"` to app.zon's `permissions`, or remove the `Cmd.credentials.*` call.",
|
|
455
534
|
why: "Secrets are the first permission-gated core effect: the runtime refuses every undeclared access with `denied`, even when the build capability is present.",
|
|
535
|
+
class: "guarantee",
|
|
456
536
|
},
|
|
457
537
|
NS1073: {
|
|
458
538
|
id: "NS1073",
|
|
459
539
|
title: "credential requests use the typed factory",
|
|
460
540
|
fix: "Use `Cmd.credentials.set`, `Cmd.credentials.get`, or `Cmd.credentials.delete` instead of spelling `core.credentials.*` through `Cmd.request`.",
|
|
461
541
|
why: "The typed factories own the bounded credential record encoding; reserving their wire namespace keeps arbitrary request bytes from being mistaken for secrets or keys.",
|
|
542
|
+
class: "guarantee",
|
|
543
|
+
},
|
|
544
|
+
NS1074: {
|
|
545
|
+
id: "NS1074",
|
|
546
|
+
title: "external file paths require filesystem permission",
|
|
547
|
+
fix: "Add `\"filesystem\"` to app.zon's `permissions`, or keep raw file effects under a path delivered from `NATIVE_SDK_APP_DATA_DIR`.",
|
|
548
|
+
why: "The runtime canonicalizes raw paths and refuses access outside this app's data/config/cache/state/logs/temp roots unless the manifest grants filesystem access; catching literal external paths at check time avoids shipping a guaranteed rejection.",
|
|
549
|
+
class: "guarantee",
|
|
462
550
|
},
|
|
463
551
|
NS1420: {
|
|
464
552
|
id: "NS1420",
|
|
465
553
|
title: "declare stable SQL in src/queries.sql",
|
|
466
554
|
fix: "Move the string literal into a named `-- name: ...` block in src/queries.sql and call its generated `Cmd.q<Name>` constructor; keep Cmd.db only for genuinely dynamic escape-hatch SQL.",
|
|
467
555
|
why: "Declared SQL is prepared against the complete migration schema during native check, so table, column, result, and parameter mistakes never reach an installed app.",
|
|
556
|
+
class: "guarantee",
|
|
468
557
|
},
|
|
469
558
|
} as const satisfies Record<string, RuleCopy>;
|
|
470
559
|
|
|
@@ -482,10 +571,12 @@ export function makeDiagnostic(
|
|
|
482
571
|
column: number,
|
|
483
572
|
): SubsetDiagnostic {
|
|
484
573
|
const rule = rules[id];
|
|
574
|
+
const classNote =
|
|
575
|
+
rule.class === "deferred" ? " The capability is deliberately deferred, not impossible." : "";
|
|
485
576
|
return {
|
|
486
577
|
id: rule.id,
|
|
487
578
|
title: rule.title,
|
|
488
|
-
message: `${site} ${rule.fix} ${rule.why}`,
|
|
579
|
+
message: `${site} ${rule.fix} ${rule.why}${classNote}`,
|
|
489
580
|
file,
|
|
490
581
|
line,
|
|
491
582
|
column,
|