Writing a plugin
The plugin API is experimental, except for the v1 data source contract: outside that contract, it may change in a minor release (Stability).
Start from the template
Récit is not on npm: create-recit, which holds the template, comes as an archive of the private
channel, like the recit command line (Quickstart).
Run it from that archive:
Bash
The template is the reference plugin of the Récit repository, examples/: one of each
capability, its tests, and a build with tsdown. The package takes the name of its folder.
It needs npm 11 or later (engines.npm in its package.json). npm 10, the one Node 22 ships,
crashes while installing vitest 4.1 (« Cannot read properties of null (reading 'edgesOut') »).
create-recit says so when npm 10 runs it; update first with npm install -. pnpm, yarn
and bun are not concerned.
Naming. Call the package recit-, or @scope/, and give it the
recit-plugin keyword in package.json: that is how people find it on npm. Its name in
definePlugin is the short one, acme: it prefixes your diagnostics (acme/) and your
commands (recit acme sync). A plugin cannot take the name of a command of Récit (build, ai,
plugins…).
Two entries
JSON
The Node entry declares everything, with its schemas:
TypeScript
name is how a config and the diagnostics name the plugin, api the plugin API it is written for
(1), version (optional) its own version, part of the cache key of its data sources, and
options the schema of what recit. passes it. Every capability is a module loaded only
when it is used.
The browser entry holds a name, the components and the views of the film blocks: no zod, no schema, no Node.
TypeScript
Every capability is a lazy import(): a module loads only when it is used, and each component is a
chunk of its own, downloaded by a slide that mounts it.
Each capability
| Capability | Its module's default export |
|---|---|
directives | static: a function that renders hast at build time; interactive: component, the name of one of components |
components | a React component, given the directive's parsed attributes as props |
blocks | { type, props, text?, props a zod schema; its view, defineBlock of @recit/ |
themes | a complete theme of @recit/theme, every token, whose id is its key |
exporters | { description?, returning the files it wrote |
sources | { schema?, returning { rows, columns? (Writing a data source) |
commands | { description?, returning the exit code |
ai | { jobs, provider? (AI jobs) |
hooks | configResolved: a function given the validated config, read only, once per load; a write or a thrown error is the plugin- diagnostic (experimental) |
A block's view draws in Frame of @recit/ (experimental), given its layout
(16x9 or 9x16): the scene root with the theme's background, colours and embedded fonts, so the
render is the same on every machine (recit- checks its block against a golden
still).
A directive never exists in Markdown only. Its attributes schema is required: it validates the
directive in a .md and in its JSON twin, and gives its JSON Schema. A static directive's output
goes in after sanitisation, like Récit's own: every text is a hast text node, never raw HTML.
A secret is a SecretRefSchema ({ env:), read with readSecret(secret, context.env)
when it is needed. Never read process.env at import time, never write a value into a file.
Data sources. The data source contract (sources, PluginSource, DCAT meta, the 30 s and
100,000-row bounds, .recit/ and plugin-stale fallback) is stable in v1; see
Writing a data source.
Style. A component brings its styles as one CSS module, compiled into the package, never a
utility class or a style prop: the same rule as Récit's own components.
Test it
TypeScript
Diagnostics
Report through context., with a code prefixed by your plugin's name (acme/).
Récit's own codes for plugins are plugin-, plugin-,
plugin-, plugin-, plugin-, plugin-,
plugin-stale, plugin- and plugin-. An error your plugin throws is
shown as yours, with its name, never as a bug of Récit.