Extensions

An extension is an npm package adding what a game system lacks: rules as text, master’s instructions, a calendar, code. A campaign plays one system and any number of extensions. Ours: rpg-engine-weather, rpg-engine-lockpicking.

1. The package

rpg-engine-<name>/
  package.json       name, version, main, the "rpg-engine" field, the keyword rpg-engine-package
  extension.yaml     what it is (section 2)
  instructions/*.md  its parts of the master's instructions
  words/<code>.yaml  its words in other languages (section 4)
  images/            pictures its widgets show
  src/, dist/        its TypeScript code, built to dist/
  test/              its tests, not shipped
"rpg-engine" key Meaning
kind "extension"
api the package API it is made for
system the game system it needs, so the catalog warns before downloading
page its page module (section 3)
  • bugs, or a GitHub repository, gives the dashboard’s “Report a problem” link.
  • The name without scope prefixes its commands: @rpgengine/weather gives weather, weather-set.
  • api covers the code contract and what the yaml may declare; it rises with each addition an older engine would misread. Name the lowest API with what you use (the list is in declarations.ts).
  • The engine reads extensions from API 1, systems from 5, up to its own. Newer is refused before installing; older than the range asks for a newer package.

2. extension.yaml

title: the weather by the climate score, by Stefano Caronia
about: the sky changes each dawn by a roll
language: en
attribution: Weather by the climate score, by Stefano Caronia, under CC BY 4.0.
needs: {system: 5e}
calendar:
  months:
    - {name: Thaw, days: 90, season: spring}
Key Meaning
title, about, language required; status gives about to the master
attribution the licence line it requires
needs {system} it is made for
calendar months replacing the core’s; the campaign’s own wins
fields, tables, computed, counters, recipes, values additions to the system, as in campaign.yaml
condition-icons drawings of effects by name
icons SVG paths on 24×24, stroked in the dashboard’s colour; at most 40
widgets at most 8 (below)
figures {width, height, mirror?} of each page-code figure; at most 8

An unknown key is refused by name.

  • Layers: the system, the extensions in campaign.yaml’s order, the campaign; the nearest wins.
  • fields, tables, computed, counters, condition-icons replace a same-named entry below; a recipe adds to the one below; values adds names to lists.
  • Naming a core field (role, status, contains) leaves the extension out; additions the system cannot read are left out. validate reports both.

Widgets

icons:
  rain: "M7 14.5h10a3.5 3.5 0 0 0 .4-6.98A5.5 5.5 0 0 0 6.6 6.5a4 4 0 0 0 .4 8Z"
widgets:
  now: {title: Weather, icon: rain, place: top}
  today: {title: Today's weather, icon: rain, place: page, page: scene, order: 0}

A widget has title (40 characters), icon (from icons), place, page (with place: page), where (with place: top) and order (lowest first). Its hook of the same name draws it.

place Where
top a chip in the top row; where: top puts it beside the campaign’s name; hidden on a phone
side a card in the table’s column
page a card at the end of scene, sheet, world or journal
person on each party member
card only in a question’s card its code asks
  • campaign.yaml moves or hides one (Settings writes it): widgets: {weather.today: side}, with top, side, person, a page, off or {place, page, order}.
  • A person widget can only be off; a card widget cannot move.

3. Code

main is a module whose default export takes the kit and returns the package’s code, every part optional. A game system’s code has the same contract; the types come from rpg-engine.

import type { PackageEntry } from "rpg-engine";

const weather: PackageEntry = ({ z }) => ({
    commands: [{ name: "weather", description: "…", input: z.object({}), readOnly: true, run: (input, game) => "…" }],
    timePassed: ({ from, to }, game) => ["Weather this morning: …"],
});
export default weather;
Part Signature When
commands {name, description, input, run(input, game), readOnly?, positionals?, player?, needsPlayer?}[] on the command line and MCP; input in the kit’s zod; run returns the master’s text
timePassed ({from, to}, game) => string[] after advance/travel, once per call, and at game start
widgets {[name]: (game, asked?: {key?, who?}) => Widget \| undefined} as the dashboard reads the game
counterChanged ({page, field, before, after, max, lost}, game) => string[] after change or a rest wrote a counter
turnStarted ({who}, game) => string[] as a turn starts
rolled ({who, notation, total, faces, dice, text, id, check?, why?, target?, asked?}, game) => string[] after a logged, not hidden, roll
effectAdded ({page, effect}, game) => string[] after an effect is added
asking ({who, checks, notations, recipe, target}, game) => Asking \| undefined words a core ask; the first answer wins
  • Command descriptions are at most 150 words. player: true lets page code run it; needsPlayer: true (it calls game.ask) tells MCP hosts it waits for the player.
  • Hooks after writes run the system’s first, then extensions in order; synchronous, at most five lines and 600 characters per package. A failure is a line; the change stands.
  • rolled: target carries met and natural; asked: {check} only for the package that asked. asking: target.screened when the player may not see it.
  • An extension may not share its campaign’s system’s name.

The game

game is all the code reaches; widgets and asking get only the reading part.

Member What it does
now(), calendarDay(day), units() game moment, calendar date, metric/imperial
setting(name), sameName(a, b) a campaign setting; names compared as the engine does
party() {places, environment, members: {name, pc}[]}
page(name) by name or alias, or a copy in the scene: name, pc, party, value(field), counter(field), has(effect), carries(thing), formula(text)
scene() {title, opened, round?, turn?}
state.read(), state.write(v) its state, extensions/<name>/state.yaml
log(text, visibility?) a public or hidden log line
roll(notation, by?) unlogged; with {who, why, check?, values?, says?, tones?} logged for who, values being physical dice. Gives {notation, total, faces, dice, text, id?, hidden?}
ask(asked) asks the player for a roll (below)
set(page, values, why) writes fields as write --set; throws what it refuses
change(page, field, {by \| to \| spend}, why) as change, for counters the rules watch; hooks run only from a command
addEffect, endEffect (page, name, why) add an endless effect, end one
  • It writes no other file. After the call stops (as while ask waits), writes and rolls with who throw.
  • Code runs in the chat server: a loop that never yields stops the dashboard and the master’s tools.

ask({who?, question, check, notation, target?, roll?, decline?, rule?, says?, tones?, card?}):

  • target as the core’s (">= 15, natural 1 fails"); roll, decline are button words, text or {label, note}; decline: false forces the roll; rule is a line under the buttons.
  • says(faces) replaces the total (4 pins, no 1); tones(faces) marks each die good or bad.
  • card: {widget, key} asks in one of its widgets, one key per attempt; it shows before and after the dice, so write the state first.
  • Gives {rolled: {id, total, faces, text, met?, natural?}}, {declined: true}, {said}, or {inWords, physical} where no buttons show.

Widget hooks

widgets: {
    now: (game) => ({ icon: "rain", chip: { text: "{range}", values: { range: { from: 10, to: 15, unit: "°C" } } }, says: "scattered rain" }),
},
  • Reads only; all hooks share two seconds, and a late one is skipped until it answers. asked is {key, who} in a question’s card, {who} in person or when page code names it.
  • The player sees what it returns: no secrets. Checked and cut at about 12,000 characters; /api/widgets says why one shows nothing.
  • Words are translated as whole texts; numbers go in values: {text: "From {low} to {high}", values: {low: 10, high: 15}}. A value is a number, text, {number, unit} or {from, to, unit}.
Widget key Meaning
icon, chip, says chip icon, text, tooltip
note, parts card head note; card body
tint low, ally, gold, muted: a question card’s frame
dead in person, drawn as dead
data, body for page code
Part Shape
lead {lead, icon?, value?, tone?, figure?}
who {who, does?}
text, facts {text}, {facts: [...]}
values, rows {values: {label, value}[]}, {rows: {label, value?, note?}[]}
track {track: {label, value, max, look?, held?, marked?, coming?, stage?, tone?, figure?, field?}}
table, image {table: {head, rows}}, {image, alt} from images/
  • track: pips to ten, else a bar; look pips (to twenty), bar or steps; field names the counter. In a question card, stage places it and held, marked, coming light pips.
  • person: read per member. A chip given only while down says their state; others are small cards of boxes.

Code in the dashboard’s page

An extension or a game system may draw in the page with its own code, in the dashboard’s style.

  • page names an ES module inside the package, served at /pkg/<package>/<version>~<print>/ and listed at /api/modules. It imports preact and rpg-engine/page from the page.
  • A widget’s data (short JSON) reaches only the page. A card or page naming a widget as widget gets its data for the character shown.
  • An error shows in its card, saying whose; a failing group falls back to the dashboard’s.
Default export What it gives
figures components drawing a track or lead with figure, declared in the yaml
bodies components drawing a roll card’s inside, named by body
style a style sheet over the dashboard’s layers, not its focus ring and tooltips
cards {page, title, icon, order} cards at a page’s end
pages {title, icon, nav?} pages at #/pkg/<package>/<name>; nav: "tab" for a tab
groups system only: components for its sheet groups, as {Stats: StatsDial}
pageStyle system only: unlayered style over the whole page; classes are no contract
Prop For Meaning
data, before figure, body the data now and before
name, part, place, size figure the part it draws, where, its room
words, number, field, fieldName all the page’s words and numbers, a field’s short and full name
language, dir, theme, reducedMotion all page context
freeRoll(field, who?) all an unlogged roll of a sheet number
run(command, input) all runs a player: true command via POST /api/run
buttons, answer(button), sent, ended body the question’s buttons and state
prompt, rule, parts, target, rolled, rest body the question, its target, the last roll, a rest’s dice
name, title, who, values, value(field), roll(field), asked(field), answer(), explain() group its fields, any sheet field, rolls, the check it answers
  • A screened target is {screened: true}, then {met, natural?, screened: true}.
  • Parts: Button, Icon, Dice, Track and the rest, statusIcons, and <Counter value={…} />, a sheet value drawn as the sheet does; as="bar"/"marks" and label override.

4. Words

words/<code>.yaml gives its words in a language; pt serves pt-BR.

title: la météo selon le score de climat
words: {Weather: Météo, "From {low} to {high}": "De {low} à {high}"}
fields: {lockpicking-rerolls: Relances de crochetage}
  • Keys: title, about, fields (its added fields’ names), words (its code’s texts).
  • A missing word stays as written; the first letter’s case does not matter. A broken file is ignored and validate names it.

5. Installing

The package command; --json returns data.

Action What it does
list packages on this computer and in the campaign
available what npm has for this API, and updates
install <name> installs or updates without its scripts; adds it to campaign.yaml
remove <name> takes it out of the campaign
uninstall <name> takes it off the computer
new "<title>" --kind extension a skeleton with example, tests and CI; --kind system too
  • A bare name is ours, under @rpgengine/, verified. Others need their scope or npm:name; folders and .tgz files are never verified.
  • It installs the newest version this engine reads; offline, from npm’s cache.
  • status tells the master of updates, at most daily; it never updates.
  • A package not ours installs and runs only after the player’s yes in the host’s form or an OS window, valid for that version and files; another version or a changed file asks again.
  • The same command installs every kind, told by the file at its top: a game system (system.yaml), a language (language.yaml, from npm too), an adventure (adventure.yaml), a theme (theme.yaml).
  • Data packages (adventures, themes, languages) come from a GitHub link, a .zip or a folder. A GitHub repository carries the topic rpg-engine-adventure, rpg-engine-theme or rpg-engine-language; its link reads the default branch, or the branch or tag after /tree/.
  • A theme or a language is unpacked once for every campaign on the computer, and updated only from the repository it came from. Its engine in the yaml, quoted (engine: "0.22"), is the lowest RPG Engine that reads it.
  • package install <folder> --link reads a theme where it is, so its author sees each change live; package new "<name>" makes a theme from a template and links it.
  • The dashboard’s Packages page installs by a link, an npm name, a folder or a file, and lists what npm and GitHub’s topics offer.

6. Tests

A package tests itself with rpg-engine/testing, part of the package API.

import { testCampaign } from "rpg-engine/testing";

const campaign = await testCampaign({ system: "5e", extensions: [fileURLToPath(new URL("..", import.meta.url))] });
campaign.dice(3, 2, 6);
expect(await campaign.ok("advance", "--to", "day 1, 18:00")).toContain("Weather:");
await campaign.close();
Function What it does
testCampaign({system, systems?, extensions, language?, play?, settings?}) a temporary campaign, set up unless play: false; systems from systems, node_modules, then free
run(...args), ok(...args) a command’s {output, exitCode}; one that must succeed
dice(...faces) next faces, 4 until given, a throw once they run out; time is a fixed day
ask({question, options?, who?, square?, recipe?, toss?, target?}) the core’s ask, answered via context
descriptions() the core’s tools as a host reads them
log(), read(path) log lines; a campaign file
widgets(name?) widgets as shown, each with its problem
dashboard() the dashboard on a local port: player, get, post
folder, context its folder; a page, a fake player whose choose answers, a signal
close() removes the campaign
systemChecks(folder) a system’s name, pages, chapters, attribution, and problem lists, empty when it passes
  • Build dist/ before testing. A 5e extension lists @rpgengine/system-5e in devDependencies.
  • npm run test:downstream runs our packages’ tests against this engine.

© 2026 Stefano Caronia · code under the MIT license