vercel-labs/ts-core
Authoring guide for TypeScript app cores - Model, Msg, update, and the pure functions they call, written in the closed app-core subset, checked by the @native-sdk/core frontend, and compiled ahead-of-time to native code by the external core compiler. Use when writing or modifying a src/core.ts app core, fixing subset checker errors (NS1001-NS1060), or deciding how to express state, messages, text (bytes and the byte-text string methods), text input, continuous controls (sliders, scroll), effects (Cmd), subscriptions (Sub), the host-event wiring channels (frameMsg, keyMsg, appearanceMsg, chromeMsg, envMsgs, app.zon assets), derived values, the view_unbound lint opt-out, local mutation of owned arrays, or how to split a core into modules under src/ (relative imports, namespace imports, @native-sdk/core/text, @native-sdk/core/events).
npx skills add https://github.com/vercel-labs/native --skill ts-core
An app core is the logic tier of a Native SDK app: Model (the app state), Msg (a discriminated union of everything that can happen), update(model, msg) (the one pure transition function), and the pure helpers they call. You write it as a TypeScript module rooted at src/core.ts - splitting into more modules under src/ when it grows (see "Splitting a core into modules") - and the build checks the whole import graph with the @native-sdk/core frontend and compiles it to native code with the external core compiler. No JS engine ships in the binary — the program either passes the subset checker and compiles to native, or you get a teaching error naming the rule, the fix, and the reason. The same file is executable TypeScript: it typechecks with stock tsc and runs unmodified under node, so you can poke behavior with plain node scripts before the native build.
A whole TS app is three files of truth and zero Zig: src/core.ts (this guide; plus any modules it imports under src/), src/app.native (the markup view over the core's model), and app.zon (windows, identity, permissions). native init scaffolds exactly that; the build detects src/core.ts in the tree (never a flag or config — a tree with both src/core.ts and src/main.zig is a teaching error) and generates the wiring outside the app. The loop:
native dev --core # the fastest loop: run the core under node's virtual host —
# dispatch Msgs as JSON lines ({"kind":"add"}, {"$bytes":"…"}
# for bytes payloads, {"advance":1000} to run virtual timers),
# watch the model + effect transcript. Logic only, no renderer.
native dev # build and run the real app (markup hot reload)
native check # subset-check core.ts + validate markup + app.zon
native build # ReleaseFast binary; native test runs the app's tests
The complete reference app in this idiom is examples/soundboard-ts in the SDK repo: the soundboard music library as three files and zero Zig — const catalog tables, REAL audio through the Cmd.audioPlay stream, scrub-to-seek on a markup slider, a motion-gated Sub.timer playback clock, the full text-edit engine on a search field, controlled scroll, registered cover assets, the width-adaptive grid through the frame channel, clipboard, and context menus, with an end-to-end suite driving the shipping markup.
export interface Model { /* readonly data fields only */ }
export type Msg =
| { readonly kind: "add" }
| { readonly kind: "toggle"; readonly id: number };
// ...one arm per thing that can happen; at least two arms
export function initialModel(): Model { /* pure */ }
export function update(model: Model, msg: Msg): Model {
switch (msg.kind) {
// one case per arm; the switch must be exhaustive (no default needed
// once every arm is present — a missing arm is a build error)
}
}
update is pure and synchronous: next model out, plus optionally command data describing effects. When a dispatch needs an effect, declare the return type Model | [Model, Cmd<Msg>] and return [nextModel, cmd] — the runtime interprets the command after the model commits and dispatches any result back to you as a Msg. initialModel may return the same pair ([Model, Cmd<Msg>]) to run a boot effect once at install, and an app that needs recurring timers exports subscriptions(model): Sub<Msg>. See "Effects are Cmd data" below.export function doneCount(model: Model): number) compile to public native functions — and every exported helper taking exactly ONE Model parameter also becomes a Model declaration markup binds by the helper's own name ({doneCount}), so derived values need no model field. One binding name per member: a helper that collides with a field (or another helper) is a taught NS1031.export const viewUnbound = ["nextId", "tick"] as const;. It emits as the view_unbound opt-out native check's unbound-state lint reads; a name outside the model surface is a taught NS1032. Entries are the TypeScript names exactly as declared ("nextId") and Msg kinds as their kind tags — the same names markup binds, because there are no other names.doneToday stays doneToday), and markup binds them verbatim. String-literal unions emit as native enums.Everything update builds lives in a per-dispatch bump arena that is freed wholesale after the returned model is committed, so spreads, map, and filter are cheap by construction. At commit, only nodes your update actually created are copied into the persistent model heap — everything you spread through unchanged is shared with the previous model for free.
That is why the immutable style is not a performance tax: { ...model, tasks: model.tasks.map(...) } copies one small struct and one pointer array, never the world.
Both regions are the compiled core's own: the frame arena bounds one dispatch's transients, the model heap holds the committed model between dispatches, and the compiler's determinism fences keep every dispatch allocation-shaped and replayable.
The subset is TypeScript minus the ecosystem minus the purity violations — never minus basic syntax. Concretely: every basic statement, operator, and declaration form of the language compiles (every loop shape including do...while, labels with labeled break/continue, switch with default, the full assignment-operator family, ** and the shifts, const record destructuring, namespace imports over your own modules). What does not compile falls into exactly two families, each with a named teaching rule: the ECOSYSTEM the binary cannot carry (npm packages, Node/DOM APIs, regex/JSON/Promise/generator machinery, eval — no JS engine ships), and the constructs that would break a core's guarantees (purity and determinism, fixed shapes, one text representation, functions as declarations not values, static types with no runtime tags). Classes and exceptions are NOT in either family: data classes and throw/try/catch/finally compile (see below) — only their guarantee-breaking tails (inheritance, unsafe finally, untagged thrown values) teach. A construct that fails with a generic error instead of a teaching rule is a checker bug — the grammar matrix test (grammar_matrix.test.ts) pins every grammar production to its verdict so no silent gap can appear.
The banned families at a glance (each diagnostic names the fix and the reason at the site):
eval, new Function, dynamic import(), debugger (NS1013); regexes (NS1040); BigInt/Symbol (NS1044); generators (NS1042); async/Promises (NS1002); npm imports (NS1035).let (NS1010), ambient time/randomness/IO (NS1005), effects outside the Cmd/Sub return paths (NS1017/NS1025).extends/super/abstract (NS1055), accessors/#-privates/class expressions/this-as-a-value (NS1056/NS1006), mutable statics (NS1010), generic classes (NS1053) — plus delete/getters/setters/computed keys (NS1012), for/in (NS1009), Map/Set (NS1011), runtime type/shape tests — typeof/in/instanceof/Object.* (NS1041). Data classes themselves compile — static methods, static readonly consts, and erased private/protected included (see "Data classes" below).+ concatenation and tagged templates (NS1018), string model fields (NS1024), the byte-text stays-out spellings — charCodeAt/normalize/replace and friends on bytes teach the byte-honest form (NS1060; the supported method surface is under "Text is bytes").?.() (NS1046), and const helpers that capture/escape/under-annotate (NS1054 — the legal shape is below under "Local function values"); fixed arity — no defaults, rest, arguments, call spreads (NS1019); generics live on module-level declarations and monomorphize per call site (NS1050/NS1053).var hoisting (NS1049), loose == (NS1048), comma/void/assignment-as-value outside a for-header (NS1043), array/parameter destructuring (NS1045), export default/export =/export * from (NS1047 — export lists and named value re-exports compile), namespace-alias-as-value and SDK namespace imports (NS1039).Model and message shapes:
interface with readonly fields; nested interfaces; T | null for optional data.number, boolean, string-literal unions ("all" | "active" | "done" → native enum), numeric-literal unions, Uint8Array (bytes), a nested interface, readonly Interface[] (arrays of object types), primitive arrays (readonly number[], readonly boolean[], arrays of literal-union tags), a tag-discriminated union ({ kind: "list" } | { kind: "detail"; note: Note } — arms may carry records, bytes, and primitive arrays), and T | null over any of these. Model unions compile to native tagged unions; switching arms in update retires the old arm's payload automatically at commit.Msg: a discriminated union on a readonly kind string tag, with primitive / bytes / interface payload fields. It must be a real union — give it at least two arms, or TypeScript collapses the alias to a plain object type and the checker rejects it.Logic:
switch on any union's kind tag — msg.kind (the Msg dispatch) and model-field unions (switch (model.view.kind)) alike — with member case labels, label stacking (case "a": case "b": body), break, and a trailing default covering the unnamed arms (without a default the switch must be exhaustive — NS1015; with every arm named the default is JS dead code and emits nothing) — and switch on a string-literal-union or numeric-literal-union *value* (switch (model.filter)) — an uncovered member skips the switch exactly like JS (a default anywhere but last is a taught stop in both forms) — and switch on a plain number or string value, lowered to an if/else chain with exact JS semantics: strict equality per case (NaN matches nothing, -0 matches 0, strings compare contents), cases tested in source order, default matching only after every case misses wherever it sits (an empty default: stacking onto the next body included); if/else; classic for (let i = 0; ...) including countdowns (i--, i -= k), multi-counter inits (let lo = 0, hi = n), and comma incrementors (lo++, hi-- — the for-header is the one home for comma sequences); do { ... } while (cond) (the body runs before the first test; continue jumps to the test, exactly node); for (const x of xs) over arrays and Uint8Array, with break/continue, plus the indexed pair form for (const [i, x] of xs.entries()) (exactly the [index, element] two-identifier binding — the index is the loop index, integer-classed; other tuple shapes stay taught); while; labeled statements on loops and blocks with labeled break/continue (outer: for (...) { ... continue outer; } — a labeled continue in a classic for still runs the incrementor, like JS); let locals with reassignment (and let x: number; declared-then-assigned); ternaries; &&/||/!; the empty statement ;.const { total, done: doneCount } = stats; — record-field destructuring into const locals (a compile-time alias per field, renames included). Array patterns, parameter patterns, defaults, rest, and nesting are taught (NS1045 — positions can be silently absent in JS; fields cannot).import * as util from "./util.ts" — a namespace import over your own modules is pure dot-syntax: util.helper(x), util.CONST, and util.Cfg in type positions all resolve to the target module's flat names. The alias is not a value (storing or passing util itself is taught), and the intrinsic @native-sdk/core module is always imported by name (NS1039 — the purity rules recognize Cmd/Sub/asciiBytes by their imported names).{ ...model, field: v }, array spreads in any shape — append [...xs, x], prepend [x, ...xs], multi-spread [...a, x, ...b] (each compiles to one exact-size copy) — .length, indexing xs[i]..map / .filter / .find / .findIndex / .some / .every / .reduce / .toSorted / .slice / .concat / .indexOf / .includes. .map is type-changing — tasks.map((t) => t.id) produces a number array, t => t.title a bytes array, and a callback that can return null produces an optional-element array. Callbacks on map/filter/find/findIndex/some/every may take the (element, index) pair — the index is the loop index, integer-classed (.reduce stays (acc, x): its index parameter is not in v1, and no callback takes the third JS parameter, the array itself — reference the array by name). Array-method calls may sit directly in if/else if and ternary conditions (if (xs.some((x) => x > 3))) — the scan lowers to a loop just before the branch; a while condition cannot (it re-evaluates per iteration — hoist into the loop body or restructure). Callbacks are arrows (expression or block body), inline function expressions, or a BARE REFERENCE to a module-level function or const helper (xs.map(encodeTurn), xs.toSorted(byAscending) — the referenced body inlines exactly like the arrow spelled at the site); in a block body every code path must end in an explicit return (falling off the end would be JS undefined, which has no mapping — a taught stop). JS semantics hold exactly: .slice resolves negative and out-of-range indices the JS way, .indexOf never matches NaN while .includes does, .some/.every keep their vacuous defaults on empty arrays, and .reduce needs its initial value (the no-initial form throws on an empty array in JS, so it is a taught NS1007 — pass the starting accumulator). .indexOf/.includes work on scalar elements (numbers, tags, booleans); on record arrays JS compares references, which has no native mapping — match a field with .find/.findIndex instead.const stack: number[] = [], const st = [1, 2, 3]) or a fresh copy (.slice() / .map() / .filter() / .concat() / .toSorted()) — is locally owned, and the full mutating method set works on it with exact JS semantics: push(...items), pop(), shift(), unshift(...items), splice(start, deleteCount?, ...items) (negative/overshooting indices clamp the JS way; the value is the removed array, also yours), reverse(), fill(v, start?, end?), in-place sort(cmp), and indexed writes xs[i] = v. A parser stack, a work queue, a copy-then-sort — all legal, deterministic, and byte-identical to node. Ownership ends at the first ESCAPE: once the array is returned from a callback, stored into a record/array/model, aliased by a second binding (const b = a), or passed where the callee could keep or mutate it, mutating it afterwards is a taught NS1051 — finish mutating first, then let it escape (an early-exit return is fine: execution ends there, so mutations on the other path stay legal). Two loosenings keep real code flowing. BORROWING: passing an owned array into a readonly T[] parameter is NOT an escape when the callee only READS it (element/property access, iteration, spreads, further borrowing passes — no return of it, no store, no onward pass into a mutable position; recursion over borrowed slices included), so measure-mutate-measure loops work (total(out); out.push(x); total(out)). REASSIGNED-OWNING: a let binding whose EVERY assignment installs a fresh owning construction (a literal or a copy — w = xs.filter(...), acc = []) stays owned through the reassignments; ONE mixed assignment (an alias, a parameter, a helper result) and the binding never owns (NS1001 names it). Never owned: parameters, model/msg data, module const tables, aliases, mixed reassigned bindings, and arrays produced by helper calls (copy with .slice() to own one). After the value escapes it is an ordinary immutable value; the commit walkers and sharing discipline are unaffected because ownership ended before the escape.push/unshift return the new length in JS, which has no mapping — mutate as a statement and read .length after; sort/reverse/fill return the same array — mutate as a statement, then use the array by name (return copy.sort(cmp) is a taught stop; the canonical form is const copy = xs.slice(); copy.sort(cmp); return copy;); pop()/shift() return T | undefined — the same one-empty the .find miss produces, so test === undefined or fold with ?? (stack.pop() ?? fallback); spread arguments (out.push(...xs)) stay taught — one element per iteration; xs[xs.length] = v on an owned array IS a push (the one growth shape — compound forms like xs[xs.length] += v read the missing slot first and stay taught), and other out-of-bounds writes are JS sparse arrays with no mapping (they trap on the native bounds check in safe builds — keep writes inside 0..length-1); changing the LENGTH of the array a for...of (or one of its own callbacks) is iterating is a taught stop (JS walks the live array; fixed-length writes during iteration are fine and identical to node); copyWithin stays out of v1 (splice/fill cover it)..toSorted(cmp) sorts a copy in one expression; .sort(cmp) sorts in place on an array you own (on shared data it keeps the NS1022 teaching, which names the copy idiom). Both comparators follow the same rules: return a sign — (a, b) => a - b for ascending numbers, or explicit -1/0/1 branches; a boolean comparator is wrong in JS itself (false claims equality) and is rejected by the types plus a taught NS1023. The comparator-less arity sorts by string ToString order in JS ([10, 9] stays [10, 9]), which has no float-text mapping — pass a comparator. Both sorts are stable exactly like JS: comparator 0 (or NaN) keeps the original order of the pair. One honesty note: a comparator that is inconsistent over the actual data (e.g. a - b when elements can be NaN) is implementation-defined in JS itself, so node and native may then disagree — keep comparators consistent..find miss is the tier's one empty value: JS spells it undefined, so test the result with === undefined (never === null — the checker teaches the difference) or fold it away with ??: tasks.find((t) => t.id === id) ?? fallback.?. on property chains (model.sel?.at ?? 0), element hops (m?.xs[0] ?? 0, xs?.[i] ?? d), and method hops on supported receivers (xs?.slice(0, 2), xs?.includes(3) ?? false — every mapped array/bytes method): each hop null-propagates exactly like JS, and the chain value is optional — end it in ?? or compare it against a real value. A ?. chain compared against null/undefined is a taught error (NS1021), and g?.() on a function value stays taught.&&/|| chains, exactly the way TS narrows: if (x !== null && x.items.length > 0), the flipped order (null !== x), the || dual (x === null || x.items.length === 0, including as an early-exit guard — the code after the exit stays narrowed), ternary conditions (x !== null && x.at > 0 ? x.at : -1), and while (cur !== null && cur.n > 0) loops (re-tested per iteration; assigning the guarded local drops the narrowing for what follows, like TS). Relational comparisons on guarded optionals (cls !== null && cls < lim) work too.??, comparisons (including === on string-typed values — content equality, same as node; ==/!= are taught NS1048 — coercion), + - * / % on numbers, unary +/-, and the bitwise family & | ^ ~ << >> >>> — all with JS number semantics (/ is float division, % truncates, is float pow with the exact JS corners — 1 NaN is NaN, (-1) Infinity is NaN, right-associative 2 3 2 is 512; bitwise and shifts are ToInt32 with the shift count masked & 31, >>> yielding the unsigned 32-bit value; unary + is the identity on numbers). ** and / results are float-classed; bitwise/shift operands are integer-required positions (a float operand is a taught NS1016).+= -= *= /= %= **= &= |= ^= <<= >>= >>>=, each exactly x = x op v, plus the guarded forms &&=/||= (boolean targets; the right side evaluates only when assigned, like JS) and ??= (optional targets; assigns only when null). A number ++/--/assignment may sit in a VALUE position when the split statement is provably order-exact — the variable's only mention in the statement, in a position JS cannot skip (arr[i++], const n = ++count, const z = (y = 5); postfix yields the pre-step value, everything else the post-step value, exactly JS); every other value-position form is taught (NS1043 — ternary branches, short-circuit right operands, loop conditions, or a second mention of the variable).Math.min / Math.max (any arity — Math.min() is Infinity, Math.max() is -Infinity, NaN propagates, -0 orders below +0), Math.round (half toward +Infinity), Math.floor / Math.ceil / Math.trunc (NaN/Infinity propagate; the -0 results keep their sign, so Math.ceil(-0.5) is -0), Math.abs (clears the zero sign), Math.sign (NaN stays NaN, a zero keeps its sign), Math.sqrt (negative input is NaN, sqrt(-0) is -0). Number.isInteger / Number.isFinite / Number.isNaN classify like node, and the NaN / Infinity globals are ordinary number values. Math calls over compile-time constants fold to their exact JS value — const HALF = Math.floor(5 / 2) is the integer 2, 5 % 0 is NaN, -5 % 5 is -0. A bare -0 literal (and constant arithmetic folding to -0, like 0 * -1) is a float value — only f64 carries the signed zero — so it cannot flow into an index or another integer-required slot. The integer rule: floor/ceil/trunc/abs/sign of an integer-classed value stays integer-classed, but of a float value stays float (floor of NaN is NaN), so bytes[Math.floor(x / 2)] over a float x is still a taught NS1016 — keep index flows integer end to end. ${n} of ${total} ) feeding asciiBytes (below). Float-valued holes are not in v1 (JS float-to-string fidelity is a runtime v2 surface).const numbers and strings fold to comptime constants, and const tables emit as rodata (no arena, shared for free at commit): arrays of numbers / booleans / strings / literal-union members (const WEEKDAYS = [3, 5, 2], const ORDER: readonly Filter[] = ["done", "all"]), records annotated with an interface (const LIMITS: Limits = { lo: 1, hi: 9 }), and arrays of records (const SEEDS: readonly Task[] = [...], names as asciiBytes literals). Element access, .length, for...of, and the array methods all work over tables. Everything inside must fold at compile time — no spreads, no calls except asciiBytes on a literal — and a record table needs its interface annotation (an unannotated { ... } is a taught stop naming the fix). Helper functions; recursion.function, interface, or type declares type parameters and instantiates from tsc's RESOLVED type arguments (explicit or inferred): export function pick<T>(xs: readonly T[], i: number): T { return xs[i]; } called with tasks emits pick__Task, with numbers pick__f64 (a bare number type argument is always f64 — the JS-exact class), one readable Zig fn per distinct instantiation, deduped. Generics over records, unions, arrays, optionals, and bytes all work; generic interfaces/aliases instantiate structurally (Box<Task> emits Box__Task; type Opt<T> = T | null resolves straight through); generics may recurse and call other generics (the inner call resolves at the outer's instantiation). typeof CONST type-query aliases resolve through tsc too (const LIMIT = 9; type Limit = typeof LIMIT). The boundaries teach: a call site whose type argument stays abstract (pick([]) infers never; any/unknown, unnamed literal unions) is NS1053 — annotate the call or name the alias; generic function VALUES and generic entry points are NS1050.class Task { title: Uint8Array; done: boolean = false; constructor(title: Uint8Array) { this.title = title; } toggle(): void { this.done = !this.done; } isDone(): boolean { return this.done; } } emits as a plain struct plus module-level functions; new Task(...) constructs a record-shaped value (field initializers run in declaration order, then the constructor body). static members are per-class module declarations: a static method lowers to a receiver-less module fn under the class's mangled name (Task.fromRow(...) resolves to Task__fromRow), and a static readonly field with an initializer is a module const (Task.LIMIT — the module-const value rules apply: numbers/strings fold, tables need their annotation); a MUTABLE static is module state and teaches NS1010, and inside a static member reach other statics by the class name, never this (NS1056). private/protected keywords are accepted and ERASED — tsc enforces them at the type level, which is their whole meaning (#-fields stay taught: runtime privacy brands). this reaches instance fields and methods (this.count, this.step()) — anything that lets this escape as a value (returning it, storing it, passing it) is taught (NS1056), so fluent chaining is out. Mutation follows exactly the array ownership rule: an instance your function creates with new mutates freely — direct field writes (t.count = 1, t.count += 2) and methods that write this — until it ESCAPES (returned, passed, stored, aliased — then NS1051), and parameters/model data never mutate (NS1001); methods that only read are callable on anything. Fields require type annotations; instances flow between functions, sit in arrays, and compare/narrow like records. The class TAIL teaches by name: extends/super/abstract (NS1055 — compose, or model variants as a kind-union), getters/setters/#-privates/accessor/class expressions (NS1056), mutable statics (NS1010), generic classes (NS1053), parameter properties (NS1008), instanceof (NS1041 — a kind field is the tag that exists). Class instances stay LOCAL values in v1: storing one in the Model tree is taught (NS1056) — keep records (interfaces) in the Model and construct the class where behavior is needed.throw/try/catch/finally as pure control flow. Inside a core, exceptions are deterministic: throw carries a subset VALUE and unwinds to the nearest enclosing catch — across helper calls, out of array-method callbacks (a throw inside .map's callback exits the whole loop, like JS), through nested trys, with finally running on every path (fall-through, return, break/continue, and throw alike). The discipline is two rules. First (NS1057): thrown values are kind-tagged subset shapes — throw kind-discriminated records (throw { kind: "bad_digit", at: i } as ParseError, where ParseError is an interface with a string-literal kind field or a kind-discriminated union; a single-shape core may also throw a number), and SEVERAL distinct shapes may throw: the checker collects every shape the core throws into its implicit thrown union. The catch binding IS that union — narrow it in place with kind tests, no as ceremony: catch (e) { if (e.kind === "bad_digit") return -e.at; if (e.kind === "io") return e.code; return -1; } (or switch (e.kind) — tsc cannot prove exhaustiveness over the implicit union, so give the switch a default or a trailing return). Bare rethrow (throw e;) re-raises the bound value — a narrowed arm included — and catch { ... } needs no binding; the single-as form (const err = e as ParseError;) stays legal in single-shape cores (and for a DECLARED union whose arms equal the thrown set — declare type AppError = ... | ... and as AppError works). What teaches: untagged values in a heterogeneous set, two shapes sharing one kind with different payloads, asserting one member shape of a multi-shape core, the binding escaping untyped into a call/store/return, and throw new Error(...) (engine error objects carry stack traces with no native layout). Second (NS1058): finally never redirects control flow — no return/throw/break-out inside it (JS's own no-unsafe-finally rule; loops fully inside the finally may break within themselves). An UNCAUGHT throw that reaches an exported function's boundary is a defined deterministic panic — exactly where node's process would crash. A throw mid-mutation of an owned array keeps the mutations applied so far, exactly like JS — the catch sees the array as node would.const scale = (x: number): number => x * 3; (arrow or function expression) hoists to an ordinary module-level fn when it is capture-free (module constants and other const helpers are fine to reference; enclosing locals/params are not — pass them as parameters), fully annotated (every parameter and the return type), and used only by direct calls (scale(v), recursion included) or as an array-method callback (xs.map(scale), comparators included). Everything else teaches NS1054: captures, missing annotations, let bindings, returning/storing the value, passing it to your own functions, calling through a record field. Capturing a locally-owned array also ENDS its ownership at the capture (a later mutation is the NS1051 teach) — the stored closure would retain the reference.Not yet in v1 — genuine roadmap deferrals, each stopping with a loud, tailored NS9001 naming the rewrite (never missing basic syntax; the banned-with-a-rule families live in "What the subset means" above): .toSorted()/.sort() without a comparator (JS ToString ordering; pass (a, b) => a - b), .reduce without an initial value (a taught NS1007 — JS throws on an empty array) or with an index parameter (use a classic loop), .indexOf/.includes on record arrays (match a field with .find/.findIndex), .join on number arrays (elements are float-valued; join byte values instead), float values (/, **, Math.round, Math.sqrt, float Math.floor-family results) where an integer is required such as an index (a taught NS1016 — those values can be fractional or NaN), Math methods beyond the batch above, Number methods beyond the three classifiers, float-valued template holes (JS float-to-string fidelity is a runtime v2 surface), arrays of unions (readonly View[]) or arrays of byte-strings (readonly Uint8Array[]) as model fields (wrap the element in a single-field interface), record payloads on Cmd.request results (results and errors arrive as one bytes payload; the record-shaped results are Cmd.fetch's { status, body } arm, Cmd.spawn's collect { code, output } arm, and the fixed audio event arm), streaming fetch responses (Cmd.fetch is buffered only; spawn line streams are the streaming surface), a collect spawn's stderr tail (v1 delivers the exit code and stdout; stderr is not surfaced — put diagnostics on stdout or check the code), per-line truncation flags (a stdout line over the engine's 4 KiB line bound arrives cut, without a flag), and non-timer subscriptions (Sub.timer is the one subscription; one-shot needs are Cmd.delay, and process/audio streams are Cmd-initiated, not subscribed).
update never performs an effect — it can return one, as inert data, alongside the next model. Import the factories from the SDK and declare the pair-return type:
import { Cmd } from "@native-sdk/core";
export function update(model: Model, msg: Msg): Model | [Model, Cmd<Msg>] {
switch (msg.kind) {
case "add":
return [{ ...model, count: model.count + 1 }, Cmd.persist()];
case "request_time":
return [model, Cmd.now("tick")]; // dispatches { kind: "tick", at: <ms> }
case "tick":
return { ...model, lastTick: msg.at }; // bare model = [model, Cmd.none]
case "ship":
return [model, Cmd.batch([Cmd.persist(), Cmd.host("beep", model.count)])];
}
}
The command set (Cmd wire format v3):
Cmd.none — no effects; returning a bare Model is sugar for [model, Cmd.none].Cmd.persist() — ask the host to persist the committed model.Cmd.now("tick") — request a timestamp; the runtime dispatches the named Msg arm with the time (ms) as its payload. The target arm must carry exactly one number field ({ kind: "tick", at: number }), and tsc checks that for you.Cmd.host(name, ...args) — a fire-and-forget host command by literal name; the host decides what the name means. Args are numbers, OR exactly one bytes payload: a Uint8Array (Cmd.host("clipboard.write", model.draft)) or a flat inline record of number/boolean/Uint8Array fields (Cmd.host("cfg.save", { gain: model.gain, on: model.muted, label: asciiBytes("main") })) — the record lowers to one bytes payload from your types at build time, byte-identical under node and native. Anything else (a smuggled string, a nested record, a payload plus extra args) is a taught error (NS1020/NS1026).Cmd.request(name, payload, { key?, ok, err }) — a routed host command: the host performs name with the payload (same bytes/record rules) and dispatches exactly one result back to you as an ordinary Msg — the ok arm with the result bytes on success, or the err arm with the error bytes on failure. Both arms must carry exactly one Uint8Array field ({ kind: "loaded", body: Uint8Array }), checked by tsc and taught by NS1027. The routing is data — string-literal arm names, never callbacks — so the result decoder derives from your Msg types at build time. The optional key (a string literal) names the in-flight effect: issuing a request whose key is already in flight replaces it (the old result is dropped), which is the debounce/exactly-one-in-flight discipline.Cmd.cancel(key) — drop the in-flight keyed effect with that key, silently: a cancelled request, named engine op (readFile/writeFile/fetch/clipboardRead), or armed delay dispatches NEITHER arm — its result is simply dropped. The one exception is a live spawn stream (below): cancel ends the child and the stream's err arm dispatches with cancelled — killing a process is an observable event, kept loud on purpose.Cmd.batch([a, b]) — several commands from one dispatch, performed in order.These map directly onto the host's effect engine — files, HTTP, the clipboard, one-shot timers. Routing follows the Cmd.request rules (inline { key?, ok, err }, string-literal arm names, arm shapes checked by tsc and taught by NS1027), with one difference from request: each op's ok arm has the op's OWN result shape. Keys follow the one keyed-effect rule everywhere: issuing an op whose key is already in flight REPLACES the old one (the superseded op's result is dropped — no message), and Cmd.cancel(key) drops it silently. Every err arm carries exactly one Uint8Array field and receives a machine-readable reason. Paths, URLs, and bodies are bytes (asciiBytes for literals); dynamic values the engine refuses at runtime surface through the err arm, while compile-time-knowable bound violations stop the build (NS1030).
Cmd.readFile(path, { key?, ok, err }) — read a whole file. ok arm: one Uint8Array field with the content. err reasons: not_found, io_failed, truncated (the file exceeds the engine's 1 MiB read bound — a cut file never passes as whole), rejected. Paths are at most 1024 bytes.Cmd.writeFile(path, bytes, { key?, ok, err }) — write a whole file (parent directories created, an existing file replaced whole; at most 1 MiB). ok arm: NO payload fields ({ kind: "wrote" }) — a successful write has nothing to report. err reasons: io_failed, rejected.Cmd.fetch({ url, method?, headers?, body?, timeoutMs? }, { key?, ok, err }) — a buffered HTTP(S) exchange. ok arm: exactly two fields, one number and one Uint8Array ({ kind: "fetched", status: number, body: Uint8Array }) — matched by type, so the names are yours. The status is the real HTTP status: a 404 is still ok (an HTTP-level error is a delivered response). err reasons: connect_failed, tls_failed, protocol_failed, timed_out, rejected, and truncated (the body exceeded the engine's 256 KiB buffered bound — never delivered silently cut). The spec is an inline object: url bytes (≤ 2 KiB), method one of "GET" | "POST" | "PUT" | "DELETE" | "PATCH" | "HEAD" (default GET), headers an inline flat record — names are compile-time ASCII, values are string literals OR runtime bytes ({ authorization: bearerToken(model.apiKey), "content-type": "application/json" } — how a launch-supplied key rides an Authorization header; ≤ 8 headers, ≤ 1 KiB total, NS1029/NS1030), body bytes (≤ 64 KiB), timeoutMs a positive integer literal (engine default when omitted). Buffered only — no streaming responses in v1.Cmd.clipboardWrite(bytes) — put bytes on the system clipboard, fire-and-forget: there is no routing, and a refused or over-bound write is dropped by design.Cmd.clipboardRead({ key?, ok, err }) — read the clipboard. ok arm: one Uint8Array field with the text. err reasons: failed (no clipboard service, over-bound content, pasteboard error), rejected.Cmd.delay(key, ms, "fired") — a keyed ONE-SHOT timer: dispatches the named arm once, ms from now, with the fire time (ms) as its single number payload (the same arm shape Cmd.now and Sub.timer target). Re-issuing a live delay key re-arms it from now — that is the debounce discipline (Cmd.delay("autosave", 800, "save_now") on every keystroke, one fire after the pause). Cmd.cancel(key) drops it silently. The interval is 1ms to one year; a literal outside that stops the build (NS1030).One honesty note on Cmd.persist(): it compiles and encodes, but no shipping host implements the persist verb yet, so the checker teaches NS1028 as a WARNING (never failing the build). Persist real state with Cmd.writeFile and load it back with Cmd.readFile from initialModel's boot command — the pattern every real app uses.
Three effect families deliver MANY results from one command — a keyed stream the app opens imperatively and drives (this is the opposite of Sub: a Sub is declared from the model and the host reconciles it; a stream is a Cmd with a lifecycle you cancel or stop). Routing still follows the Cmd.request rules: string-literal arm names, shapes checked by tsc and taught by NS1027.
Cmd.spawn(argv, { key?, stdin?, line?, exit, err }) — run a subprocess, streaming stdout line by line. argv is an inline array literal of bytes elements ([asciiBytes("/bin/ps"), asciiBytes("-axo")], at most 16 elements, 2 KiB total; the array shape is NS1029, the bounds NS1030), and stdin (optional bytes, ≤ 4 KiB) is written to the child once. Each stdout line dispatches the line arm (one Uint8Array field) as it arrives, across dispatches; omit line to drop lines (an exit-only spawn, e.g. piping stdin to pbcopy). Exactly ONE terminal ends the stream: a clean exit dispatches the exit arm — one number field carrying the exit code (a non-zero code is still exit: the process ran; its failure code is yours to read) — and every other end dispatches err with the reason bytes: signaled, cancelled, rejected (a duplicate live key, or dynamic argv/stdin the engine refused), spawn_failed (the binary could not start). Lines over the engine's 4 KiB line bound arrive cut.Cmd.spawn(argv, { key?, stdin?, collect: true, exit, err }) — the same child, whole stdout buffered instead of streamed (the system-monitor shape: run ps, parse the block). No line arm (NS1027 teaches the conflict). The exit arm is a two-field record — one number field (the exit code) and one Uint8Array field (the collected stdout, up to 512 KiB), matched by type like Cmd.fetch's arm. Collected stdout over the bound routes err with truncated — a cut block never parses as whole.Cmd.cancel(key) aimed at a live spawn ends the child mid-stream; the stream's err arm dispatches with cancelled — loud on purpose, because killing a process is an observable event (the contrast with the named ops, whose cancel is silent). Spawn keys are the ONE exception to the replace rule: a spawn whose key is already streaming is rejected (err gets rejected), never replaced — a running subprocess is never killed implicitly; cancel it first.Cmd.audioPlay(key, { path?, url?, cachePath?, expectedBytes? }, { event }) — open the audio event stream. One player is the whole surface, so a new audioPlay always REPLACES the current playback (the one key-reuse exception besides Cmd.request). The source cascade is the engine's: the local path is tried first, a missing file falls through to url (streamed progressively, cached at cachePath when given, integrity-gated by expectedBytes — omitted/0 means unknown size). At least one of path/url is required (NS1029); each is bytes, at most 1 KiB (NS1030). Prefer OMITTING cachePath for URL sources: when the app wiring configures a caches directory (TsUiApp's audio_cache_dir), the host derives the conventional content-addressed cache path from the URL itself — your update never builds filesystem paths, and replay re-derives the same path by construction. Pass cachePath only to override that convention.event arm is the one SDK-fixed record shape, six fields matched by NAME: state (the AudioState string-literal union — import it from @native-sdk/core/events, or declare an alias with exactly the members "loaded" | "position" | "completed" | "failed" | "rejected" | "spectrum" in any order; the runtime matches members by name), positionMs: number, durationMs: number (milliseconds; the duration is the player's estimate), playing: boolean, buffering: boolean (true while a streamed url is stalled waiting for bytes), and bands: Uint8Array (the 32 spectrum band magnitudes, 0–255 each, all zeros outside "spectrum" events). Every playback event dispatches this arm — "failed" (unplayable source, decode/device failure) and "rejected" (an empty or over-long source) included, so failure is never silence — until Cmd.audioStop closes the stream. "completed" fires once at the natural end and does NOT close the stream: starting the next track from it is the idiom.Cmd.audioPause(key) / Cmd.audioResume(key) / Cmd.audioStop(key) / Cmd.audioSeek(key, ms) / Cmd.audioSetVolume(key, volume) — fire-and-forget control verbs: no result of their own; their consequences arrive on the event stream (audioResume on a dead player reports one "failed" event, never silence). A verb whose key names no open stream is a no-op. audioStop is the audio stream's close — no events for the key after it (Cmd.cancel does not apply to audio). Volume is clamped 0..1 and remembered across tracks; a literal outside 0..1 (or a negative seek literal) stops the build (NS1030).Cmd.channelOpen(key, { event }) — open an EXTERNAL-SOURCE channel under the app's numeric key: the host stages a long-lived, thread-safe posting seam its NATIVE side feeds — embedders and platform-services extensions post bytes from their own threads (sockets, watchers, workers), and each accepted post dispatches the event arm as one "data" event. Posting is deliberately not a TS verb — compiled cores are single-threaded, so the TS tier opens, closes, and receives while the posting handle lives on the native side (Effects.channelHandle(key)). key may be any number expression, a positive integer below 2^53 (a certain-to-be-refused literal stops the build, NS1030). The event arm is a five-field record matched by NAME: key (the channel key echoed verbatim, so concurrent channels sharing one arm stay distinguishable; a key the wire cannot carry exactly echoes 0), state (the ChannelState union — import it from @native-sdk/core or declare an alias with exactly the three members "data" | "closed" | "rejected" in any order; checked BOTH directions, since a narrower union would silently drop states the host emits), bytes (Uint8Array — the post's payload on "data" events, empty otherwise), and droppedPending/droppedTotal (numbers — the honest back-pressure counters: posts the native handle refused since the previous delivered event, and over the channel's whole life; refused posts count, never silence). One channel per key at a time — a duplicate live key dispatches "rejected" — and the key shares the engine's effect-key space (a same-key fetch is blocked while the channel lives). No timer polling anywhere: the source wakes the loop itself. Channel events journal at the effect boundary, so recorded sessions replay the whole stream from the journal — the native posting side is never needed at replay (a native producer that consults ChannelHandle.live() before launching keeps replay fully offline; one that launches unconditionally is stopped at its first post, which answers .closed).Cmd.channelClose(key) — close the open channel under the key, if any: staged posts flush, exactly one "closed" event (final drop totals aboard) dispatches the event arm, and the key frees. A key with no open channel no-ops.Cmd.imageLoad(id, { path?, url?, cachePath?, expectedBytes? }, { event }) — load an image at runtime under the model-owned NUMERIC ImageId your markup binds (<image image="{cover}"/>, <avatar image="{avatar}"/>); id may be any number expression (ids are model data), a positive integer below 2^53 (a certain-to-be-refused literal like 0 stops the build, NS1030). The source cascade is audioPlay's exactly: local path first, a missing file falls through to url (fetched whole, installed at the cache path and integrity-gated by expectedBytes); at least one of path/url (NS1029), and prefer OMITTING cachePath — the wiring's caches directory (TsUiApp's image_cache_dir) derives the content-addressed path from the URL. Exactly ONE event arm dispatches per load — a five-field record matched by NAME: id (the requested ImageId echoed verbatim, so concurrent loads sharing one arm stay distinguishable; an id the wire cannot carry exactly echoes 0), state (the ImageState union — exactly the fifteen members "loaded" | "rejected" | "not_found" | "io_failed" | "connect_failed" | "tls_failed" | "protocol_failed" | "timed_out" | "http_status" | "cancelled" | "too_large" | "unsupported" | "decode_failed" | "registry_full" | "alloc_failed", any order; "alloc_failed" is resource exhaustion at registration — the host refused the memory, the bytes may be fine, retry when memory frees), width/height (the decoded dimensions on "loaded", 0 otherwise), and status (the HTTP status for url loads that performed an exchange; 0 when none occurred — local paths, cache hits — so a cached "loaded" is distinguishable from a network one). On "loaded" the pixels are already registered under the id — store the id in the model then (the store-on-success discipline keeps a fallback rendering until the load lands). One load per id at a time: a duplicate live id dispatches "rejected" (the spawn discipline — a load in flight is never replaced implicitly), and image loads are not the string-keyed Cmd.cancel's to end — Cmd.imageCancel(id) is their cancel, LOUD like spawn's: the one terminal still arrives as the event arm's "cancelled", and the id frees for a fresh load once it lands (an id with no live load no-ops; the same NS1030 literal gate as imageLoad). Decode limits are the registered-image limits (16 slots, 1 MiB decoded pixels — avatar/cover scale, not photo scale); the encoded source bound is 1.25 MiB, and over-bound sources fail whole with "too_large", never cut. Cmd.imageUnregister(id) releases a loaded image's registry slot — the gallery eviction move when the 17th distinct image would answer "registry_full": views bound to the id fall back, and the slot accepts the next load. Unregister is synchronous registry surgery, NOT an effect — no result Msg, an unregistered id no-ops (the same NS1030 literal gate) — and it frees only the CURRENT registration: a load in flight under the id still registers at its terminal, so cancel the load first (Cmd.imageCancel) to keep the slot free.The menu-bar lifecycle pair — fire-and-forget, no routing and no result Msg (the window's own frame event carries the resulting state):
Cmd.showWindow(label) — un-hide + activate the window with the declared label (a string literal — window labels are declarations, in app.zon or a windows_fn descriptor): the counterpart to a close_policy = "hide" close and the tray "Open" consequence; also restores a minimized window. An unknown label is a no-op.Cmd.quitApp() — the graceful terminate, and the tray "Quit" consequence: the host quits through the SAME shutdown path a last-window close takes, so the stop hook runs exactly once and a recording session seals its journal.Commands are constructed inline in the return path and nowhere else (NS1017): never in the Model or a Msg, never in a local, never in a helper. This is what keeps effects inside the dispatch cycle and replay honest.
initialModel may return the same pair to run a boot effect once at install, before the first view build — loading a store is the canonical use:
export function initialModel(): [Model, Cmd<Msg>] {
return [
{ notes: [], loading: true },
Cmd.request("store.read", asciiBytes("notes.bin"), { key: "boot", ok: "loaded", err: "load_failed" }),
];
}
A plain initialModel(): Model stays exactly as before; the pair is opt-in.
Recurring effects are declared, not issued: export subscriptions(model): Sub<Msg> and return descriptors derived from the current model. After every commit the host reconciles the returned set against its active timers by key — a new key (or a changed interval) arms a timer, a missing key cancels it — so starting, stopping, and re-tuning timers is just returning different data:
import { Sub } from "@native-sdk/core";
export function subscriptions(model: Model): Sub<Msg> {
if (!model.running) return Sub.none;
return Sub.batch([
Sub.timer("tick", model.fast ? 250 : 1000, "tick"), // dispatches { kind: "tick", at: <ms> } every interval
Sub.timer("autosave", 30000, "save_now"),
]);
}
Sub.none — no subscriptions (everything paused).Sub.timer(key, everyMs, "tick") — a repeating timer named by its string-literal key; each fire dispatches the named arm with the current time (ms) as its single number payload (the same arm shape Cmd.now targets). The interval may derive from the model.Sub.batch([...]) — several at once.Sub values follow the Cmd purity rule with their own home (NS1025): built inline in subscriptions' return path, never stored, never returned from anywhere else. Debounced re-arm falls out of reconciliation — change the key or interval and the timer re-arms; drop it from the set and it stops.
Keep the Sub-vs-stream line straight: a Sub is DECLARATIVE — derived from the model, started and stopped by reconciliation, and the app never opens or closes one. The multi-result streams (Cmd.spawn's lines, Cmd.audioPlay's events) are Cmd-INITIATED — imperative opens with a keyed lifecycle the app drives (Cmd.cancel for spawn, Cmd.audioStop for audio). If the effect should exist exactly while some model state holds, it wants a Sub shape; if the app decides when it starts and ends, it is a stream.
One caveat for node-side pokes: the build resolves the @native-sdk/core* specifiers for you, but plain node does not know them, so quick behavioral checks under node work directly on cores with no SDK import, and on cores importing Cmd, Sub, asciiBytes, or the text engine only with a module mapping (or by copying the SDK module files next to the core and rewriting the specifiers). native dev --core already maps them.
src/core.ts is the ENTRY module; a core that outgrows it splits into more .ts files under src/ (subdirectories included). The whole import graph still compiles as ONE native module - one flat namespace - and runs unchanged under node.
import { parsePs } from "./parsers.ts" (node's loader resolves real files, not bare stems - a missing extension or a missing file is a taught NS1037).src/ is the boundary: ../ escapes and absolute paths are taught (NS1034); bare npm specifiers are taught (NS1035 - vendor the code under src/ or make the import import type). Only @native-sdk/core (the intrinsic Cmd/Sub/asciiBytes surface) and the SDK library modules below carry runtime meaning from outside.const numbers and tables, and helper functions all cross files (renamed imports and import * as ns namespace aliases both work — the alias is dot-syntax over the same flat namespace, never a value of its own). Export lists and value re-exports work too: export { helper, doneCount as remaining } binds names over existing declarations, and export { parsePs } from "./parsers.ts" forwards another module's export by name (a renamed binding emits as a flat-namespace alias). Type names and EXPORTED value names must be unique across the core's files (NS1038 - declare once, import where used; renamed exports claim their new names in the same namespace); colliding PRIVATE helpers are fine (the compile uniques them per module).import type back-edges are legal and idiomatic: a helper module type-imports Model from ./core.ts while core.ts runtime-imports the helpers - that is the expected shape, not a smell.update, initialModel, subscriptions, the wiring channels (commandMsg/keyMsg/frameMsg/appearanceMsg/chromeMsg/envMsgs), and viewUnbound are DECLARED in core.ts and exported under their own names (export on the declaration or an un-renamed export { update } list entry — a rename or a re-export from an imported module cannot bind an entry point) - imports may FEED them, never replace them. The markup binding surface is also entry-only: an exported single-Model-parameter helper binds ({doneCount}) only when it is DECLARED in core.ts — export lists participate under their exported names (export { taskTotal as taskCount } binds {taskCount}), but a re-export of an imported helper does not bind (under node the app's module object is the entry's exports, so it would bind natively but not exist under node). Imported modules export cross-module API for update and the entry helpers to call.@native-sdk/core/text ships the byte-splice text engine - applyTextInputEvent(state, event, capacity) / clampedInsertEvent over TextEditState (the full caret/word/selection/IME reducer for markup text controls), plus containsIgnoreCase, orderIgnoreCase, and trimAsciiSpaces. @native-sdk/core/events ships the canonical event record types (TextInputEvent re-exported, ScrollState, FrameEvent, KeyEvent, ColorScheme/AppearanceEvent, ChromeInsets/ChromeButtons/ChromeEvent, AudioState/AudioEvent) so no core re-types the vocabulary. Unlike @native-sdk/core (intrinsic, never compiled into the core) these are ordinary subset TypeScript, compiled INTO your core when imported and absent when not. Under node they resolve like the core module itself. One namespace rule to know (NS1038): module-scope names are unique across the whole import graph, so a core that imports an SDK event type deletes its own in-file mirror of that name.The reference splits are examples/soundboard-ts (core.ts + library.ts + player.ts + the SDK text engine), examples/system-monitor-ts (core.ts + parsers.ts + table.ts + the SDK text engine), and examples/ai-chat-ts (core.ts + api.ts — the JSON-over-bytes wire-format reference: request encoding and a targeted parse walk that returns null on anything malformed) in the SDK repo.
string in a core is for literals, string-literal-union tags, and === comparisons — content equality, on tags and plain string values alike (name === "app.add" in a command mapper works and behaves identically under node and native). Dynamic, user-visible text lives in the Model as Uint8Array — indexing yields byte values, .length is byte length, subarray is a view and slice is a copy, and both resolve their bounds the JS way (negatives count from the end, out-of-range clamps, a crossed range is empty), identical under node and native. Observing a string's code units (.length, s[i], .charCodeAt) is banned (NS1004) because UTF-16 and UTF-8 would disagree, and + concatenation is banned (NS1018) because runtime string building needs a JS string heap the binary does not carry — build text with template literals into bytes instead.
Turn literals and templates into bytes with the asciiBytes intrinsic from the SDK. The compiler recognizes the import by identity and folds every call at compile time — a literal argument becomes rodata, a template becomes per-dispatch arena bytes — and under node the same import runs as a plain function with the same result:
import { asciiBytes } from "@native-sdk/core";
export type Bytes = Uint8Array;
const label = asciiBytes(`${done} of ${total} done`); // arena bytes
const seed = asciiBytes("Stretch"); // rodata, free to commit
Arguments must be string literals or templates (the fold happens at compile time); dynamic text is already bytes, so there is nothing to bridge. Hand-rolling the old bridge shape (function asciiBytes(s: string): Bytes { ... }) no longer gets special treatment — its body observes code units and teaches NS1004.
Bytes read like text: the everyday string methods work directly on Uint8Array values, with byte-honest semantics — every length, offset, and index is a BYTE length/offset (never a character count: é measures 2 and padStart pads by bytes), search is byte-wise, and case mapping is Unicode SIMPLE case mapping (code point → code point from the Unicode tables; locale-free, no special casing — ß stays ß, σ uppercases to Σ; bytes that are not well-formed UTF-8 pass through case mapping unchanged). Natively each call lowers onto the compiled core's runtime; under node the devhost installs the same methods from the same Unicode tables, so both runtimes produce identical bytes.
const query = model.query.trim().toLowerCase(); // JS whitespace set; simple case map
if (title.toLowerCase().includes(query)) { ... } // byte substring search
const bar = asciiBytes("#").repeat(used).padEnd(w, asciiBytes(".")); // w is a BYTE width
const cells = row.split(asciiBytes(",")); // Uint8Array[] — the array is yours (push works)
const ext = name.lastIndexOf(asciiBytes(".")); // byte offset, -1 when absent
const last = line.at(-1) ?? 0; // byte value | undefined (the .find one-empty)
toUpperCase() / toLowerCase() — fresh bytes, simple case mapping only (locale casing stays out; toLocaleUpperCase teaches NS1005).Take vercel-labs/ts-core from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.