Files
de-praxis/docs/campaign-system.md
juli 65fdded813 Campaign catalogs
A catalog is a static index.json (de-praxis/catalog@1) listing .dpc
packages with versions and checksums. 'campaign catalog' writes one for
a folder of packages. The control panel follows catalog URLs, shows new
campaigns and updates, and installs them after checking each download
against the catalog's SHA-256 (http(s) only, no redirects, size caps).
Docs cover the library, Studio, catalogs and the admin API.
2026-10-25 03:20:05 +01:00

17 KiB
Raw Permalink Blame History

Campaign system: format, studio and sharing (proposal)

Status: phases 1–5 implemented: format v1 with items, stats, private information, locations and item hand-overs; the engine runs every live room; protocol v2 with a campaign picker in the app; .dpc packages and the relay's campaign library; the Studio (/admin/studio) with flow view, play-test and simulation; catalogs with follow, install and update in the control panel and a campaign catalog command to publish one (see campaign-format.md, server-control.md and architecture.md). Not done yet: the community catalog repository on git.autisme.monster and its review rules, and author signatures. Decisions agreed on 2026-10-25:

  • Studio lives in the relay control panel (/admin/studio).
  • Sharing ships with .dpc files and catalogs, plus a community catalog repository on git.autisme.monster.
  • Rules are declarative only. No scripting.
  • v1 mechanics go beyond Dead Channel: inventory, per-player state, secret information and locations (section 1b).

Why

Dead Channel is compiled into the relay and the app. Game.kt holds its rules, scenes, clues, failure text, escalation beats and endings. Protocol.kt hard-codes its two roles and six tactics as enums that the Android client renders and uses to preview success chances. The narrator's system prompt names Dead Channel. A second campaign today means a new server and a new app release.

Goal: anyone can write a campaign, check it, play-test it, and hand it to a friend, who loads it on their relay without updating the app.

Principles

  1. Data, never code. Campaigns are declarative documents interpreted by the relay. No scripts, expressions with side effects, network access or file paths. A shared campaign is untrusted input; it must be safe to load on a public relay.
  2. The server stays authoritative. The engine evaluates every condition, roll and effect. The app renders what the snapshot says. The narrator still only adds atmosphere.
  3. Bounded by construction. Every game ends: the clock always runs down, loops are impossible, and documents have hard size limits.
  4. Dead Channel is the reference. Format v1 is done when Dead Channel, rewritten as data, produces byte-identical transcripts to today's Kotlin for the same dice sequence.
  5. Readable diffs. One text file per campaign, so campaigns can live in Git and be reviewed.

1. The format: de-praxis/campaign@1

A campaign is one JSON document (UTF-8, ≤ 512 KiB), described by a published JSON Schema so editors like VS Code give autocomplete and inline errors. JSON is chosen over YAML because the relay already parses it strictly (kotlinx.serialization), the studio produces it, and schema tooling is mature. Authors who prefer YAML can convert; the canonical form is JSON.

Building blocks

Block What it defines Dead Channel example
meta id, version, title, tagline, authors, license, language, content warnings, player count, expected length dead-channel, 1–2 operators, ~20 min
rules dice, base DC, off-specialty bonus, preparation bonus, setback step and cap, clock length d20, DC 10, +1, +3, +2/+4, 12 cycles
roles id, name, blurb, bonus per action Engineer +4 restore/contain
state named flags and bounded counters (0–99) power, decoded, sealed, discoveries
objectives label, the flag that completes it, optional Restore power, Decode signal, Contain (optional)
actions label, hint, when shown, when allowed (with a refusal reason), resolution order, check or no check, success and failure effects Observe (first), Restore, Decode, Contain, Escape (last, no roll), Improvise
scenes ordered list of condition → chapter, title, prompt; first match wins I / First contact … III / Departure
clues ordered decks drawn by effects, with a fallback per scene the three cassette clues
beats text at clock values or when state changes breathing at 8, mainland at 4, final cycle at 1
endings id, title, grade (best/mixed/bad), text, debrief line Silent Shore, Carrier, Dead Air
intro opening log entries; {crew} and {player} placeholders the alarm speaking your callsigns
narrator setting brief and style direction for the optional LLM "1986 North Sea relay horror…"

Conditions and effects

Conditions are a tiny, side-effect-free vocabulary, evaluated by the server:

{ "all": ["power", "decoded"] }                 // flags
{ "not": "sealed" }
{ "any": ["power", { "counter": "discoveries", "atLeast": 2 }] }
{ "clock": { "atMost": 3 } }
{ "role": "engineer" }                           // acting player's role

Effects are a closed list applied in order: set/clear a flag, add to a counter (clamped), prepare (self or crew), setback (grow this action's approach bonus), say (append text), draw (next clue from a deck), end (with an ending id, possibly conditional). say text supports only {player}, {crew}, {role} and {clock} placeholders: plain text, no markup.

Excerpt

{
  "format": "de-praxis/campaign@1",
  "meta": { "id": "dead-channel", "version": "1.0.0", "title": "Dead Channel",
            "tagline": "North Sea Relay 09, November 1986.", "players": { "min": 1, "max": 2 },
            "authors": ["juli"], "license": "CC-BY-SA-4.0", "language": "en",
            "warnings": ["isolation", "body horror (implied)"] },
  "rules": { "dice": "d20", "dc": 10, "offRole": 1, "prepare": 3, "setback": { "step": 2, "cap": 4 },
             "clock": { "start": 12, "label": "until contact", "onZero": "dead-air" } },
  "roles": [
    { "id": "engineer", "name": "Engineer", "bonus": { "restore": 4, "contain": 4 } },
    { "id": "analyst",  "name": "Analyst",  "bonus": { "decode": 4 } }
  ],
  "state": { "flags": ["power", "decoded", "sealed"], "counters": { "discoveries": 0 } },
  "actions": [
    { "id": "restore", "label": "Restore", "hint": "Bring the emergency power online.",
      "allowed": { "when": { "not": "power" }, "otherwise": "Power is already on." },
      "check": {},
      "success": [{ "set": "power" }, { "say": "Emergency power restored. Something knocks from inside the wiring." }],
      "failure": [{ "setback": {} }, { "say": "The breaker trips. You find the burned contact." }] },
    { "id": "escape", "label": "Escape", "hint": "Open the airlock. No roll.", "order": "last",
      "allowed": { "when": { "all": ["power", "decoded"] }, "otherwise": "The airlock needs power and the code." },
      "effects": [{ "end": { "if": "sealed", "then": "silent-shore", "else": "carrier" } }] }
  ],
  "endings": [
    { "id": "silent-shore", "title": "Silent Shore", "grade": "best",
      "text": "The airlock opens onto salt air. For the first time in thirteen years, the sea is silent." }
  ]
}

Validation

validate rejects, with a path and a plain-language message:

  • unknown fields or effect types; references to undefined flags, actions, decks, scenes or endings
  • an action or ending that no reachable state can ever trigger, and objectives that can never complete
  • a campaign where no ending is reachable before the clock runs out, found by a bounded exploration of flag states (flags × counters is small by design; the validator caps the search and reports when it gives up)
  • text fields over their limits (titles 60, hints 160, log text 1,000 characters) and documents over 512 KiB or 500 effects
  • duplicate ids, invalid semver, unknown SPDX license ids

Warnings, not errors: no best ending, a role with no bonus, unreachable clues, very long or very short clocks.

Versioning

format carries the format version; relays refuse formats they don't know with a clear message. meta.version is the campaign's own semver. A room pins the exact campaign file it started with (the relay stores a content hash and keeps that version until the room expires), so updating a campaign never changes a game in progress.

1b. v1 mechanics beyond Dead Channel

Each mechanic is optional; a campaign that doesn't declare it behaves exactly like Dead Channel.

Inventory

"items": [
  { "id": "fuse", "name": "Ceramic fuse", "text": "Rated for 30 amps. Warm.", "scope": "personal", "uses": 1 },
  { "id": "keycard", "name": "Duty keycard", "scope": "crew" }
]
  • scope: personal (one operator carries it) or crew (shared pool). uses makes an item consumable.
  • Effects: give (to self or crew), take, use (spend one use). Handing an item to a co-located crewmate is the built-in pass action.
  • Conditions: { "has": "fuse" } (acting player), { "crewHas": "keycard" }.
  • Actions can require an item (allowed) or grant a bonus while it is held ("bonus": { "item": "multimeter", "value": 2 }).
  • Snapshots show each player only their own personal items plus the crew pool.

Per-player state

"stats": [
  { "id": "stress", "name": "Stress", "start": 0, "min": 0, "max": 5,
    "atMax": { "status": "shaken", "say": "{player}'s hands won't stop shaking." } },
  { "id": "health", "name": "Health", "start": 3, "min": 0, "max": 3, "atMin": { "status": "down" } }
]
  • Effects: adjust a stat for self, crew, a role, or the action's target. Values clamp to min and max.
  • Conditions: { "stat": "stress", "atLeast": 3 }, { "status": "down" }.
  • Statuses change what a player may do. down limits them to wait, and an optional allDown ending fires when every operator is down, so the game still always ends. Check modifiers can depend on stats ("bonus": { "stat": "stress", "atLeast": 3, "value": -2 }).

Secret information

  • say takes an audience: "to": "self" | "crew" | "role:analyst" | "here". Here, here means players in the same location. Private entries are stored with their audience and filtered per token when the server builds each player's snapshot.
  • Hidden goals: a role can carry a private objective ("secret": true), seen only by its holder, revealed to everyone in the ending debrief.
  • Clue decks can be personal: each player draws their own clues.
  • The optional narrator only receives entries visible to the whole crew, so atmosphere can never leak a secret.

Locations

"locations": [
  { "id": "control", "name": "Control room", "text": "...", "exits": ["generator", "airlock"] },
  { "id": "generator", "name": "Generator deck", "exits": ["control"], "hazard": { "stat": "health", "adjust": -1, "chance": 0.25 } }
],
"start": "control"
  • Every player has a position. A built-in Move action lists the exits and costs the turn. Exits can be gated by a condition ("locked": { "not": "power" }).
  • Actions and scenes can be tied to places ("at": "generator"). The app shows only actions available where you stand, and the scene of your own location.
  • Players can split up. Combined with "to": "here", that is how one operator learns something the other doesn't.
  • Conditions: { "at": "airlock" } (acting player), { "crewAt": "airlock" } (everyone).

Limits

To keep validation tractable and games short: at most 32 flags, 16 counters, 24 items, 4 stats, 24 locations, 60 actions and 6 players. The validator's reachability search abstracts per-player positions and stats. When it can't prove an ending is reachable, it reports that, and the author confirms with simulate.

2. Engine and protocol changes

  • Interpreter: replace Campaign in Game.kt with a generic engine that executes a validated campaign. Keep today's guarantees: simultaneous submission, crew order with first/last ordering, idempotent request ids, redundant-task preparation, the hard clock limit and room size caps. Room state becomes { flags, counters, setbacks, decks } instead of fixed fields.
  • Parity test: load campaigns/dead-channel.json, replay scripted dice for every ending path and compare transcripts with the current implementation. Remove the Kotlin campaign only when they match.
  • Protocol v2: Role and Intent stop being enums. Snapshots carry the campaign's meta, roles, and per-player actions: [{ id, label, hint, enabled, reason, check: { dc, bonus, chance } }]. The server computes the check preview, so the app needs no rules. CreateRequest gains campaignId. /health reports api: 2 so the app can tell an old relay to update rather than failing.
  • Narrator: the system prompt takes the campaign's narrator.brief and the relay's style setting; the safety contract (no new facts, player text is untrusted) stays in code.
  • App: a campaign picker on Create (cover, title, tagline, players, length, warnings); everything else already renders from the snapshot. A joining player sees which campaign the room uses.

3. Creation tool: the Studio

Recommended: a Studio page in the relay's existing control panel (/admin/studio), same design language and access rules (localhost, SSH tunnel or --lan-admin).

  • Form-based editing for every block, plus a raw JSON tab with schema validation; both stay in sync.
  • Live validation panel with clickable errors.
  • Flow view: objectives, actions and endings drawn as a graph from their conditions, highlighting dead ends.
  • Play-test: runs the real engine on the relay against a throwaway room, with optional forced dice ("make this roll fail") and a state inspector. Because it is the same interpreter, there is no second rules implementation to drift.
  • Start from a template (blank, one-room escape, Dead Channel copy).
  • Optional, behind the existing LLM settings: "suggest variants" for clue and failure text. Suggestions are inserted as drafts the author must accept; the model never writes rules.
  • Export a package; save to the relay's library.

Plus a CLI for authors working in Git and for CI:

server campaign validate my-campaign.json
server campaign pack my-campaign.json --cover cover.png    # → my-campaign.dpc
server campaign simulate my-campaign.json --runs 1000      # ending distribution, average length

simulate plays random legal actions with real dice and reports ending rates and round counts, to catch campaigns that are unwinnable or trivially short.

4. Packages and management

Package: .dpc is a ZIP containing campaign.json, optional cover.png (≤ 1 MiB, ≤ 1600 px, re-encoded on import) and an optional README.md. It also holds manifest.json, with the format, id, version, title, license, authors, SHA-256 of each file, and optional signature. ZIP entries are size-checked and path-checked on import (no zip-slip, no compression bombs: 4 MiB unpacked total).

Relay library (DATA_DIR/campaigns/, managed from the control panel):

  • Import from a file upload or URL; export any campaign as .dpc.
  • List with title, version, author, license, validation state, and how many rooms use each version.
  • Enable or disable a campaign for new rooms; set the default; keep older versions while rooms still use them; delete unused versions.
  • Dead Channel ships built in and cannot be deleted, only disabled.
  • MAX_CAMPAIGNS (default 50) to cap storage on public relays.

5. Sharing

Three levels, in order of effort:

  1. Files: send a .dpc in any chat or Git repo; import it in the control panel. Works on day one.
  2. Catalogs: a catalog is a static index.json listing packages, their versions, hashes and download URLs, hostable on any web server or Git forge release page (like an F-Droid repository). Relay owners add catalog URLs in the control panel, browse them, and install or update campaigns with one click. Hashes are checked on download. A de-praxis community catalog could live in a Git repository where campaigns arrive by pull request and CI runs validate and simulate.
  3. Signatures (later): authors sign manifests with an Ed25519 key; catalogs list trusted author keys; relays show "signed by …" and warn on key changes. Not needed for files shared among friends.

Licensing: meta.license is required, and the Studio defaults to CC BY-SA 4.0 so shared campaigns can be remixed. The game's GPL license covers the code, not campaign content.

Security notes

Campaigns are untrusted. The interpreter has no loops, no recursion beyond the fixed condition depth (8), and bounded counters. Text is rendered as plain text in the app and escaped in the panel. Imports run validation before anything is stored. Catalog downloads use the relay's outbound HTTP limits and size caps, and are admin-only. Room files reference campaigns by hash, so a malicious update can't alter running games.

Delivery plan

Phase Outcome Rough size
1 Format v1 schema, engine interpreter, Dead Channel as data with parity tests, validate CLI largest step
1b Inventory, per-player stats, audiences and hidden goals, locations; a small sample campaign that uses all four large
2 Protocol v2, app campaign picker and server-provided action previews, API version check medium
3 .dpc packages, relay library in the control panel, import/export medium
4 Studio editor, flow view, play-test, pack/simulate large
5 Catalogs and a community catalog repository; signatures later medium

Each phase ships independently. After phase 2 a second campaign can be played; after phase 3 it can be shared as a file.

Still open

  1. Default content license for Studio-created campaigns (proposed CC BY-SA 4.0).
  2. Player count: the format allows up to 6 operators, but the relay and app are built for 1–2. Raising the room size is a separate change.
  3. Community catalog rules: who reviews pull requests, and whether content warnings and a minimum simulate win rate are required.