Single File Component (.aihu) compiler — Rust binary + JS glue.
_buildDeferredHydrationfunction _buildDeferredHydration(compiledCode: string, elementTag: string): stringRewrite an interactive-island module so its `connectedCallback` waits for the element to scroll into view before mounting.
_buildStaticIslandfunction _buildStaticIsland(compiledCode: string, elementTag: string): stringBuild a static-island shim for a compiled module.
_clearTransformMemofunction _clearTransformMemo(): voidTest/diagnostic hook — wipe the memo and its counters.
_compileViaBackendfunction _compileViaBackend( source: string, legacyArgs: string[], options: CompileEnvelopeOptions, ): EnvelopeReplyRun one compile through the active backend.
_foldCssEngineStylesfunction _foldCssEngineStyles(compiledCode: string, css: string): stringFold css-engine-produced scoped CSS into a compiled `.aihu` module.
_foldCssEngineStylesGlobalfunction _foldCssEngineStylesGlobal( compiledCode: string, css: string, id: string, ): { code: string; virtualId: string } | nullBug 6 — `shadowMode === 'light'` branch.
_formatExtractCensusfunction _formatExtractCensus( census: ReadonlyMap<string, { read: string; call: string }>, ): string[]GX Phase 1 (#437-GX) — format the per-value extract census (the DA-e census pattern from #437: every build PRINTS the posture distribution, so the default-vs-declared migration story stays visible rather than silent).
_getCompilerNativeStateKindfunction _getCompilerNativeStateKind(): CompilerNativeState['kind']Returns the cached state kind (resolving if needed).
_globalizeAuthoredStylefunction _globalizeAuthoredStyle(code: string): stringLight-DOM (`shadowMode:'light'`) recipes: redirect the authored `@style` block's per-instance `host.adoptedStyleSheets = [__style__]` assignment to `document.adoptedStyleSheets` so the recipe's class-scoped CSS reaches the global cascade (a light-DOM host has no shadow root, making the original setter a silent no-op).
_hashIdForUtilityCssfunction _hashIdForUtilityCss(id: string): stringStable short hash for keying the virtual-CSS module per source-SFC id.
_injectAutoWiringfunction _injectAutoWiring(code: string): stringInject `_setMount(mount)` + `_setSignal(signal)` auto-wiring into a compiled `.aihu` module.
_injectShadowModefunction _injectShadowMode(code: string, mode: 'light' | 'shadow'): stringInject `{ shadowMode: '...' }` as the third argument to the emitted `defineElement('tag', defineComponent(...))` call.
_isLayoutFilefunction _isLayoutFile(rawId: string, layoutsDir: string): booleanIs `rawId` a layout SFC (a `.aihu` file under the configured layouts dir)?
_layoutTagfunction _layoutTag(stem: string): stringLayout custom-element tag for a filename stem.
_parseExtractMarkerfunction _parseExtractMarker(code: string): { read: string; call: string } | nullGX Phase 1 (#437-GX) — parse the `//
_parseIslandMarkerfunction _parseIslandMarker(compiledCode: string): 'static' | 'interactive'Read the compiler's AUTHORITATIVE island classification from the `//
_passivizeOutletfunction _passivizeOutlet(code: string): stringCollapse the reactive `<outlet>` boundary the Rust codegen emits into a passive `data-aihu-outlet` marker.
_resetCompileBackendfunction _resetCompileBackend(): voidReset the cached backend (tests).
_resetCompilerNativefunction _resetCompilerNative(): voidReset the cached state.
_resolveCompileBackendfunction _resolveCompileBackend(): CompileBackendResolve (once) which backend serves compiles for this process.
_transformMemoStatsfunction _transformMemoStats(): { size: number hits: number misses: number seeds: number }Test/diagnostic hook — current memo size + hit/miss/seed counters.
aihuCompilerPluginfunction aihuCompilerPlugin(options?: AihuCompilerPluginOptions): VitePlugincompileRouteMetafunction compileRouteMeta(source: string, id?: string): RouteMeta | nullcompileSidecarfunction compileSidecar( source: string, id?: string, options?: { /** * #486 step 4 — emit the attribute/component-prop type layer * (`--strict-templates`). Default off: the surface stays byte-identical * to the pre-#486 sidecar. */ strictTemplates?: boolean }, ): stringCompile an SFC to its TYPE-CHECK SURFACE and return it as a string — the `.aihu.ts` sidecar's content, without writing a file.
compileToAstfunction compileToAst(source: string, id?: string): SfcAstkebabComponentTagfunction kebabComponentTag(raw: string): stringO1a (tag naming) — JS mirror of the Rust compiler's `tags::kebab_component_tag` (packages/compiler/src/tags.rs).
loadCompilerNativefunction loadCompilerNative(): CompilerNativeStateResolve (and cache) the native compiler addon.
transformfunction transform( source: string, id: string, options?: { sidecarOut?: string target?: 'client' | 'server' | 'universal' /** Override the registered custom-element tag (default: file stem). Used for layouts. */ tag?: string /** * #486 step 4 — emit the sidecar's attribute/component-prop type layer * (`--strict-templates`). Affects only the type-check surface written to * `sidecarOut`; the compiled JS is identical either way. Default off. */ strictTemplates?: boolean }, ): { code: string; map: null }Compile a .aihu source string to TypeScript.
_MEMO_MAX_ENTRIESconst _MEMO_MAX_ENTRIESFIFO size bound.
VIRTUAL_UTILITY_PREFIXconst VIRTUAL_UTILITY_PREFIXVirtual-module prefix used by the `shadowMode === 'light'` branch to route per-SFC utility CSS through Vite's built-in CSS pipeline.
AihuCompilerPluginOptionsinterface AihuCompilerPluginOptions {
/**
* When `true` (default), components the compiler classified as `'static'`
* (read from the `// @aihu:island` marker via `_parseIslandMarker()`) are
* emitted with a minimal HTML-only registration shim that ships **zero**
* `@aihu/runtime` and `@aihu/signals` JS to the browser. Components
* classified as `'interactive'` retain the full runtime path.
*
* Setting `islands: false` opts every component back into the unified
* runtime path (Plan 3.2 baseline behaviour).
*/
islands?: boolean
/**
* Project-wide rendering mode applied to every `.aihu` SFC compiled
* by this plugin instance. When set, the plugin post-processes the
* compiled JS to inject `, { shadowMode: '<mode>' }` as the third arg
* to the emitted `defineElement(tag, defineComponent(...))` call.
*
* BINARY vocabulary (DA4 #437):
* - `'shadow'` — shadow DOM (`attachShadow({ mode: 'open' })` internally;
* open is the only browser mode aihu's composition/hydration
* can use). `this.shadowRoot` is the non-null root.
* - `'light'` — **no shadow root.** The component mounts into its own
* element (`this.shadowRoot === null`). Required for global
* utility-class CSS frameworks like Tailwind, UnoCSS, Pico
* that rely on the cascade.
*
* Per-file override: the `$shadow: 'light' | 'shadow'` macro outranks this
* config. Unset, pages/layouts default to `'light'` and leaves to
* `'shadow'`.
*/
shadowMode?: 'light' | 'shadow'
/**
* Build target threaded to the compiler binary (`--target`). Defaults to the
* compiler's `universal` target (current behaviour). Set to `'client'` for a
* browser bundle that must NOT ship the server `__agentBinding` (policy) and
* instead gets the policy-free `@agent` opaque-ID dispatcher + the per-instance
* `_registerAgentDispatcher` wiring the capability bridge reads after mount.
* See `examples/agent-driven-demo`.
*/
target?: 'client' | 'server' | 'universal'
/**
* Directory (relative to the project root) holding layout SFCs. Default:
* `'src/layouts'`. Files under this directory are compiled in **layout mode**:
* their custom element is registered under the namespaced tag
* `aihu-layout-<stem>` (a layout stem like `app` is not a valid custom-element
* name on its own), and their `<outlet>` lowers to a **passive**
* `data-aihu-outlet` marker rather than the reactive route-driven boundary —
* because `@aihu/app`'s client renderer fills the marker imperatively and the
* reactive boundary would otherwise clear it on mount.
*
* Kept in sync with `@aihu/router`'s `layoutTagFor()` (`virtual:aihu-layouts`).
*/
layoutsDir?: string
}Options for `aihuCompilerPlugin()` (Plan 3.3 — Islands).
CompileEnvelopeinterface CompileEnvelope {
envelope: number
targets: Record<string, { js?: string; manifest?: string }>
astJson?: string
routeJson?: string
diagnostics: unknown[]
}The wire shape of a compile envelope (Rust `Envelope`, camelCase).
CompileEnvelopeOptionsinterface CompileEnvelopeOptions {
tag?: string
path?: string
targets?: string[]
emits?: Array<'js' | 'ast' | 'route' | 'manifest'>
strictTemplates?: boolean
exprParser?: string
}Options forwarded to the Rust envelope API (Rust `EnvelopeOptions`).
RouteMetainterface RouteMeta {
pattern?: string
name?: string
layout?: string
middleware?: string[]
ssr?: boolean
params?: string[]
head?: unknown
/**
* GX Phase 1 fan-out (#437-GX): the resolved `extract` policy — always
* present in the binary's route-json output since 0.1.12 (the default is
* recorded, never implied by absence). Typed loose here: consumers
* normalize fail-closed (`deriveReadPolicy` in `@aihu/server`).
*/
extract?: { read?: unknown; call?: unknown }
/**
* GX Phase 4 fan-out (#466): the `data:` governed-resource declaration
* (70-governed-data-access §2.1) — present only when the route declares one
* (0.1.14+). `type` keys the server registry's provider; `preview` lists
* the locked-state fields (omitted when none declared). Consumers: the
* server runtime's boot validation + generated loader, and the router Vite
* layer's C486 sibling-loader conflict check (§4.7).
*/
data?: { type?: string; preview?: string[] }
}Structured `@route` metadata (the `.route.json` sidecar shape).
SfcAstinterface SfcAst {
/** Resolved custom-element tag name (meta.name → route.name → file stem). */
tag: string
/** AST schema version — bumped on any breaking shape change (semver-tied). */
astVersion: 1
/** The @style block, if the SFC declared one. */
style: SfcStyleBlock | null
/** Parsed template tree. null when the SFC has no @template block. */
template: SfcNode[] | null
/** SFC-level metadata. */
meta: SfcMeta
}Top-level AST export — one per .aihu SFC.
SfcMetainterface SfcMeta {
/** From @meta { name } / @route { name } / file stem — never null after resolution. */
name: string
}SfcStyleBlockinterface SfcStyleBlock {
/** Verbatim CSS body of the @style block (braces stripped, $global token removed). */
content: string
/** 'scoped' (default) or 'global' (@style { $global ... }). */
scope: 'scoped' | 'global'
}SfcAttrtype SfcAttr =
| { kind: 'static'; name: string; value: string } // Form A
| { kind: 'binding'; name: string; expr: string } // Form B
| { kind: 'macro'; name: string; value: SfcMacroValue }Discriminated union mirroring Rust `Attr` — the three class-forms key on `kind`.
SfcMacroValuetype SfcMacroValue =
| { form: 'quoted'; value: string }
| { form: 'curly'; expr: string }
| { form: 'boolean' }SfcNodetype SfcNode =
| { kind: 'element'; tag: string; attrs: SfcAttr[]; children: SfcNode[] }
| { kind: 'macroElement'; name: string; attrs: SfcAttr[]; children: SfcNode[] }
| { kind: 'text'; value: string }
| { kind: 'interpolation'; expr: string }
| { kind: 'ifBlock'; branches: Array<{ cond: string; body: SfcNode[] }> }
| {
kind: 'eachBlock'
list: string
item: string
idx: string | null
key: string | null
body: SfcNode[]
emptyBody: SfcNode[] | null
}
| { kind: 'htmlBlock'; expr: string }Discriminated union mirroring Rust `TemplateNode`.