# Plethora: Verify and Upload

Plethora Studio = Plethora. No login, password, API key or plugin is needed, and nothing to install (an optional MCP server is at https://agent.plethora.studio/mcp): you start pairing yourself, show the creator a QR or 8-character code, they approve it in the Plethora app, then you upload the Bit as a draft.

Context version: plethora-agent-context-2026-10-22.1
SDK version: 1.8.0
Workflow version: 2026-10-30.1

**Fetch the current context first, every time.** At the start of every new Bit, and again right before every upload, fetch https://agent.plethora.studio/v1/agent/context.md and note its Version (also `contextVersion` in https://agent.plethora.studio/v1/agent/context.json). Do not build from an SDK, context, schema, template, skill or memory kept from an earlier chat or an earlier Bit: the contract changes, and Plethora only publishes full-screen Bits (`"display": "fullscreen"`). Send the version you built against as `agentFeedback.contextVersion`; an upload built against an older context is refused with 409 `context_outdated` and nothing is saved.

Public guidance. No pairing or token needed to read or build.

## 0. Fetch the current context
Before this upload, fetch https://agent.plethora.studio/v1/agent/context.md again and compare its Version with the one you built against. If it changed, re-read what changed, re-check the Bit, and send the new version as agentFeedback.contextVersion. An upload declaring an older context is refused with 409 context_outdated and nothing is saved. Check the manifest declares "display": "fullscreen": Plethora only publishes full-screen Bits.

## 1. Verify without pairing
Read [best practices](https://agent.plethora.studio/v1/agent/best-practices.md) and the topic relevant to any failure. Parse plethora.json, validate against [schema.json](https://agent.plethora.studio/v1/agent/schema.json), check exact registry pins/loader kinds, and run the source. There is no public validation/preview endpoint yet. Do not invent one.

Check visible first frame BEFORE ready; first real touch; every control and replay; resize/orientation and the content safe area (no text under the island, nothing behind the logo, full screen and in the legacy safe frame older apps still use); lifecycle/audio cleanup; permission-denied fallbacks. Native-only motion/mic/camera needs phone testing. A browser stub or HTTP 200 is not that proof.

Use your environment's tools (PowerShell on Windows, shell on Unix). Serialize the upload with JSON.stringify or an equivalent structured serializer; do not splice source into quoted shell JSON. Do not rewrite the game merely to fix quoting.

## 2. Reconnect only if needed
Keep building/testing while approval is pending. At upload, reuse a valid saved token. Otherwise check the existing session or show new approval paths from [start.md](https://agent.plethora.studio/v1/agent/start.md) if absent/expired. Preserve source, manifest and pending upload identity. Do not ask for another starter prompt.
Respect denial/revocation: stop account writes, ask before requesting access again. Do not loop against an explicit refusal or treat every 403 as token expiry.

## 3. Save a draft
Endpoint: https://agent.plethora.studio/v1/agent/bits/drafts (POST).
- Authorization: Plethora-Agent <data.accessToken>
- Content-Type: application/json
- X-Plethora-Command-Protocol: v1
- Idempotency-Key: <new stable key per user action>

Reuse the exact same idempotency key only when retrying the same upload after a lost or timed-out response. A changed upload is a new user action and needs a new key.
Never generate a new key just because a response is slow: reconcile the existing operation first. For a genuinely corrected payload, use a new key. Retain keys and payload with local work; keep credentials out of source, logs, URLs and chat.

Body fields:
- title: string fallback used only when manifest.title is missing; final title is required
- description: optional string fallback used only when manifest.description is missing
- tags: optional string[] fallback used only when manifest.tags is missing
- source: required JavaScript source string defining window.plethoraBit
- manifest: plethora.json object; strongly recommended for every upload; title, runtime, entry, permissions, dependencies, assets, memory, game.progress, tuning, onboarding, and display are validated and normalized; publishing requires display: "fullscreen"
- generated: optional boolean; true when coding agent generated the draft
- agentFeedback: optional but expected object reporting SDK/docs/validator/runtime/upload friction. Send it on every agent upload, even as { outcome: "clear", unclear: [], blockers: [], suggestions: [] } when nothing hurt.

Keep the first line of the source as `// Plethora Bit · docs and draft upload: https://agent.plethora.studio/v1/agent/start.md`. The starter and every example begin with it; add it to a Bit without it before you test. It tells the next agent that opens the file how to upload or update the Bit.

Example (replace with your actual source and honest feedback):
```json
{
  "title": "Touch Sketch",
  "description": "A tiny touch-reactive Plethora Bit.",
  "tags": [
    "creative",
    "touch"
  ],
  "manifest": {
    "schemaVersion": 1,
    "runtime": "plethora-bit@2",
    "entry": "main.js",
    "title": "Touch Sketch",
    "description": "A tiny touch-reactive Plethora Bit.",
    "tags": [
      "creative",
      "touch"
    ],
    "permissions": [
      "haptics"
    ],
    "dependencies": [],
    "display": "fullscreen",
    "onboarding": {
      "kind": "one_line",
      "version": 1,
      "message": "Touch the canvas to make a mark."
    }
  },
  "generated": true,
  "agentFeedback": {
    "contextVersion": "plethora-agent-context-2026-10-22.1",
    "sdkVersion": "1.8.0",
    "outcome": "minor_friction",
    "confidence": "medium",
    "unclear": [
      "How to choose between ctx.onFrame and ctx.game.loop."
    ],
    "blockers": [],
    "repeatedFixes": [
      "Adjusted safe-area layout twice after mobile preview."
    ],
    "workarounds": [],
    "suggestions": [
      "Add one more tiny game-loop example with scoring and onboarding together."
    ],
    "docsMissing": [],
    "runtimeIssues": [],
    "validatorIssues": [],
    "libraryIssues": [],
    "uploadIssues": [],
    "pairingIssues": [],
    "timeSpentMinutes": 34,
    "iterationCount": 3,
    "notes": "Keep this honest and short. If everything was clear, send outcome \"clear\" and empty arrays."
  },
  "source": "// Plethora Bit · docs and draft upload: https://agent.plethora.studio/v1/agent/start.md\nwindow.plethoraBit = {\n  meta: {\n    title: \"Touch Sketch\",\n    runtime: \"plethora-bit@2\",\n    tags: [\"creative\", \"touch\"],\n    permissions: [\"haptics\"]\n  },\n\n  async init(ctx) {\n    const canvas = ctx.createCanvas2D({ coordinateSpace: \"css\", maxDpr: 2 });\n    const g = canvas.getContext(\"2d\");\n    const touches = [];\n\n    function draw() {\n      const area = ctx.contentSafeArea ?? ctx.safeArea; // clear of the island and the logo\n      g.fillStyle = \"#142a29\";\n      g.fillRect(0, 0, ctx.width, ctx.height);\n      g.fillStyle = \"#ffffff\";\n      g.font = \"20px sans-serif\";\n      g.textAlign = \"center\";\n      g.fillText(\"Touch to make a mark\", ctx.width / 2, area.top + 48);\n      g.fillStyle = \"#f2c94c\";\n      for (const touch of touches) {\n        g.beginPath();\n        g.arc(touch.x, touch.y, 12, 0, Math.PI * 2);\n        g.fill();\n      }\n    }\n\n    ctx.input.on(canvas, \"tap\", pointer => {\n      ctx.platform.start();\n      ctx.platform.haptic(\"light\");\n      touches.push({ x: pointer.x, y: pointer.y });\n      if (touches.length > 64) touches.shift();\n      draw();\n    });\n\n    ctx.onResize(draw, { immediate: true });\n    ctx.platform.ready();\n  }\n};"
}
```

## 4. Interpret responses, not wishes
- 200 with ok:true: saved draft/revision. Read data.action, data.bit.id, data.packageHash, data.packageBytes and data.notices. Not published, not a gameplay test. data.notices does not block saving: the draft is saved either way, but a notice can mean it cannot be published yet.
- 202: command still pending. Poll GET https://agent.plethora.studio/v1/agent/commands/:commandId using the SAME agent token. Follow returned command identity/status; do not launch another upload.
- 400: inspect the actual structured error. Fix source/manifest/JSON as indicated, then use a new key for the changed payload.
- 401/403: inspect error code. Missing/expired session may require pairing again; denial, revocation, wrong scopes or other permission errors need explanation, not blind retries.
- 409: inspect the error code. context_outdated: nothing was saved; fetch the current context, re-check the Bit, send the new contextVersion and upload with a new key. Otherwise it is a title or idempotency conflict: do not silently rename a creator's Bit or rotate keys against an unknown outcome. Re-pairing is the exception: a pairing create's 409 with details.reason pairing_restart_required asks for a new pairing session with a new key.
- 429: honor Retry-After/backoff. Network/5xx: bounded retry of the SAME request/key; reconcile before retrying a possibly accepted upload.

Command identity is data.command.id on a 202, also X-Plethora-Command-Id when supplied. Command status reads return data.command.status and data.result. A null result is still pending, not success. A terminal result has statusCode and envelope: inspect data.result.envelope.ok and its data/error. The outer status-read HTTP 200 only means you fetched a status successfully.

Command receipts are scoped to the original agent token. If that token expires after an upload with an unknown outcome, a newly paired token cannot read the old receipt. Preserve the command id, payload and key, report the uncertainty and have the creator check their draft before a new submission. Do not claim re-pairing alone proves the original upload failed.

Success envelope:
```json
{
  "ok": true,
  "data": {
    "action": "created | updated | draft_revision",
    "bit": "{ id, title, description, tags, source, manifest, runtime_version, ... }",
    "packageHash": "sha256:<64 hex chars>",
    "packageBytes": 12345,
    "notices": "[{ code, message }]: advice to pass on to the creator; the draft is saved either way (e.g. display_not_fullscreen: saved, but it cannot be published until the manifest declares display \"fullscreen\"); empty when there is none"
  },
  "requestId": "request-id",
  "serverTime": "2026-06-20T21:00:00.000Z"
}
```

## 5. Tell the creator what happened
Say "Saved draft", its title/id, actual tests run and any remaining phone checks. Open Plethora -> Create -> Drafts for review; do not invent Profile -> Uploads navigation. Do not say published or working just because upload succeeded. Publishing stays manual in Plethora.

Pass on every data.notices message in plain words. display_not_fullscreen means the draft was saved but cannot be published: Plethora only publishes full-screen Bits, and publishing answers 422 display_fullscreen_required. Add "display": "fullscreen" to the manifest, keep text and controls inside ctx.contentSafeArea ?? ctx.safeArea, test it, and upload again with a new Idempotency-Key before telling the creator it is ready to publish.

Include agentFeedback on every upload: outcome, unclear docs, blockers, repeated fixes and suggestions; empty lists and outcome clear are fine when truthful. Never include credentials or private creator data.
- Include agentFeedback in every paired-agent draft upload. Be honest about unclear docs, blockers, repeated fixes, runtime surprises, validator friction, upload/pairing friction, and SDK suggestions. Send outcome "clear" with empty arrays when the flow was smooth.

Reading path: [Creation](https://agent.plethora.studio/v1/agent/creation.md) | [Fundamentals](https://agent.plethora.studio/v1/agent/fundamentals.md) | [Complete SDK](https://agent.plethora.studio/v1/agent/sdk.md) | [Verify and upload](https://agent.plethora.studio/v1/agent/upload.md).
