Package Exports
- @femtomc/mu-core
- @femtomc/mu-core/browser
- @femtomc/mu-core/node
Readme
@femtomc/mu-core
Core runtime primitives shared across mu packages.
Install
After publishing:
npm install @femtomc/mu-core
# or: bun add @femtomc/mu-coreFrom this repo:
cd mu
bun install
bun run buildUsage
import { EventLog, InMemoryJsonlStore, JsonlEventSink, newRunId, runContext } from "@femtomc/mu-core/node";
const jsonl = new InMemoryJsonlStore();
const events = new EventLog(new JsonlEventSink(jsonl));
await runContext({ runId: newRunId() }, async () => {
await events.emit("demo.event", { source: "readme", payload: { ok: true } });
});
console.log(await jsonl.read());HUD contract helpers
@femtomc/mu-core exports a versioned HUD contract, deterministic JSON helper, and shared runtime loop:
HudDocSchema,HUD_CONTRACT_VERSIONparseHudDoc(...),normalizeHudDocs(...)resolveHudStylePresetName(...),applyHudStylePreset(...),hudStylePresetWarnings(...)serializeHudDocTextFallback(...),serializeHudDocsTextFallback(...)stableSerializeJson(...)HudRuntime+HudProviderfor provider registration, reducer updates, ordered effect execution, and HUD snapshot emission
HudDoc also supports optional presentation hints (title_style, snapshot_style, chip/item/section/action style objects) and metadata style presets (metadata.style_preset currently planning|subagents) so renderers can opt into richer emphasis while preserving deterministic plain-text fallbacks.
These are runtime-agnostic primitives intended for shared HUD capture/render pipelines.
UI contract helpers
Interactive UI documents are modeled as first-class, versioned contracts that describe renderable components, actions, and revisions so any rendering surface can stay in sync with agents. @femtomc/mu-core exposes the following helpers:
UI_CONTRACT_VERSION,UiDocSchema,UiRevisionSchema,UiComponentSchema, andUiActionSchemafor validating document payloads.parseUiDoc(...),normalizeUiDocs(...), anduiDocRevisionConflict(...)for deterministic selection, conflict detection, and safe merging of candidate documents.UiEventSchema+parseUiEvent(...)for structured event payloads emitted by frontends (every event includesui_id,action_id, the originatingrevision, optionalcallback_token,payload, andcreated_at_ms).
Field limits
The UI contract enforces strict bounds to keep cross-frontends renderable:
- titles are capped at 256 characters and summaries at 1024 characters.
- documents can contain at most 64 components, where text segments are limited to 2048 characters, lists can hold at most 32 items, and key/value rows are capped at 32 entries.
- actions are limited to 32 entries; labels are 128 characters, descriptions 512, and callback tokens 128.
Deterministic ordering
normalizeUiDocs(...) deduplicates by ui_id, chooses the highest revision.version, breaks ties with updated_at_ms, and falls back to a stable JSON comparison (stableSerializeJson) so every renderer observes the same ordering. Use uiDocRevisionConflict(...) to detect when two docs claim the same revision but differ, enabling agents to guard against race conditions.
Tests / Typecheck
From the mu/ repo root:
bun test packages/core
bun run typecheckRuntime
@femtomc/mu-coreis runtime-agnostic (no Node builtins).@femtomc/mu-core/nodeis Node-only (node:fs,node:async_hooks).@femtomc/mu-core/browseris browser-only (IndexedDB/localStorage).