Presto, the embedded CruftScript kernel

Presto is a small cruft:presto module of HTML-templating helpers, escapeHtml, applyPipe, openTag, slugify, titleCase, and classAttr, written in CruftScript and shipped inside the binary. Calling them from JavaScript crosses a type-checked boundary that rejects wrong-typed arguments with a TypeError.

cruft:presto is a small module of HTML-templating helpers, and a large architectural statement: it is the first cruft: module implemented in CruftScript itself. Its source is a .fts file (presto-core.fts) shipped inside the binary; importing the module parses, type-checks, and boundary-wraps that sound source on first use, through exactly the pipeline any user .fts file takes. The runtime dogfoods its own language at its own module tier.

Presto, the larger system, is a templating engine; its TypeScript reference implementation lives outside this repo and is the parity reference. cruft:presto is its pure expression kernel, ported to sound CruftScript and driven to full parity with the JavaScript engine.

The API

import { escapeHtml, applyPipe, openTag, slugify, titleCase, classAttr }
  from "cruft:presto";
ExportSignature (CruftScript)Behavior
escapeHtml(s: string): string<a href="x">&</a>&lt;a href=&quot;x&quot;&gt;&amp;&lt;/a&gt;, escapes & < > "
applyPipe(str: string, pipe: string): stringNamed display pipes: "uppercase", "lowercase", "trim", "capitalize"; unknown pipe returns the input unchanged
openTag(tag: string, id: string, cls: string): stringopenTag("div", 'my"id', "hero <b>")<div id="my&quot;id" class="hero &lt;b&gt;">, id and class are escaped
slugify(name: string): string" Hello, World! 2.0 "hello-world-2-0, lowercase, non-alphanumerics collapsed to -, trimmed
titleCase(s: string): string"the quick brown fox"The Quick Brown Fox
classAttr(classes: string[]): string["btn", "", "btn-primary", ""]"btn btn-primary", empty entries filtered

The boundary, live

Because these exports are boundary(secure) CruftScript functions, calling them from JavaScript crosses a validated boundary, and classAttr's string[] parameter demonstrates the enforcement working:

classAttr(["ok", 5]);
// TypeError: argument 0 for runtime export `classAttr`
// does not conform to parameter `classes`

A wrong-typed element inside the array HALTs the call, the thrown value is a TypeError whose message is the boundary's conformance report. Record, array, and bare primitive contracts are all validated at the crossing (see the CruftScript page), so a number passed where the signature declares a string is rejected at the boundary with that same conformance report, rather than failing deeper in the function body.

Why this module matters beyond its size

  • The dogfood proof. The .fts source uses template literals, regex replace, split/map/join, filter with predicate callbacks, and optional-argument handling, real stdlib surface, exercised in production by every consumer of the module (the cruft.sh site's templating runs through this kernel). CruftScript's standard-library work prioritizes methods by what this module uses.
  • The bundling primitive. Embedding a checked .fts module into the binary through the shared module-namespace path is the pattern by which future sound modules ship; the module is the proof of concept.
  • The GC-safety anchor. Repeated JS→.fts boundary calls through this kind of wrapper once exposed a garbage-collector use-after-free on the boundary's trace path; this surface now runs thousands of crossings under GC stress.

Relation to cruft:serve

cruft:presto + cruft:serve is the intended web-page-serving pair on the primitive tier: a fetch-shaped handler assembling HTML with escaped interpolation. The broader presto engine (directives, routing, pipelines) lives in its .ts edge tier above this kernel, with behavioral parity against the reference implementation.