Skip to content

hue transformer pipeline — Architecture Requirements

Status: architecture · researched · Date: 2026-07-23 · Scope: the pluggable transformer pipeline hue's document processing is (or becomes) — parse → transform → compile, modeled on unified.js, markdown-it, and babel. Existing features (highlighting, injections, overlays, folding, navigation, media, twoslash, semantic refinement) are transform plugins; the ANSI / HTML / GUI / TUI renderers are compilers. Likely a sparkles:syntax-hosted (or sibling) processor layer; hue is the first consumer.

NOTE

Forward-looking architecture — researched/not started. hue already has an implicit pipeline: parse (highlightInjected + the markdown model) → an event/model → render (ANSI/HTML/GUI consume the identical stream, ENG3). This spec makes that a plugin seam so the growing feature set composes instead of accreting. Status legend and IDs: see the overview.

Design & rationale

The prior art converges on one shape — a three-stage pipeline with a plugin chain in the middle:

Stageunified.jsmarkdown-itbabelhue
Parseparse → mdast/hastblock/inline rules → tokensparse → ASTtree-sitter CST + markdown model + event stream
Transformtransformer pluginscore ruler + pluginsvisitor pluginsXFM plugins (this spec)
Compilestringify/compilerrenderer rulesgeneratorCMP compilers (ANSI/HTML/GUI/TUI)

hue's feature set has been growing as a set of separate concerns that each read the model and add something — decorations, fold ranges, reference targets, media blocks, semantic kinds. That is a transform chain; naming it one makes the concerns compose (ordered, dependency-aware) rather than accrete as ad-hoc passes.

The pipeline (PIP)

IDRequirementStatusTraces to
PIP1hue's document processing must be a pluggable pipeline — parse → transform → compile — modeled on unified.js / markdown-it / babel; each stage extensible by plugins composed into a processor.researched/not-startedproposed processor layer (sparkles:syntax or sibling)
PIP2The stages operate over a shared document model — the tree-sitter CST + the markdown model + the offset-based highlight-event stream; the model is the contract between stages.partialsparkles:syntax engine + md/model.d (ENG3)
PIP3A processor is configured by attaching plugins in order (parsers, transformers, compilers) plus shared data/options; the same processor runs across every backend — the backend is a compiler choice.researched/not-startedproposed processor API
PIP4Plugins must compose and order deterministically — a plugin may depend on an earlier plugin's output (e.g. semantic refinement after base highlighting); ordering is explicit, not incidental.researched/not-startedproposed ordering contract
PIP5The pipeline must be the single seam existing features plug into: highlighting, injections, overlays, folding, navigation, media, twoslash, semantic refinement are XFM plugins; the renderers are CMP compilers.researched/not-startedthis spec (unifying claim)
PIP6Interop — the pipeline should map onto the unified / rehype / remark ecosystem so the web integration can expose a unified-compatible processor / Shiki transformer.researched/not-startedweb-integration.md PKG5

Parse stage (PRS)

IDRequirementStatusTraces to
PRS1Parsing must be pluggable per language/format — the tree-sitter engine (code), the markdown structural parser (MdDoc) — producing the shared model; an unbundled grammar/format falls back to plain text (totality).partialcanonicalLanguage/highlightInjected; md/model.d
PRS2The parse stage must expose both the offset-based event stream and the structural tree, so transformers can work in whichever representation fits (spans vs nodes).partialHighlightEvent stream; CST/MdDoc

Transform stage (XFM)

IDRequirementStatusTraces to
XFM1A transformer is a plugin model → model that annotates, rewrites, injects, or decorates; it runs in the processor's order over the shared model.researched/not-startedproposed transformer contract
XFM2Transformers must be able to add decorations/overlays (the overlays OVL model), derived data (fold ranges FSR, reference targets REF, media blocks MDB), and node rewrites (injections, the twoslash node overlay) — all as plugins.researched/not-startedoverlays.md; folding.md; navigation.md; media.md
XFM3A transformer may run a nested pipeline — highlight a fenced block in another language, re-highlight a twoslash popup signature — the reentrancy injections (ENG1) and twoslash already need.partialhighlightInjected; twoslash highlightSignature
XFM4A semantic transformer may enrich the model from an external analyzer (sparkles:dmd-lsp — semantic tokens, definitions) after the syntactic transformers (PIP4 ordering).researched/not-startedtwoslash.md DMD*; SEM1

Compile stage (CMP)

IDRequirementStatusTraces to
CMP1Compiling must be pluggable per target — ANSI, HTML, GUI (raylib), TUI (cells) — each a compiler consuming the transformed model; adding a backend adds a compiler, not touching parse/transform.partialrenderAnsi/renderHtml; GUI/TUI painters (ENG3)
CMP2Per-construct render rules must be overridable/extensible by plugins (the markdown-it renderer-rules / unified handlers pattern) — e.g. how a callout, a media block, or a twoslash popup renders in a given target.researched/not-startedproposed render-rule registry
CMP3Every compiler must satisfy the totality law — an unknown construct degrades to a plain rendering, never a crash (gui.md RND5).full (74d8f6a3)RND5/ENG4 (existing renderers)

Milestones

MilestoneScopeStatusRequirements
P0Formalize the current implicit parse→transform→compile flow as an explicit processor APIresearched/not-startedPIP1PIP3, PRS*
P1The XFM transformer seam — land overlays / folding / navigation / media as pluginsnot startedXFM1, XFM2
P2Overridable compiler render rulesnot startedCMP2
P3Formalized nested-pipeline reentrancy + semantic transformer orderingnot startedXFM3, XFM4
P4unified / rehype interop for the web packagenot startedPIP6

Feature → stage map

Every hue feature lands on a pipeline stage — the concrete payoff of naming the seam:

FeatureStage
Highlighting, grammar loading (ENG)PRS (parse) → base XFM
Injections (ENG1)XFM3 (nested pipeline)
Overlays — twoslash / coverage / tracing / TSI / CSZ / source-map (overlays)XFM2 (decorations)
Content folding fold ranges (folding FSR)XFM2 (derived data)
Navigation reference targets (navigation REF)XFM2 (derived data)
Images / diagrams / math (media MDB)XFM2 (media blocks) → CMP
Semantic refinement (sparkles:dmd-lsp, SEM1)XFM4 (semantic)
Diff passes — pairing / word refinement / noise classification / structural (diff-view DVM/DVN)XFM2 (derived data) — ships standalone first
ANSI / HTML / GUI / TUI renderersCMP (compilers)
@sparkles/hue unified/rehype interop (web)PIP6

UI architecture · Overlays · Web integration · General requirements · Overview