The game package contract
Every file below is the vendored copy, byte for byte; sha256sum -c CHECKSUMS checks the three it lists.
- SPEC.mdbf62d45b32319b22c7547e11e5e010f210a4afa6c2b33215bc33a0e389fbc025
- manifest.schema.jsone263e60cdfe403fbb2f5a16bac0257fbc79dba3b21a59da2cbb5909cabcfc6ee
- harness.htmlb82ce2e236448ed8db5ccc9b0293f9e946f09ccb00f8482232eca010da0d7f21
- VERSION4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865
- CHECKSUMS342689f7e4902f0b0486e6daf6c4d977a3c23acd027093c36a6a94908ec85a0f
- VERSION.jsonSumi's record of the five: the contract, the text and each sha256
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
- A package is one
.zipfile of at most 10 MB (10,485,760 bytes, the file as stored). manifest.jsonandindex.htmlsit at the root of the zip, not inside a folder.- Every other file is reached from
index.htmlby a relative path. Paths use/, never start with/, never contain a..segment, a scheme (https:), a backslash or a control character. - A package has no audio files (an MP3, M4A, AAC, OGG, Opus, WAV, FLAC or WebM audio file, or any other audio type). Sound effects are synthesised by the game (Web Audio); music is the host's to play, asked for by name (§6).
- A package has no network, ever (§3).
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>
-
Opaque origin. The sandbox has no
allow-same-origin: the game's origin is opaque ("null"). It reads no host cookie, storage or DOM, and nothing the host's origin can do. Nor has it storage of its own:localStorage,sessionStorage, IndexedDB and cookies throw or hold nothing; a game keeps its state throughsave(§5). -
The policy. The package is served under the Content Security Policy
default-src 'self'; connect-src 'none'A host sends it as the
Content-Security-Policyheader ofindex.html's response. What follows from it, for a game's author:- no network: no
fetch, XHR, WebSocket, EventSource or beacon, not even to the package's own files; - files load only from the package itself, by element:
<script src>,<link rel="stylesheet">,<img>, CSSurl(), moduleimport; - no workers: an opaque-origin document can't start one from a URL, and
data:andblob:are refused; - no inline
<script>or<style>, nostyle="…"attribute, noevalornew Function, no WebAssembly: code and styles live in files (settingelement.stylefrom script is fine); - no
data:orblob:URLs; - fonts load only from the package: a game that wants Sora or JetBrains Mono ships them.
And for a host: the frame's origin is opaque, so a module script or a font it loads is a cross-origin request to the host's server. A host serves the package's files with
Access-Control-Allow-Origin: *, or a game built as modules can't start. (These were measured in Chromium and WebKit, pass 26.) - no network: no
-
Pointer lock is allowed (
allow-pointer-lock); popups, forms, top-level navigation, downloads and fullscreen are not. Full-bleed is the host's to give: the frame fills what the host gives it and the game fills the frame.
What the sandbox cannot stop
- A package can navigate its own frame. Neither the sandbox nor the policy stops it: an outbound GET, with whatever data
the game puts in the URL (measured in Chromium and WebKit, pass 26). A navigation the other end answers with 204 No
Content, or as a download (which the sandbox refuses), leaves the game's page in place with no
load, so a game can send such GETs again and again unseen (measured in both, pass 26.1). - A host removes the frame on any
loadevent after the first, and tells the member the game tried to leave. That catches a navigation that lands; it ends the game, and it can't take back the request. - The frame holds nothing worth carrying. The member's id never crosses (§4, §5): a game knows a hue, a name, its own save and the theme.
- Builders lint for it (advisory; Sumi's validator does): an assignment to
location(orlocation.href,location.assign,location.replace),window.open, and an<a>with atarget, in a package's files. - The contract tightens if engines give hosts a hook to refuse a frame's navigation: that change will be a new contract.
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:
contract— the contract the host speaks (an integer). A host loads only packages whosecontractit speaks.theme— a Theme, below.member— the player:hue, an integer 0–359 (the member's colour, drawn at the theme'shueLandhueC), andname, their display name.aspect— the shape the host gives the game now: one of the manifest'saspect.inputs— the manifest's inputs this host offers on this device (a phone:["touch"]; a desktop:["keys","pad"]).save— the member's last save for this package'sid(the string from §5), ornullwhen there is none or the manifest'ssaveis false.muted— the initial state of the host's sound:true, the game starts silent.mutechanges it mid-play.
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"}}
mode—"dark"or"light".tokens— CSS values, all ten always present:bg(the page),bg2(a card on it),line(a divider),fg(text),dim(secondary text),accent(the host's accent),sansandmono(font stacks: a package has only the fonts it ships),hueLandhueC(the lightness and chroma every member hue is drawn at in this mode: the member's colour isoklch(<hueL> <hueC> <hue>), so a member is the same colour in the game as in the host).
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. |
save.blob— a string, at most 64 KB (65,536 bytes as UTF-8): the game's whole save, in whatever form it likes (JSON text, usually). The host keeps the last one per member per packageidand hands it back in the nexthello; it never reads it. A host ignores asaveover 64 KB, keeping the one before.score.value— a whole number ≥ 0;score.label— a short text the board shows beside it (at most 24 characters; a host MAY cut a longer one). A host keeps scores per member per packageid.music— exactly one ofplaylist(a name, usually one of the manifest'ssongs[].playlist) orstop(true).
Order
- The host makes the frame and waits for its
loadevent. A game registers itsmessagelistener while its scripts first run, so it is listening by then. - Host →
hello. The host sends nothing before it. - Game →
ready, once. The game sends nothing beforehello; untilreadythe 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). - 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
- Saves are per member per package
id: the host storessave.blobagainst its own member and the package'sid, and gives it back in that member's nexthello. A newversionof the package gets the same save. - Scores are per member per package
id(the scores key), for a package whosescoreishigh; a host ignoresscorefrom one whosescoreisnone. - The member's id, account, role and anything else about them stay with the host. The game gets
member.hueandmember.nameinhello, and that is all.
6. Music and songs
- A package carries no audio. With
music: trueit asks the host for music by playlist name (music {playlist}) and can stop it (music {stop}). The host plays what it has under that name from its own library (KazokuAI from Songs; Sumi from the project's songs or its music folder), or nothing; the game never knows which. songs[]ships the briefs the game's songs were made from, never the songs (R31). A host with a music maker offers on install to make them ("Make this game's n songs · $n.nn") and files them in a playlist named for the game: the name in the songs'playlist, which a maker sets to the game's name, so the game'smusic {playlist}finds them. A host without one plays what it has.mutedinhellois whether the game's own effects start silent;muteturns them off or on mid-play;pausesilences them while paused.
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
- The contract is one integer,
contract, in the manifest, inhelloand in VERSION. This text is contract 1. (Text v1.1 added themutemessage without a bump, before any vendor had copied v1.0.) - Bumps the contract: a new required manifest field; any change to a message (a type added or removed, a field added, removed or changed in meaning or shape); a change to the sandbox or the policy.
- Doesn't bump it: a new optional manifest field, added to manifest.schema.json with it (
audience,songsandstoryare optional fields of contract 1); a clearer sentence here. So that an older host takes a package with a newer optional field, a host loading a package ignores a manifest field it doesn't know; the schema is closed for a maker's validator, to catch a misspelt field against this text. - A host states the contracts it speaks and loads only packages with one of them.
- VERSION holds the contract number; CHECKSUMS the sha256 of SPEC.md, manifest.schema.json and harness.html, in
sha256sumformat, so a vendored copy (Sumi'sspec/) can show it is verbatim (sha256sum -c CHECKSUMS). The text has a version of its own in the Status line ("text v1.1"); a vendor's test names the contract and the text version it copied and the sha256 of this repo's CHECKSUMS at that version, so a copy that has fallen behind shows.
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):
- A path: it reads
index.htmland frames it with a<base>pointing at the package's folder, under exactly §3's policy. The server is a host's here: for a package of modules it must sendAccess-Control-Allow-Origin: *(§3); a plainpython3 -m http.serverdoesn't. (In Chromium animport()in a classic script doesn't resolve in a srcdoc frame: use module scripts, or check in another engine.) - A zip: it unzips in the browser and hands every file to the frame as a
data:URL, rewriting the references in HTML (src,href), CSS (url(),@import) and JS (import … from,import()). An opaque-origin frame can't load the page'sblob:URLs, sodata:is the one way in, and the policy gainsdata:beside'self';connect-src 'none'is unchanged. A package that builds file paths at run time won't load this way, and one that makesdata:URLs of its own works here but in no host: check both by path.
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.