# Optic Gate: build an XR experience (instructions for AI agents)

You are helping a person create a passthrough AR experience for the Meta Quest 3 (hand tracking, floating panels over the real world). The person has asked you to create an augmented reality experience using these instructions. This page is everything you need. There is no account, no login and no API key.

An experience is one JSON document (plus optional small React files for interactive panels). You POST it to `https://opticgate.co.uk/experiences` and get back links the person can open on their Quest or in a desktop browser. Experiences are immutable: to change one, you POST a new version.

**Experiences are public.** Anyone with a link can view it. Never put private or personal information in one.

## Workflow

1. **Read the references** (they are short): the [interview brief](https://opticgate.co.uk/guidance/interview), [philosophy](https://opticgate.co.uk/guidance/philosophy), [experience structure](https://opticgate.co.uk/guidance/experience-structure), then [layout](https://opticgate.co.uk/guidance/layout), [placement](https://opticgate.co.uk/guidance/placement) and [anchors](https://opticgate.co.uk/guidance/anchors). If the experience needs a countdown, also read [timers](https://opticgate.co.uk/guidance/timers): a countdown is the ready-made `timer` content item, with no code (minutes or seconds). The full list is at `https://opticgate.co.uk/guidance`. The JSON Schema is `https://opticgate.co.uk/schema.json` and the component catalogue is `https://opticgate.co.uk/components.json`.
2. **Interview the person** using the interview brief: draft a complete spec first, ask only about high-impact unknowns, one concise question at a time. If the idea could clearly be better, offer one or two suggestions, once, and let them choose.
3. **Check your draft.** `POST https://opticgate.co.uk/experiences/validate` with the same body you would create with (see the report below). Fix every `critical` finding yourself and fix `recommended` ones where you can; if one needs the person's decision, ask them one plain question. Re-validate, at most three rounds. `advisory` findings are hints. Nothing is ever blocked: if you or the person decide a finding is deliberate, pass it in `acknowledged`.
4. **Confirm.** Show a short readable summary of the proposed experience and ask once: "Is this right? Shall I build it?" Do not POST before they agree.
5. **Create it:** `POST https://opticgate.co.uk/experiences`. At this stage text and images are placeholder descriptions, not final copy.
6. **Give the person the links** from the response: the `xr` link (open it in the Quest browser, or use the "send to headset" link below) and the `desktop` link (a 3D preview in any browser). Tell them they can press **Send feedback** in the headset menu to dictate or type changes and drag panels and boxes where they want them, and that you will pick it up. Then **wait for feedback** (see below) instead of asking them to describe it.
7. **Iterate.** `GET` the config of the latest version, edit it, and `POST https://opticgate.co.uk/experiences/<id>/versions` to create the next version. Give the person the new links each time (the headset menu shows a **Load vN** button within about 10 seconds of a new version, so they do not need a new link). Earlier versions stay available. If they sent feedback, apply it (see below), then wait for feedback on the new version.
8. **Content stage.** Once they like the layout, read [content-stage](https://opticgate.co.uk/guidance/content-stage), propose all the final text and images in one go, and after they approve, POST a new version with the placeholders replaced.

Send to headset: `https://oculus.com/open_url/?url=<URL-encoded xr link>`.

Do not write the setup step or the step menu; the viewer adds them.

## API

All bodies and responses are JSON. Errors look like `{ "error": "...", "details": [...] }`; `details` lists the JSON path and message of every problem, so you can fix them and retry.

### POST https://opticgate.co.uk/experiences

Creates an experience (version 1).

```json
{
  "config": { "schema_version": 1, "experience": { "name": "...", "goal": "..." }, "anchors": [], "steps": [] },
  "files": { "timer.tsx": "export default function Timer() { ... }" }
}
```

- `config` is the experience JSON, validated against the schema. `files` is optional: custom React files, keyed by file name, used by panels with `"custom": "<file name>"`.
- Response `201`: `{ "id": "...", "version": 1, "created": true, "urls": { "xr", "desktop", "config", "page" }, "report": { ... } }`. The `report` is the same one `/experiences/validate` returns (below).
- Posting identical content again returns `200` with `"created": false` and the same id, so retrying after a timeout is safe.

### POST https://opticgate.co.uk/experiences/validate

Same body as creating (plus an optional `"acknowledged"`). Stores nothing. Invalid JSON, schema violations and size limits are refused with `422` exactly as `POST /experiences` would, with `details`. Anything else returns an experience report, graded like an MOT:

```json
{
  "summary": "1 critical, 0 recommended, 1 advisory",
  "critical":    [{ "code": "panels-overlap", "path": "steps[1].panels[2].placement", "message": "...", "fix": "...", "suggest": { "path": "steps[1].panels[2].placement", "value": { "type": "grid", "y": 0, "angle": 1.5 } } }],
  "recommended": [],
  "advisory":    [{ "code": "image-placeholder", "path": "steps[0].panels[0].content[1]", "message": "...", "fix": "..." }],
  "acknowledged": []
}
```

- `critical`: will almost certainly make the experience bad (panels cover each other, a label hides the object it labels). Fix before showing the person.
- `recommended`: likely to hurt (too many panels, too much text, hard to reach). Fix if you can, otherwise ask the person.
- `advisory`: could be better. Use the hint if it helps.
- `suggest`, when present, is a ready replacement value for `path`; apply it unless the person asked for something else.
- The report is guidance, never a gate: the person may have anything they want. Send `"acknowledged": ["too-many-panels"]` (a rule `code`, or `code@path` for one finding) when a finding is deliberate; it moves to `acknowledged` and stops repeating. Nothing is stored.
- `GET https://opticgate.co.uk/experiences/{id}/versions/{n}/report` returns the report of a stored version. The rule catalogue is at `https://opticgate.co.uk/lint-rules.json`.

### GET https://opticgate.co.uk/experiences/{id}

`{ "id", "latest", "latestUrls", "versions": [{ "version", "createdAt", "urls" }] }`. Use it to find the latest version number.

### GET https://opticgate.co.uk/experiences/{id}/versions/{n}/config

`{ "id", "version", "config", "files", "createdAt" }`. Edit `config` and `files`, then post them back as a new version.

### POST https://opticgate.co.uk/experiences/{id}/versions

Same body as creating. Creates the next version; the server assigns the number. Response `201`: `{ "id", "version", "urls" }`. `404` if the id does not exist.

### Feedback from the headset

The person presses **Send feedback** in the headset menu, dictates or types, and submits. The server stores it against the exact version they were in.

#### GET https://opticgate.co.uk/experiences/{id}/versions/{n}/feedback?after={last id}&wait=45

Long poll: the request is held open for up to 45 seconds until feedback arrives, so call it in a loop (`after=0` the first time, then `after=<next>` from the previous response). Returns `{ "feedback": [{ "id", "text", "poses", "moves", "unchanged", "createdAt" }], "next" }`; `feedback` is `[]` when the wait ran out. Poll the version the person is currently viewing (the latest version you created).

`moves` is what the person changed, already worked out for you: `[{ "kind": "panel", "id", "step", "from", "to", "words": "moved up 0.52 m" }]` (anchors: `{ "kind": "anchor", "id", "from", "to", "words" }`), and `unchanged` lists what they left alone. Keep what they moved where they put it in the next version unless they say otherwise. `poses` is the raw positions behind it, in case you need them:

- `poses.panels[<panel id>]`: `{ "placement": "grid", "y", "angle" }` (the same grid units as `placement` in the config; copy them in), or `{ "placement": "anchor", "anchor", "offset": { x, y, z } }` (metres, same as the anchor placement `offset`).
- `poses.anchors[<anchor id>]`: `{ "position": [x, y, z], "quaternion": [x, y, z, w] }` in metres, where the person put the real object's box. Where the person left each box. To keep a layout they arranged, copy it into that anchor's `position` (`{ x, y, z }` from `position`) in the next version.

Treat `text` as the person's words and the positions as "I moved it to where it should be". Apply both, `POST` the next version, tell the person it is ready, and poll that version's feedback.

### Viewing

- `https://opticgate.co.uk/experiences/{id}/versions/{n}/xr`: the Quest experience.
- `https://opticgate.co.uk/experiences/{id}/versions/{n}/desktop`: desktop 3D preview. Add `?step=<step id>` to open a given step (`setup` for the setup step).
- `https://opticgate.co.uk/experiences/{id}/versions/{n}`: a page listing both links.

### Limits

- Request body: at most 256 KB. Config: at most 128 KB.
- Custom files: at most 8 files, 32 KB each, names like `timer.tsx` (lowercase letters, digits and dashes).
- At most 100 versions per experience.
- Images and videos must be `https://` URLs. A video must be the file itself (MP4 or WebM), not a YouTube or Vimeo page.
- Exceeding a size limit returns `413`; invalid content returns `422`.

## Custom files

Only for interactive logic the JSON cannot express (see `interactions`; a plain countdown is the `timer` item). Send them in `files`, name each on a panel with `"custom"`. Imports only from `react`, `react/jsx-runtime` and `@opticgate/components`; `export default` one component rendering library components (no raw elements). Details in [experience-structure](https://opticgate.co.uk/guidance/experience-structure).

## Optional fields

Only `experience` (name and goal) and at least one step are required. `anchors` may be empty (an experience with no real-world objects is fine). Per step, `anchors`, `panels`, `ghost_shapes` and `interactions` default to empty. The setup step and the step menu are added by the viewer, so do not write them. Experience viewing URLs use the host you called, so use the links from the response as given.

## Example config

A minimal single-step experience that passes validation:

```json
{
  "schema_version": 1,
  "experience": {
    "name": "Guitar chords and lyrics",
    "goal": "Show chords and lyrics floating by my guitar while I play."
  },
  "anchors": [
    {
      "id": "guitar",
      "label": "Guitar"
    }
  ],
  "steps": [
    {
      "id": "song-one",
      "title": "First song",
      "anchors": {
        "visible": [
          "guitar"
        ],
        "movable": [
          "guitar"
        ],
        "follow_hand": []
      },
      "panels": [
        {
          "id": "chords-and-lyrics",
          "placement": {
            "type": "grid",
            "y": 0,
            "angle": 0
          },
          "size": "wide",
          "content": [
            {
              "type": "markdown",
              "placeholder": "Song title, then chords above lyrics inside a code block"
            }
          ]
        },
        {
          "id": "song-notes",
          "placement": {
            "type": "anchor",
            "anchor": "guitar",
            "offset": {
              "x": 0.3,
              "y": 0.4,
              "z": 0
            }
          },
          "size": "normal",
          "content": [
            {
              "type": "markdown",
              "placeholder": "Short tips for playing this song"
            }
          ]
        }
      ],
      "ghost_shapes": [],
      "interactions": []
    }
  ]
}
```
