墨kazokuai.dev

The game package contract

contract 1text v1.1vendored verbatim from kazokuai v0.26.1; canonical in KazokuAI's docs/game-package

Every file below is the vendored copy, byte for byte; sha256sum -c CHECKSUMS checks the three it lists.

Run the harnessa page that hosts a package (a zip or a path) by the text, and logs every message

Game package — the contract

Status: contract 1, text v1.1, 2026-10-05 (KazokuAI pass 26.1: the navigation limit stated, the Theme's shape ruled, the mute message added; still contract 1, as nothing had vendored v1.0). Text v1.0: pass 26. Written from Sumi's brief: §7 (the contract) and the rulings R2 (the package), R5 (where this lives, how it is versioned), R33 (audience), with R25 and R31 for what music and songs mean, and J's pass-26.1 rulings. Nothing here goes beyond them; where §7 left a shape open, this text picked the plainest one and the pass-26 report lists each pick.

This directory is canonical: docs/game-package/ in the KazokuAI repo — SPEC.md (this), manifest.schema.json (the manifest as JSON Schema, field for field with §2), harness.html (a page that hosts a package by this text, for checking one), VERSION (the contract number) and CHECKSUMS (sha256 of the three files). Sumi vendors a verbatim copy under spec/; a test in each repo checks the copy against the version it claims. kazokuai.dev/spec will publish it.

A package is a game as a static bundle with a manifest. A host is anything that loads one over this contract: KazokuAI's Games tab, Sumi's Play room, or a third party's page. The contract is the whole interface between a game and a host: a game never imports host code, a host never imports game code, and a package can be written with neither tool.

Words: MUST, MUST NOT and MAY are requirements; "never" is MUST NOT.

1. The zip

2. The manifest

manifest.json is one JSON object, UTF-8. Fields not listed here are refused (manifest.schema.json: additionalProperties: false).

field type required meaning
contract integer, 1 yes The contract this package speaks (§9).
id string, a slug: ^[a-z0-9]+(-[a-z0-9]+)*$, 1–64 characters yes The package's identity and the scores key. It never changes: a new version keeps its id; a different id is a different game, with its own scores and saves.
name string, not empty yes The game's name, as the tile shows it.
version string, semver 2.0 (1.4.0, 2.0.0-beta.1) yes This build's version. A host shows it and may keep several; scores and saves follow id, not version.
entry string, "index.html" yes The page the host loads. In contract 1 it is always index.html at the root.
icon string, a path inside the package ending .png, .svg or .webp yes The tile's image, as a host shows it with an <img>.
aspect array of "portrait" · "wide", at least one, no repeats yes The shapes the game can lay out to: portrait (taller than wide: a phone held upright) and wide (wider than tall: a desktop, a phone on its side). The host picks one and says which in hello; aspect tells the game when it changes.
inputs array of "touch" · "keys" · "pad", at least one, no repeats yes What the game can be played with: a touchscreen; a keyboard (and the mouse beside it); a gamepad, through the Gamepad API (§3's allow="gamepad").
save boolean yes The game keeps a save (§5). False: it never sends save and hello.save is always null.
score "high" · "none" yes high: the game sends score at the end of a run and higher is better; the host keeps a leaderboard by id. none: no scores.
music boolean yes The game asks the host for music by playlist name (§6). False: it never sends music.
audience "all" · "adult" no; absent means all Who the game is for (R33). A host's "minors can play" switch, set to everyone-rated, hides adult packages from minors (§7).
songs array of song objects (below) no The briefs the game's songs were made from (R31): never the audio.
story string, a path inside the package ending .md no The game's story as markdown (Sumi's story.md).
author string, not empty yes Who made it: a person's or a studio's name.

A song object (each field required, nothing else allowed):

field type meaning
id string, a slug like the package's The song's identity within the package: no two alike (a validator checks this; the schema can't).
playlist string, not empty The playlist the song belongs to: the name the game asks for in music {playlist}.
brief string, not empty The text the song was made from (a music model's prompt).
mood array of strings Mood words for the music model ("driving", "dark"). The list may be empty.
lyrics boolean The song has words (true) or is instrumental (false).

3. The sandbox

A host loads index.html in exactly this frame:

<iframe sandbox="allow-scripts allow-pointer-lock" allow="gamepad"></iframe>

What the sandbox cannot stop

4. Messages

Host and game talk only by postMessage, each message one JSON object { "type": …, … } with exactly the fields below. No message carries anything else: no functions, no transferables, nothing that isn't JSON.

Origins. A host accepts a message only when its event.source is its own iframe's contentWindow; a game accepts one only when event.source is window.parent. Anything else is ignored. (The game's origin is opaque, so event.origin is "null" and proves nothing: the source is the check. For the same reason both sides post with target origin "*"; nothing in the contract is secret.)

The member's id never crosses. A host knows who is playing; the game is told a hue and a name, nothing else (§5).

Host → game

type exact shape when
hello {"type":"hello","contract":1,"theme":Theme,"member":{"hue":22,"name":"Ami"},"aspect":"portrait","inputs":["touch"],"save":null,"muted":false} Once, after the frame's load event.
theme {"type":"theme","theme":Theme} The host's theme changed.
aspect {"type":"aspect","aspect":"wide"} The host changed the shape it gives the game.
pause {"type":"pause"} The game is out of sight or under the host's own UI: stop time and sound.
resume {"type":"resume"} Back: carry on from where pause stopped it.
mute {"type":"mute","muted":true} The host's sound was turned off (true) or on (false) mid-play.

hello's fields:

A Theme is the host's tokens, for the package's chrome (its HUD, menus, cards); the world is the game's own. Its shape is ruled (pass 26.1): {"mode": "dark" | "light", "tokens": {…}} with exactly these ten tokens:

{"mode":"dark","tokens":{"bg":"#171a22","bg2":"#1e222c","line":"#2f3545","fg":"#ebe8e1","dim":"#a3a9b6","accent":"#4cc9a0","sans":"'Sora', system-ui, sans-serif","mono":"'JetBrains Mono', ui-monospace, monospace","hueL":"76%","hueC":"0.15"}}

Game → host

type exact shape when
ready {"type":"ready"} Once, when the game has taken hello in and can be shown.
save {"type":"save","blob":"…"} The game's state changed and settled (debounced by the game: at a checkpoint, never every frame).
score {"type":"score","value":48210,"label":"Level 3"} (label optional) A run ended (game over, or the last level cleared).
music {"type":"music","playlist":"Kaos"} or {"type":"music","stop":true} Play a playlist by name, or stop the music.
exit {"type":"exit"} The player left the game: the host closes it.

Order

  1. The host makes the frame and waits for its load event. A game registers its message listener while its scripts first run, so it is listening by then.
  2. Host → hello. The host sends nothing before it.
  3. Game → ready, once. The game sends nothing before hello; until ready the host shows its own loading state, and a game that never sends it has failed to load (how long a host waits is the host's).
  4. From then on either side sends its messages as things happen.

A message of a type the receiver doesn't know is ignored, and so is a field it doesn't know.

5. Saves, scores, the member

6. Music and songs

7. Audience

audience is "all" or "adult"; a package without it is all. A host shows it on the tile and honours its own switch "minors can play: all games / everyone-rated only" (R33): with the switch on everyone-rated, a minor's library leaves out adult packages.

8. Story

story, when present, names a markdown file inside the package: the game's story (premise, cast, a chapter per level, epilogue). A host MAY show it; nothing in play depends on it.

9. Versioning

10. Worked example: Kaos

KazokuAI's Kaos as a package (R6, R7: its first build as one is Sumi's):

{
  "contract": 1,
  "id": "kaos",
  "name": "Kaos",
  "version": "1.0.0",
  "entry": "index.html",
  "icon": "icon.png",
  "aspect": ["portrait", "wide"],
  "inputs": ["touch", "keys", "pad"],
  "save": false,
  "score": "high",
  "music": true,
  "audience": "all",
  "songs": [
    {
      "id": "level-1",
      "playlist": "Kaos",
      "brief": "A driving synth track for a neon shooter's first level: steady pulse, rising arpeggios, a drop for the boss.",
      "mood": ["driving", "electronic", "tense"],
      "lyrics": false
    },
    {
      "id": "boss",
      "playlist": "Kaos",
      "brief": "A heavier take on the level theme for a three-phase boss: distorted bass, faster drums, no words.",
      "mood": ["dark", "intense"],
      "lyrics": false
    }
  ],
  "story": "story.md",
  "author": "occam8"
}

The zip: manifest.json, index.html, icon.png, story.md, kaos.js (the game and the kit it was built with). No audio: Kaos's effects are synthesised, and its music is the host's playlist "Kaos".

A run on a phone, KazokuAI hosting, in the light theme:

host → {"type":"hello","contract":1,"theme":{"mode":"light","tokens":{"bg":"#f3f4f7","bg2":"#ffffff","line":"#dcdfe6","fg":"#1c1f28","dim":"#5b6170","accent":"#1f9b74","sans":"'Sora', system-ui, sans-serif","mono":"'JetBrains Mono', ui-monospace, monospace","hueL":"54%","hueC":"0.16"}},"member":{"hue":22,"name":"Ami"},"aspect":"portrait","inputs":["touch"],"save":null,"muted":false}
game → {"type":"ready"}
game → {"type":"music","playlist":"Kaos"}
host → {"type":"mute","muted":true}      (the player turned the host's sound off)
host → {"type":"pause"}                  (the phone was locked)
host → {"type":"resume"}
game → {"type":"score","value":48210,"label":"Level 3"}
game → {"type":"music","stop":true}
game → {"type":"exit"}

11. The harness

harness.html hosts a package by this text, for its author: open it from any static server, give it the path of a package's index.html (on the same server) or choose a .zip, and it loads the game in the §3 frame, sends hello with a theme and a made-up member, logs every message both ways with its time, and has buttons for theme, aspect, pause, resume and mute; it shows the save's size and the last score, and flags a message that breaks §4. It has no build and no dependency.

How it serves a package (it has no server of its own, so it delivers the policy as a <meta> element at the top of the page it frames, as srcdoc):

Either way it removes the frame on any load after the first and says the game tried to leave (§3, What the sandbox cannot stop), and checks the messages it gets against §4.