@native-sdk/cli 0.8.4 → 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.
Files changed (161) hide show
  1. package/build/app.zig +1178 -74
  2. package/build.zig +715 -17
  3. package/build.zig.zon +1 -0
  4. package/native-sdk.d.ts +10 -0
  5. package/package.json +12 -11
  6. package/packages/core/compile-surface/core.ts +435 -3
  7. package/packages/core/package-lock.json +11 -11
  8. package/packages/core/package.json +2 -2
  9. package/packages/core/scripts/compiler_typecheck.mjs +116 -15
  10. package/packages/core/scripts/gen_service_surface.mjs +268 -0
  11. package/packages/core/scripts/merge_static_archives.mjs +78 -0
  12. package/packages/core/scripts/npm_static_spike.mjs +64 -0
  13. package/packages/core/scripts/run_external_core_compiler.mjs +122 -6
  14. package/packages/core/scripts/run_external_service_compiler.mjs +280 -0
  15. package/packages/core/scripts/stage_external_core.mjs +9 -1
  16. package/packages/core/scripts/stage_external_services.mjs +172 -0
  17. package/packages/core/scripts/surface_manifest_diff.mjs +253 -0
  18. package/packages/core/scripts/vendor_service_packages.mjs +189 -0
  19. package/packages/core/sdk/core.d.ts +224 -0
  20. package/packages/core/sdk/core.ts +694 -22
  21. package/packages/core/sdk/events.d.ts +89 -0
  22. package/packages/core/sdk/events.ts +128 -0
  23. package/packages/core/src/checker.ts +936 -15
  24. package/packages/core/src/cli.ts +156 -3
  25. package/packages/core/src/contract.ts +28 -5
  26. package/packages/core/src/devhost.ts +1876 -16
  27. package/packages/core/src/devhost_journal.mjs +183 -0
  28. package/packages/core/src/devhost_resolver.mjs +17 -1
  29. package/packages/core/src/devhost_service_worker.mjs +90 -0
  30. package/packages/core/src/diagnostics.ts +179 -22
  31. package/packages/core/src/frontend.ts +210 -34
  32. package/packages/core/src/infer.ts +24 -0
  33. package/packages/core/src/modules.ts +129 -80
  34. package/packages/core/src/service_contract.ts +597 -0
  35. package/packages/core/src/sqlite_cli.ts +93 -0
  36. package/packages/core/src/sqlite_codegen.ts +806 -0
  37. package/packages/core/src/sqlite_runtime_policy.ts +364 -0
  38. package/packages/core/src/typed_ast.ts +36 -8
  39. package/skill-data/automation/SKILL.md +1 -1
  40. package/skill-data/core/references/project-anatomy.md +1 -1
  41. package/skill-data/native-ui/SKILL.md +58 -5
  42. package/skill-data/ts-core/SKILL.md +123 -41
  43. package/skill-data/ts-services/SKILL.md +126 -0
  44. package/skill-data/ts-services/references/service-surface.md +604 -0
  45. package/skill-data/zig/SKILL.md +1 -1
  46. package/skills/native-sdk/SKILL.md +1 -1
  47. package/src/app_runner/no_migrations.zig +3 -0
  48. package/src/app_runner/no_services.zig +20 -0
  49. package/src/app_runner/root.zig +133 -4
  50. package/src/app_runner/ts_core_main.zig +254 -8
  51. package/src/app_runner/ts_core_mobile.zig +241 -0
  52. package/src/automation/protocol.zig +5 -1
  53. package/src/automation/snapshot.zig +31 -11
  54. package/src/embed/app_exports.zig +12 -1
  55. package/src/embed/c_api.zig +48 -2
  56. package/src/embed/conversions.zig +4 -5
  57. package/src/embed/host.zig +109 -1
  58. package/src/embed/root.zig +8 -0
  59. package/src/embed/tests.zig +241 -0
  60. package/src/embed/types.zig +51 -0
  61. package/src/embed/ui_host.zig +185 -5
  62. package/src/platform/android/NativeSdkActivity.java +131 -0
  63. package/src/platform/android/android_host.c +182 -1
  64. package/src/platform/android/native_sdk_app.h +17 -0
  65. package/src/platform/ios/native_sdk_app.h +17 -0
  66. package/src/platform/ios/uikit_host.m +115 -0
  67. package/src/platform/linux/cef_host.cpp +8 -2
  68. package/src/platform/linux/gtk_host.c +289 -22
  69. package/src/platform/linux/gtk_host.h +5 -1
  70. package/src/platform/linux/root.zig +109 -22
  71. package/src/platform/macos/appkit_host.h +24 -7
  72. package/src/platform/macos/appkit_host.m +686 -64
  73. package/src/platform/macos/cef_host.mm +400 -66
  74. package/src/platform/macos/root.zig +304 -47
  75. package/src/platform/null_platform.zig +435 -48
  76. package/src/platform/null_platform_tests.zig +113 -0
  77. package/src/platform/root.zig +19 -0
  78. package/src/platform/types.zig +281 -28
  79. package/src/platform/windows/root.zig +207 -27
  80. package/src/platform/windows/webview2_host.cpp +334 -51
  81. package/src/primitives/app_manifest/comptime_scene.zig +2 -0
  82. package/src/primitives/app_manifest/root.zig +4 -0
  83. package/src/primitives/app_manifest/tests.zig +3 -0
  84. package/src/primitives/app_manifest/types.zig +32 -0
  85. package/src/primitives/app_manifest/validation.zig +19 -1
  86. package/src/root.zig +53 -0
  87. package/src/runtime/api.zig +19 -0
  88. package/src/runtime/automation_commands.zig +35 -2
  89. package/src/runtime/automation_snapshot.zig +32 -20
  90. package/src/runtime/bridge_permission_tests.zig +58 -3
  91. package/src/runtime/bridge_responses.zig +4 -2
  92. package/src/runtime/builtin_bridge.zig +11 -1
  93. package/src/runtime/canvas_frame.zig +18 -11
  94. package/src/runtime/canvas_frame_animation_tests.zig +4 -0
  95. package/src/runtime/clock.zig +13 -1
  96. package/src/runtime/core.zig +145 -7
  97. package/src/runtime/credentials_store.zig +115 -0
  98. package/src/runtime/effects.zig +3701 -231
  99. package/src/runtime/effects_credentials_tests.zig +332 -0
  100. package/src/runtime/effects_file_tests.zig +587 -0
  101. package/src/runtime/effects_host_tests.zig +208 -1
  102. package/src/runtime/effects_notification_tests.zig +11 -0
  103. package/src/runtime/effects_relational_tests.zig +314 -0
  104. package/src/runtime/effects_store_tests.zig +211 -0
  105. package/src/runtime/file_access.zig +400 -0
  106. package/src/runtime/file_effect_crash_helper.zig +28 -0
  107. package/src/runtime/file_effect_crash_tests.zig +37 -0
  108. package/src/runtime/flow.zig +35 -10
  109. package/src/runtime/gpu_surface_events.zig +6 -1
  110. package/src/runtime/native_command_event_tests.zig +86 -2
  111. package/src/runtime/persist_store.zig +666 -0
  112. package/src/runtime/pty.zig +5 -2
  113. package/src/runtime/record_store.zig +788 -0
  114. package/src/runtime/relational_store.zig +854 -0
  115. package/src/runtime/root.zig +54 -0
  116. package/src/runtime/runtime_event_tests.zig +70 -0
  117. package/src/runtime/service_host.zig +711 -0
  118. package/src/runtime/service_pool.zig +1314 -0
  119. package/src/runtime/session_blobs.zig +4 -1
  120. package/src/runtime/session_journal.zig +158 -5
  121. package/src/runtime/session_record.zig +215 -0
  122. package/src/runtime/session_replay.zig +206 -11
  123. package/src/runtime/session_tests.zig +81 -0
  124. package/src/runtime/shell_layout.zig +1 -0
  125. package/src/runtime/shell_layout_tests.zig +120 -0
  126. package/src/runtime/sqlite_engine.zig +474 -0
  127. package/src/runtime/state.zig +16 -0
  128. package/src/runtime/system_services.zig +170 -38
  129. package/src/runtime/tests.zig +4 -0
  130. package/src/runtime/ts_core_host.zig +1067 -95
  131. package/src/runtime/ts_core_host_tests.zig +325 -11
  132. package/src/runtime/ts_ui_app.zig +953 -2
  133. package/src/runtime/ui_app.zig +434 -96
  134. package/src/runtime/ui_app_tests.zig +287 -11
  135. package/src/runtime/ui_app_window_tests.zig +61 -7
  136. package/src/runtime/validation.zig +42 -0
  137. package/src/runtime/view.zig +9 -0
  138. package/src/runtime/window_storage.zig +1 -0
  139. package/src/runtime/window_view_runtime.zig +2 -3
  140. package/src/runtime/window_views.zig +19 -0
  141. package/src/tooling/android.zig +21 -16
  142. package/src/tooling/db.zig +160 -0
  143. package/src/tooling/ios.zig +7 -1
  144. package/src/tooling/manifest.zig +214 -2
  145. package/src/tooling/package.zig +116 -0
  146. package/src/tooling/raw_manifest.zig +30 -0
  147. package/src/tooling/root.zig +1 -0
  148. package/src/tooling/templates.zig +189 -4
  149. package/src/tooling/ts_core.zig +366 -17
  150. package/src/tooling/verbs.zig +7 -0
  151. package/third_party/sqlite/README.md +13 -0
  152. package/third_party/sqlite/sqlite3.c +269649 -0
  153. package/third_party/sqlite/sqlite3.h +14349 -0
  154. package/tools/corewire/core_abi.zig +14 -2
  155. package/tools/corewire/emit.zig +98 -29
  156. package/tools/corewire/emit_facade.zig +442 -27
  157. package/tools/corewire/emit_profile.zig +6 -2
  158. package/tools/corewire/emit_service.zig +924 -0
  159. package/tools/corewire/main.zig +122 -0
  160. package/tools/corewire/service_contract.zig +250 -0
  161. package/tools/corewire/sidecar.zig +26 -15
@@ -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,378 +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
- fix: "Store text as `Uint8Array` bytes and index those; turn literals and templates into bytes with the `asciiBytes` intrinsic from \"@native-sdk/core\".",
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
- fix: "Build the text as bytes: `asciiBytes(`${count} items`)` from \"@native-sdk/core\", or stitch byte buffers with `new Uint8Array(n)` + `.set`.",
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
- fix: "Type the field `Uint8Array` and build its values with the `asciiBytes` intrinsic from \"@native-sdk/core\" (literals and templates fold at compile time), or use a string-literal union (`\"low\" | \"high\"`) when the field holds one of a closed set of tags.",
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
- fix: "Pass one `Uint8Array` (build text with `asciiBytes`), or one inline record whose fields are numbers, booleans, or `Uint8Array` values — nothing nested, no extra arguments alongside a payload.",
179
- why: "A host command carries exactly one bytes payload on the wire; only these field types have a byte encoding that is identical under node and native.",
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`.",
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
- title: "Cmd.persist is not yet host-backed",
190
- fix: "Persist app state yourself with `Cmd.writeFile(path, bytes, { ok, err })` and load it back at boot with `Cmd.readFile` from `initialModel`'s command.",
191
- why: "No shipping host implements the persist verb yet, so the record is performed by nobody — a writeFile you control (own path, own format, a load path) is the persistence real apps use. The op still compiles and stays on the wire for hosts that add the service.",
224
+ title: "Cmd.persist and its capability must agree",
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.",
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
- fix: "Spell the op exactly: paths/URLs/bodies are `Uint8Array` (asciiBytes for literals), `method` is one of the closed verb literals, `timeoutMs` is a number literal, and `headers` is an inline flat record whose names are compile-time ASCII and whose values are string literals or `Uint8Array` bytes (`{ accept: \"application/json\", authorization: token }`).",
197
- why: "Named effect ops encode to a fixed wire record shape at build time — a closed verb set, literal header names, and bytes-typed dynamic fields (URL, body, header values) are what encodes identically under node and native.",
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.",
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` where `ThemePack` is `\"house\" | \"geist\"`; `export const appearanceMsg = \"<arm>\"` / `chromeMsg = \"<arm>\"` naming a Msg arm with that channel's record shape; `export const envMsgs = [{ env: \"NAME\", msg: \"<arm>\" }] as const` with one-`Uint8Array`-field arms.",
221
- why: "The generated wiring builds host events and model-derived theme selection structurally from your declarations at build time; a wrong shape would otherwise surface as a Zig compile error inside generated code instead of a teaching diagnostic here.",
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
- fix: "Vendor the logic as a module under src/ and import it relatively, or make the import type-only (`import type`); only \"@native-sdk/core\" modules carry runtime meaning.",
233
- why: "No JS engine ships in the binary — an npm package's code has nowhere to run natively, while types erase and cost nothing.",
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.",
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
- title: "core modules do not import in a cycle",
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
- 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 } from \"@native-sdk/core\"`.",
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",
473
+ },
474
+ NS1064: {
475
+ id: "NS1064",
476
+ title: "asciiBytes is ASCII-only",
477
+ fix: "Use `utf8Bytes(...)` for user-visible or Unicode text; keep `asciiBytes(...)` for guaranteed-ASCII command names, keys, paths, URLs, and protocol values.",
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",
480
+ },
481
+ NS1065: {
482
+ id: "NS1065",
483
+ title: "the core does not import services",
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.",
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",
487
+ },
488
+ NS1066: {
489
+ id: "NS1066",
490
+ title: "service package imports are exact vendored facts",
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.",
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",
494
+ },
495
+ NS1067: {
496
+ id: "NS1067",
497
+ title: "service calls match the generated typed contract",
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`.",
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",
501
+ },
502
+ NS1068: {
503
+ id: "NS1068",
504
+ title: "persistent model shapes advance monotonically",
505
+ fix: "Increase app.zon's `.persist.version` when the `Model` shape changes, and never decrease or reuse a version number.",
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",
508
+ },
509
+ NS1069: {
510
+ id: "NS1069",
511
+ title: "Cmd.store and its capability must agree",
512
+ fix: "Add `\"store\"` to app.zon's `capabilities`, or remove the unused capability/command.",
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",
515
+ },
516
+ NS1070: {
517
+ id: "NS1070",
518
+ title: "Cmd.db and its capability must agree",
519
+ fix: "Add `\"sqlite\"` to app.zon's `capabilities`, or remove the unused capability/command.",
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",
522
+ },
523
+ NS1071: {
524
+ id: "NS1071",
525
+ title: "Cmd.credentials and its capability must agree",
526
+ fix: "Add `\"credentials\"` to app.zon's `capabilities`, or remove the unused capability/command.",
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",
529
+ },
530
+ NS1072: {
531
+ id: "NS1072",
532
+ title: "core credentials require explicit permission",
533
+ fix: "Add `\"credentials\"` to app.zon's `permissions`, or remove the `Cmd.credentials.*` call.",
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",
536
+ },
537
+ NS1073: {
538
+ id: "NS1073",
539
+ title: "credential requests use the typed factory",
540
+ fix: "Use `Cmd.credentials.set`, `Cmd.credentials.get`, or `Cmd.credentials.delete` instead of spelling `core.credentials.*` through `Cmd.request`.",
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",
550
+ },
551
+ NS1420: {
552
+ id: "NS1420",
553
+ title: "declare stable SQL in src/queries.sql",
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.",
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",
402
557
  },
403
558
  } as const satisfies Record<string, RuleCopy>;
404
559
 
@@ -416,10 +571,12 @@ export function makeDiagnostic(
416
571
  column: number,
417
572
  ): SubsetDiagnostic {
418
573
  const rule = rules[id];
574
+ const classNote =
575
+ rule.class === "deferred" ? " The capability is deliberately deferred, not impossible." : "";
419
576
  return {
420
577
  id: rule.id,
421
578
  title: rule.title,
422
- message: `${site} ${rule.fix} ${rule.why}`,
579
+ message: `${site} ${rule.fix} ${rule.why}${classNote}`,
423
580
  file,
424
581
  line,
425
582
  column,