Skip to content

Game protocol v1

How a game integration (a mod) or a screen (an overlay, a phone page) talks to the hub. You can write an integration in any language that has JSON and WebSocket.

The source of truth is packages/protocol/src/messages.ts. JSON Schema files for other languages are in packages/protocol/schema/. The Hollow Knight mod (C#) and the simulator (TypeScript) are working examples.

When the hub starts, it writes a discovery file:

  • Windows: %APPDATA%\game-learning\hub.json
  • macOS: ~/Library/Application Support/game-learning/hub.json
  • Linux: ~/.config/game-learning/hub.json
{ "protocol": "1", "port": 47474, "token": "3f9c…", "pid": 1234 }

If the file is missing, the hub is not running. Retry every few seconds.

Open ws://127.0.0.1:<port>/. The first message must be hello (within 5 seconds):

{
"type": "hello",
"protocol": "1",
"role": "game",
"token": "<token from hub.json>",
"integration": { "id": "hollow-knight", "name": "Hollow Knight mod", "version": "0.1.0" },
"game": { "id": "hollow-knight", "name": "Hollow Knight" },
"capabilities": {
"events": ["player.died", "player.rested"],
"effects": ["currency.grant", "health.restore"]
}
}

The hub answers { "type": "welcome", "protocol": "1", "sessionId": "…" }, or { "type": "error", "code": "unauthorized" | "unsupported-protocol" | "bad-message", "message": "…" } and closes.

Declare only what you really support. The hub offers a reward only if the game listed its effect.

{
"type": "event",
"id": "<unique id, e.g. a UUID>",
"name": "player.died",
"at": "2026-11-21T13:05:00Z"
}

data is optional, for example { "scene": "Crossroads_01" }. The hub ignores repeated ids, so retrying is safe.

Name When
player.died The player died
player.rested The player sat at a safe spot (a bench, a bed)
boss.started / boss.ended A boss fight starts or ends
scene.changed The player moved to another room or level (data.scene)
area.entered The player entered a different region (data.area), e.g. Greenpath
loading.started The game started loading (a room change): a good moment for a fact
npc.talked The player started talking to a character (data.npc)
game.paused / game.resumed The game was paused or resumed

Game-specific events use a prefix: hollow-knight:charm.equipped.

The hub may ask the game for a reward:

{ "type": "effect", "id": "e-123", "name": "currency.grant", "params": { "amount": 50 } }

Apply it on the game’s main thread, then answer:

{ "type": "effect.result", "effectId": "e-123", "status": "applied" }

status is applied, rejected (you chose not to, for example during a cutscene) or failed (an error; add message). The player is told about the reward only after applied.

Name params Meaning
currency.grant amount Give in-game money (Geo in Hollow Knight)
health.restore amount Restore health
message.show text, language Show a short message in the game

Screens say hello with "role": "client" and a client object instead of integration/game. They receive state, challenge, feedback and reward messages, and send answer and dismiss. The answer to a question never reaches a screen before the player answers.

Any screen can say what it is, so the hub can adapt (all optional):

"surface": { "kind": "phone", "input": ["touch"], "audio": true, "lineLength": 32 }

kind: overlay, phone, tablet, tv, web, terminal, in-game. input: keyboard, mouse, touch, controller, voice.

  • Screens put it in their hello ("surface": … next to client).
  • Play state: a game that declares play.started sends it when a save is loaded and play.stopped at the title screen or a menu. Warm-up, timed questions, study breaks and play time then wait for actual play. Games that do not declare it count as always playing.
  • Settings in the game’s menu: a game with capabilities.settingsMenu: true gets { "type": "settings", "values", "locked" } on connect and after each change, and may send { "type": "settings.set", "key", "value" }. The app checks the value, saves it and applies it (most settings without a restart); the game gets settings again after every change, also changes made in the app. Refused while a PIN locks the settings.
  • Hints: a challenge with hints: n lets the player ask for up to n hints: { "type": "hint.request", "challengeId" }. The hub answers every screen with hint (removeChoices: all greyed-out choice indexes so far, keys keep their numbers; text/title: a clue or the lesson part; remaining). A right answer after a hint earns half the reward and is scheduled as “hard”.
  • Study breaks: the hub sends break (state: started, progress, ended; unlock, done, needed, skippable). Games with their own UI pause until it ends; other screens cover the game. Questions come as usual during the break. A screen may send { "type": "break.skip", "breakId" } when skippable.
  • Lessons and facts: the hub may send a lesson (id, title, Markdown body) before a question, e.g. at a bench; the screen shows it with a Continue button and answers { "type": "lesson.done", "lessonId" }, and the hub then asks the question. A fact (text, optional source) is shown without stopping play (e.g. while loading) and needs no answer. Games with their own UI get both too.
  • Question kinds: a challenge view is multiple-choice, true-false, typed, ordering (shuffled items) or matching (left in order, right shuffled). Answers are { "kind": "choice", "index" }, { "kind": "boolean", "value" }, { "kind": "text", "value" }, { "kind": "order", "items": [...] } (item texts in the chosen order) or { "kind": "pairs", "right": [...] } (the partner of each left item). A surface lists what it can show in questionKinds; without it, only multiple-choice and true-false are sent to it.
  • Games that can show questions in their own UI put it in capabilities.surface. They then receive challenge, feedback and reward like a screen, and may send answer and dismiss. A game without capabilities.surface that sends an answer gets a bad-message error.
  • The companion in the game: a game that draws the companion itself sets capabilities.companion: true. While it also shows the questions, state marks it with "drawsCompanion": true, so other screens can hide their own companion (the desktop overlay does when the player’s companionInGame setting is on). The settings message also carries language (the content’s language) for the game’s own text.
  • The state message marks such games with "showsChallenges": true, so other screens can step back (the overlay then only reads the question aloud). The player can turn this off (questionScreen: "overlay"); the game then gets showsChallenges: false and no challenges.
  • The Hollow Knight mod is the reference: it pauses the game, draws the card, and reads keyboard and controller (integrations/hollow-knight/src/QuestionCard.cs).

This is how console players can learn inside a game (for example through a Minecraft Bedrock server). See PLATFORMS.md.

Within v1, changes only add optional fields and new message types. A breaking change means protocol 2, and the hub will speak both for a while.