<div align="center">
</div>
@tty-pt/stele
Universal Node.js and Browser bindings forlibstele, the zero-dependency system substrate for plain C and isomorphic WebAssembly. Provides high-resolution monotonic clocks, memory diagnostics, the decoupledCapabilityRegistryplug-and-play contract, and the bundled portablemk/build system. Canonical C headers:<ttypt/stele.h>,<ttypt/iso.h>,<ttypt/iso_json.h>,<ttypt/stl_json.h>,<ttypt/wq.h>,<ttypt/stl_job.h>, and<ttypt/stele_wasm.h>.
๐ Full C & Substrate Documentation: See the main libstele GitHub README for single-allocator shared WASM memory, POSIX/Win32 socket shims, and STL_WASM_MODULE slot lifecycle.
1. Quickstart & Installation
# Primary tty.pt registry (recommended; also mirrored to npmjs.org)
npm config set @tty-pt:registry https://tty.pt/npm/
npm install @tty-pt/stele
Native & Mobile OS Packages (tty.pt): Prebuilt native C packages (libstele) for Linux (apt, apk, pacman, dnf), macOS (brew), Windows (winget, MSYS2), OpenBSD (pkg_add), Android (https://tty.pt/android/), and iOS XCFramework (https://tty.pt/ios/) are available via the tty.pt package repositories.
Usage in modern JavaScript / TypeScript:
import {
nowMs,
selfRssBytes,
CapabilityRegistry,
WasmSubstrate,
getSubstrate,
getSharedWasm
} from "@tty-pt/stele";
// 1. High-Resolution Metrics
console.log(`Current process monotonic time: ${nowMs()} ms`);
console.log(`Resident Set Size (RSS): ${selfRssBytes()} bytes`);
// 2. Capability Registry
const caps = new CapabilityRegistry();
caps.register("audio", (root, wasm) => ({
play: (url) => console.log("Playing audio:", url)
}));
// 3. WebAssembly Substrate
const substrate = getSubstrate();
console.log("Single-memory substrate initialized:", substrate.memory.buffer.byteLength);
2. JavaScript / TypeScript API Reference
nowMs(): number
Returns a high-resolution monotonic timestamp in milliseconds using the fastest available native clock.
selfRssBytes(): number
Returns the process Resident Set Size (RSS) in bytes.
CapabilityRegistry
Decoupled plug-and-play capability registry mapping feature slots to runtime providers.
.register(name: string, provider: Function): this.get(name: string): Function | null.has(name: string): boolean.list(): string[].unregister(name: string): boolean
WasmSubstrate
Universal single-memory WebAssembly runtime substrate.
instance: WebAssembly.Instance: Underlying compiled WASM instance.memory: WebAssembly.Memory: Shared linear memory space across all colocated modules..malloc(size: number): number: Allocates memory within the substrate..free(ptr: number): void: Frees memory within the substrate..encodeString(str: string): [number, number]: Writes UTF-8 string into WASM memory, returning[ptr, byteLength]..writeBytes(bytes: Uint8Array): [number, number]: Writes raw binary bytes into WASM memory, returning[ptr, byteLength]..allocString(str: string): number/.readString(ptr: number, maxLen?: number): string: Null-terminated UTF-8 string helpers..withString(str: string, fn: (ptr: number) => T): T/.withStrings(strings: string[], fn: (...ptrs: number[]) => T): T: RAII scoped string helpers..u8()/.u32()/.i32()/.f32()/.f64(): Detached-buffer immune typed array views over shared linear memory..kernelBoot(): number: Invokesstl_kernel_boot()..kernelMount(slot: number, name: string, json?: string): number: Mounts module into slot with JSON state..kernelMountBin(slot: number, name: string, bin: Uint8Array): number: Mounts module into slot with zero-copy binary state (stl_kernel_mount_bin())..kernelUpdate(slot: number): number: Invokesstl_kernel_update(slot)..kernelAction(slot: number, actionId: number, data?: string): number: Dispatches action to module..kernelUnmount(slot: number): number: Unmounts module from slot..eventEmit(topic: string, payload?: string | Uint8Array | object): number: Emits an event on the in-WASM event bus (stl_event_emit())..onEvent(topic: string, payload?: string | Uint8Array | object): number: Delivers an external host event into the WASM event bus (stl_on_event()).
getSubstrate(): WasmSubstrate / getSubstrateAsync(): Promise<WasmSubstrate>
Returns the globally shared WasmSubstrate instance, guaranteed to instantiate stele.wasm strictly once per lifecycle with dynamic WebAssembly linear memory growth up to 4 GB.
loadWasmModule(wasmUrl, customImports?) / loadWasmModuleAsync(wasmUrl, customImports?)
Instantiates a downstream WebAssembly module onto the shared WasmSubstrate linear memory with automatic malloc/free and env.memory wiring.
Native Addon & Prebuild Loader (@tty-pt/stele)
loadNativeAddon(baseDir, addonName): Loads a Node-API.nodeaddon withRTLD_NOW | RTLD_GLOBAL(falling back acrossbuild/Release/andprebuilds/<platform>-<arch>[-musl]/) and pre-loadslibstele.{so,dylib,dll}so downstream C symbols resolve globally acrossdlopen.resolveSiblingPrebuildDirs(callerImportMetaUrl, pkgNames)(alias:resolveAxisPrebuildDirs): Discovers installed sibling@tty-pt/<name>nativeprebuilds/<key>/andlib/directories for dynamicdlopenresolution.getPlatformPrebuildKeys()/isMuslLinux(): Detects current OS/CPU and glibc vs. musl libc prebuild directory keys.
Cross-Platform Advisory File Locks (Node-API)
tryLockFile(lockPath: string): object | null: Attempts a non-blocking exclusive fixed-inode OS advisory lock (stl_file_lock_try,O_CLOEXEC, never unlinked). Returns an opaque lock handle on success ornullwhen contended. Pin the returned handle for the duration of the critical section so GC does not finalize it early.unlockFile(handle: object): void: Releases and closes an acquired OS file lock handle (stl_file_lock_release).isFileLocked(lockPath: string): boolean: Non-blocking probe returningtruewhen another open file description currently holds an exclusive OS lock onlockPath(stl_file_lock_is_held).
Browser Client Runtime (@tty-pt/stele/client)
SteleWasmClient (dist/client.js / htdocs/stele-client.js) provides the browser-side multi-slot hydration runtime:
- Unified kernel instance reuse across slots via
data-wasm-bundle. - Runtime capability handler registration (
registerSteleMainHandler(type, fn),registerSteleWorkerHandler(type, fn)) and bridge capability metadata (workerOwned,slotBridge,dispatchExport) so downstream bridges plug in without modifyinglibstele. - Multi-core compute worker pool (
stl_job/STELE_JOB_WORKER_SRC) dispatching Web Workers overMessageChannelwith zero-copyArrayBuffertransfers (noSharedArrayBufferrequired). - Zero-copy binary state hand-off (
application/octet-stream, Base64data-state-bin, ormeta[name="state-src"]preloads). - On-demand lazy slot mounting (
lazyMountSlotwithinteraction,visible, ormanualtriggers). - Cross-slot and host event bus (
client.on(topic, cb),client.off(topic, cb),client.emit(topic, payload)). - Optimistic form mutations (
stl_optimistic_update) with automatic rollback on HTTP failure (stl_optimistic_rollback). - Batched capability bridge remounting across DOM patch replay boundaries.
3. Isomorphic C Headers & Portable mk/ Build System
@tty-pt/stele ships the canonical C substrate headers (include/ttypt/), stele.pc, and the integrated portable mk/ build system (mk/include.mk, mk/portable.mk, mk/portable-gnu.mk, mk/portable-bsd.mk, mk/service.mk, mk/cx.mk, mk/iso.mk, mk/glfw.mk, mk/ttypt/{include,portable}.mk, mk/wasm_alloc_shim.c, mk/Doxyfile*, mk/scripts/wasm-audit.sh):
<ttypt/stele.h>: Cross-platform POSIX/Win32 socket, local IPC (stl_ipc_*), wake (stl_wake_*), subprocess (stl_spawn/stl_proc_*), user/path, and system shims.<ttypt/iso.h>: UniversalISO_EXPORTandISO_IMPORTmacros for isomorphic C modules compiled natively for SSR and into.wasmfor the browser.<ttypt/iso_json.h>: Header-only, zero-allocation, WASM-safe JSON writer (iso_json_w_init,iso_json_escape,iso_json_raw,html_safemode) and flat-token parser (iso_json_parse,iso_json_obj_get,iso_json_unescapewith BMP/UTF-16 surrogate pair decoding).<ttypt/stl_json.h>: Lightweight single-owner JSON DOM (stl_json_parse,stl_json_stringify,stl_json_obj_*,stl_json_arr_*) and growing streaming writer (stl_json_buf_*).<ttypt/wq.h>: Cross-platform lock-free workqueue (stl_wq_*/stele_wq_*), logical processor discovery (stl_cpu_count,stl_wq_thread_count), andSTL_THREAD_LOCALstorage across POSIX threads, Win32 threads, and WebAssembly workers.<ttypt/stl_job.h>: Generic message-passing multi-core compute worker pool (stl_job_init,stl_job_submit,stl_job_poll,stl_job_take,stl_job_step,stl_job_shutdown) backed by native pthreads or WASM Web Workers.<ttypt/stele_wasm.h>: Universal single-instantiation WASM kernel substrate and slot orchestration ABI.
When building native Node addons, C libraries, or WebAssembly reactors:
CFLAGS += -I./node_modules/@tty-pt/stele/include
LDLIBS += -lstele
include ./node_modules/@tty-pt/stele/mk/include.mk
System installs (make install on libstele) also install these helpers to share/ttypt/mk/, install Make search-path shims (ttypt/include.mk, ttypt/portable.mk), expose datadir, mk_dir, include_mk, portable_mk, and wasm_includedir in stele.pc, and provide a backward-compatible ttypt-mk.pc.
License
BSD-2-Clause โ Copyright (c) 2026, Paulo Quirino <quirinpa@gmail.com>. See LICENSE.