gamestruct docs

Start here

This page assumes you have never heard of gamestruct. It takes about five minutes and ends with a surface that both a screen reader and an agent can operate.

The idea in one sentence

Describe your UI once as a tree of named, role-tagged nodes, and you get two things for free: a screen-reader experience and an agent tool catalog - because they read the same description.

1. Describe

A node carries a handle (a stable id), a role (what it is), an accessible name (what a screen reader says), and, if it is interactive, the actions it accepts.

import { Bridge, ROLES } from 'gamestruct'

const bridge = new Bridge({ name: 'pause menu' })
bridge.tree.add(null, { id: 'ui:start',  role: ROLES.BUTTON, name: 'Start game' })
bridge.tree.add(null, { id: 'ui:volume', role: ROLES.SLIDER, name: 'Volume', value: 50, min: 0, max: 100 })

The handle is the whole contract. Use a stable one (ui:start, not “button number 1”); it is the same handle the human lane walks and the agent lane drives.

2. Wire

Register one handler per actionable handle. The verb is the action the node declares - activate for a button, set_value for a slider.

bridge.on('ui:start',  { activate: () => startGame() })
bridge.on('ui:volume', { set_value: (v) => setVolume(v) })

3. Read both lanes

The same bridge now renders to a screen reader and to an MCP client:

import { human, agent } from 'gamestruct'

human.a11yDump(bridge)      // the screen-reader text
agent.toolCatalog(bridge)   // the MCP tool list
[*] region "pause menu"
[ ]   button "Start game" {activate}
[ ]   slider "Volume" =50 {set_value}

4. Act

Either lane drives the same code path. There is no agent rail and no second protocol - one act().

await bridge.act('ui:start')            // the button
await bridge.act('ui:volume', 'set_value', 75)

5. Gate it

Run the a11y audit in CI. It flags the failures that actually break a screen reader: an interactive node with no name, one that declares no action, an image with no alt text.

const { ok, problems } = human.audit(bridge)

Or run the CLI on a demo surface to see both lanes and the audit at once:

npx gamestruct doctor

You now serve assistive technology and agents from one description. That is the whole on-ramp. Next: the contract for the normative rules, or the adapters to see how a real game and a real brain connect.