/meta-wearables-webapp-game:add-webapp-game-logging [project-dir]from meta-wearables-webapp-game
Adds a remote log sink and passcode-gated web log portal to a webapp game, enabling log reading from Meta Display Glasses on a laptop via serverless endpoints.
Ships in meta-wearables-webapp-game. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Wire up the backend half of the logging subsystem: serverless log-ingest endpoints, a passcode-gated portal page, and a helper that builds the debug URL / QR deep link.
The client half already ships in every scaffolded game — the Logger, the ?logview
on-screen overlay, the RemoteLogSink, and the consent gate are all in src/framework/, and
main.ts is already wired for them. This skill only adds what a backend needs. Read
${CLAUDE_PLUGIN_ROOT}/docs/logging.md before starting.
Say so and stop if the user's problem is solved more cheaply:
?log=debug&logview. That draws the last log lines straight onto the 600x600 display, works
offline, and needs no backend or deploy.?log=debug is
the whole answer.Remote logging is for the case where the bug only reproduces on the glasses and the log is too long, too fast, or too awkward to read on the display itself.
All outside src/framework/ — that directory is managed and re-synced wholesale by
update-webapp-game-framework, so anything written there would be destroyed on the next
framework update.
<project>/
api/
_http.js shared auth / body / cookie helpers (fail-closed)
_store.js pluggable log store (Upstash Redis | file | memory)
logs.js POST ingest (token) + GET tail (cookie)
log-auth.js portal sign-in -> HttpOnly cookie
public/
logs.html the portal page
logs.js the portal client (textContent-only rendering)
scripts/
debug-url.mjs prints the debug URL + the fb-viewapp:// deep link
lib/deep-link.mjs the URL/deep-link builders (the double-encoding rule)
vite-log-api.mjs serves the api/ handlers and /logs during `npm run dev`, and prints
the logging-enabled game URL + the portal URL alongside Vite's own
vite-log-api.d.mts its type declarations — tsconfig type-checks vite.config.ts
vercel.json updated: /logs route + /api/* excluded from the SPA catch-all
vite.config.ts updated: registers the dev-server plugin
.gitignore / .env updated: .env + .logs/ ignored; LOG_TOKEN written to .env
Source templates: ${CLAUDE_PLUGIN_ROOT}/skills/add-webapp-game-logging/templates/.
PROJECT="${1:-$(pwd)}"
test -f "$PROJECT/package.json" && test -d "$PROJECT/src/framework" \
&& echo "OK: $PROJECT" || echo "NOT a meta-wearables-webapp game"
Confirm the framework is new enough to have the client half:
test -f "$PROJECT/src/framework/debug/RemoteLogSink.ts" \
&& echo "client half present" \
|| echo "MISSING — run /update-webapp-game-framework first"
If it's missing, stop and tell the user to run /update-webapp-game-framework, then
re-run this skill. Do not hand-write the framework files.
The token is the single secret. It gates ingest (in the game's URL) and portal access, and without it set, every endpoint 404s.
Use AskUserQuestion to offer:
node -e "console.log(require('crypto').randomBytes(16).toString('base64url'))"
gives 22 URL-safe characters (128 bits). Step 3 does this for you if you omit --token.A 22-character token costs 22 characters in the QR deep link (base64url needs no percent-encoding), which leaves plenty of room under the QR generator's ~271-char capacity — a typical debug deep link lands around 185 characters. If a QR ever refuses to encode, shorten the app name, not the token.
Never write the token into a tracked file. Step 3 puts it in .env — which it also adds to
.gitignore — and that is the only file it may live in. It reaches the deployment as an
environment variable, never through a commit.
One command does all the mechanical wiring:
node "${CLAUDE_PLUGIN_ROOT}/skills/add-webapp-game-logging/scripts/install.mjs" \
--project "$PROJECT" --token <token>
It is idempotent, prints a JSON summary, and:
api/, public/logs.*, and the three scripts/ helpers — including
scripts/vite-log-api.d.mts, without which the first npm run typecheck fails with TS7016
(the scaffold's tsconfig.json type-checks vite.config.ts, which now imports the .mjs
plugin);vercel.json rather than overwriting it: adds
{ "source": "/logs", "destination": "/logs.html" } before the catch-all so /logs serves the
portal, and migrates any negative-lookahead route pattern an older scaffold left behind to a
plain /(.*) — Vercel rejects lookaheads outright, so a project still carrying one cannot
deploy. The catch-all needs no api/ carve-out: Vercel resolves Serverless Functions in the
filesystem step, ahead of rewrites;vite.config.ts (logApiPlugin()), which is what makes the
whole feature testable on localhost before publishing — it serves the api/ handlers and the
portal at /logs, the same paths the deployment uses; loads .env into process.env so the
handlers see LOG_TOKEN (Vite itself only exposes VITE_-prefixed vars, and only to client
code); and prints the two URLs you need under Vite's own on startup;.env and .logs/ are in .gitignore (the scaffold already ships .env) and writes
LOG_TOKEN into .env.Omit --token to have one generated; pass --no-env to set LOG_TOKEN some other way.
For the deployment, set the token there too:
vercel env add LOG_TOKEN production
Vercel will not pick up a new environment variable until the next deploy. Redeploy after adding it, or the endpoints keep 404ing.
First the mechanical half — endpoints, auth, ingest, read-back, and the fail-closed contract:
node "${CLAUDE_PLUGIN_ROOT}/skills/add-webapp-game-logging/scripts/smoke-log-api.mjs" --project "$PROJECT"
It starts the dev server (reading LOG_TOKEN from .env), checks ingest, portal sign-in,
read-back, the fail-closed contract, and that a bare npm run dev picks the token up from .env,
then restores the log store and exits non-zero listing any failure. It does not need the
browser.
Then walk the consent sequence by hand. This part is the privacy contract and is the reason the smoke test isn't the whole story:
npm run dev
It prints both URLs you need, filled in with the token from .env:
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
➜ Logging: http://localhost:5173/?log=debug&logkey=k3j9xz
➜ Portal: http://localhost:5173/logs
(The last two appear only when a token is configured — an unconfigured project has nothing to
advertise. To override the token for one run — a different value, or none, to see the fail-closed
behavior — export it inline: LOG_TOKEN=<token> npm run dev.)
/api/logs before you accept.LOGGING
badge appears.?logview still shows logs on screen.(The fail-closed check — no LOG_TOKEN, so both /api/logs and /api/log-auth 404 — is already
covered by the smoke test above. The portal page itself still loads either way; it is a static
file, it just can't authenticate or read anything.)
Deploy from the project root as usual (never add a server.js or a package.json start script —
see ${CLAUDE_PLUGIN_ROOT}/docs/logging.md and the create skill). Then:
node scripts/debug-url.mjs https://<project>.vercel.app --token=<token> --logview
It prints the plain game URL and the correctly encoded fb-viewapp:// deep link. Render the deep
link as a scannable PNG with the qr_generator.py in meta-wearables-webapp's
ai-glasses-webapp-publish skill (the command is printed by debug-url.mjs). By default it registers a separate
<name> (debug) entry, so the glasses launcher shows the normal game and the debug build side by
side and the user never re-registers to toggle logging.
This is a real unknown — check it, don't assume. After scanning the QR and launching the debug entry on the glasses, confirm the consent gate appears. If it does, the query string survived. If the game launches straight into play, it did not survive registration and remote logging can never turn on that way.
Fallback if it was stripped: switch to a path-based flag. The SPA rewrite already sends every path
to index.html, so /<token>/ can be read from location.pathname in src/log.ts and passed to
logKeyFromSearch's caller in main.ts. Tell the user what you changed and why.
Give the user, concisely:
LOG_TOKEN;memory, file, or redis) and,
if it is memory, that records can be lost on a cold start and how to upgrade (below).Auto-selected by api/_store.js; no configuration needed to start.
| Backend | When it is used | Durable? |
|---|---|---|
| Upstash Redis | KV_REST_API_URL + KV_REST_API_TOKEN are set | Yes — survives cold starts, shared across instances |
| File (JSONL) | A persistent filesystem exists (npm run dev, self-hosted Node) | Yes, per host. Also readable with cat .logs/game-logs.jsonl |
| Memory ring | Fallback (the default on Vercel) | No — a cold start or a second instance loses records |
On Vercel the default is the memory ring, and the portal shows a banner saying so. It is fine for
"I am watching the portal while I test"; it is not fine for "let me play for ten minutes and read
it later". To upgrade, add an Upstash Redis integration from the Vercel Marketplace (it sets
KV_REST_API_URL / KV_REST_API_TOKEN automatically) and redeploy — no code change.
A public HTTPS endpoint on the game's own deployment, gated by one shared secret. LOG_TOKEN
is simultaneously the write key (the game sends it as ?k=) and the read passcode (you type it at
/logs). There are no accounts, no roles, and no way to grant read without granting write.
So anyone who learns the token can:
The token travels in the game's URL and therefore in the QR deep link, the launcher entry on the
glasses, and anything that records browser history. Treat a URL with ?logkey= in it as the secret
itself. It reaches the deployment as an environment variable and must never be committed.
Rotate by changing LOG_TOKEN and redeploying — old URLs stop working immediately. Rotate after
sharing a debug URL with anyone, after a demo, and when you are done debugging. Or turn the feature
off entirely by unsetting the variable; the endpoints then 404.
Do not weaken these; each one is load-bearing.
LOG_TOKEN, no endpoints. A game published without deliberately enabling
logging has no ingest endpoint to abuse and no portal to find.x-forwarded-for — a
believed header defeats the per-IP budget entirely. Vercel is the exception (its edge sets the
header and the socket is an internal hop), and is detected automatically. If the user self-hosts
behind a reverse proxy, tell them to set LOG_TRUST_PROXY=1; otherwise leave it unset.textContent only. Log text arrives from a device over the public
internet; a viewer that interpolates it into markup is an XSS hole. Keep the CSP in logs.html
too — the two are halves of the same defense.?logkey token is redacted automatically;
nothing else is. This is also why the consent gate is not a formality — the wearer is agreeing to
transmit off-device, so it must appear before the game, must be declinable, and must not be
remembered across sessions.npm run dev..logs/game-logs.jsonl, or your
Upstash instance in plain JSON.| Issue | Solution |
|---|---|
| Every endpoint 404s | LOG_TOKEN is unset — or was set after the last deploy. Set it and redeploy. In dev it comes from .env, loaded by logApiPlugin(); if the portal rejects the right passcode on localhost, check that the plugin is registered in vite.config.ts and that .env has a LOG_TOKEN= line. |
| Portal says "incorrect passcode" with the right one | The deployment has a different LOG_TOKEN than you think. vercel env ls to check. |
| Game shows the badge but the portal is empty | Memory store on a different instance. Check the portal's store line; move to Upstash. |
| Consent gate never appears on device | The query string was stripped at registration — Step 6's fallback. |
| Consent gate appears in a desktop browser but nothing sends | You declined, or LOG_TOKEN doesn't match the ?logkey in the URL (the POST 401s and the sink disables itself; look for the "remote logging stopped" warning in the console). |
/logs shows the game instead of the portal | The SPA catch-all answered first: on the deployment the /logs rewrite in vercel.json is missing or sits after it; in dev logApiPlugin() isn't registered in vite.config.ts. /logs.html works either way and confirms the diagnosis. |
| Deep link registers without the flags | The appUrl wasn't percent-encoded — use scripts/debug-url.mjs, never a hand-built string. |
| QR won't scan / too dense | The deep link is over ~271 chars. Shorten the app name — not the token. |
NetworkGuard warns about /api/logs | Pass allow: isLogEndpoint to sealAssetNetwork — see ${CLAUDE_PLUGIN_ROOT}/docs/logging.md. |
| Skill | Purpose |
|---|---|
/read-webapp-game-docs | The docs/logging.md reference this skill implements |
/update-webapp-game-framework | Required first if the client half is missing |
ai-glasses-webapp-publish (meta-wearables-webapp) | Its scripts/qr_generator.py turns the deep link into a scannable PNG |
/validate-webapp-game | Enforces that game code logs through the logger, not console.* |
scripts/install.mjs (opens in a new tab)scripts/smoke-log-api.mjs (opens in a new tab)templates/api/_http.js (opens in a new tab)templates/api/_store.js (opens in a new tab)templates/api/log-auth.js (opens in a new tab)templates/api/logs.js (opens in a new tab)templates/public/logs.html (opens in a new tab)templates/public/logs.js (opens in a new tab)templates/scripts/debug-url.mjs (opens in a new tab)templates/scripts/lib/deep-link.mjs (opens in a new tab)templates/scripts/vite-log-api.d.mts (opens in a new tab)templates/scripts/vite-log-api.mjs (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
remote-logging, webapp-game, meta-glasses, log-portal, serverless
7 skills in this plugin
/create-webapp-gameScaffold a new webapp game for Meta Display Glasses using Vite + TypeScript + Three.js + Vitest, with a renderer- and input-agnostic architecture. Supports both 2D and 3D games. Use when the user wants to start a glasses game, build a 2D or 3D game for smart glasses, or scaffold a Three.js game project for Meta Display Glasses./iterate-webapp-gameAutonomously iterate on a webapp game in a real browser via the Chrome DevTools Protocol (CDP): load the running game, take screenshots, click/type/press keys, run console commands, read game state, and capture console errors — then change code and repeat. Also runs a structured verification pass over a finished build (renders at all, visible on the additive display, every input responds, HUD inside the 600x600 stage) using a screenshot-statistics tool, so frames can be checked numerically instead of eyeballed. Drives a Chrome it launches itself, or attaches to one the user started with `npm run chrome` when the agent is sandboxed and cannot launch a browser. Use when the user wants to screenshot the game, see what it looks like, debug it in the browser, click through it, drag in it, reproduce a bug, check the console, inspect runtime state, verify a change visually, or check whether a finished game actually works — all without a headset./read-webapp-game-docsDiscover documentation about building games on the Meta Display Glasses platform — platform capabilities (600x600 additive display, CPU/GPU/memory budgets, EMG/D-pad input model and latency, refresh rate) and the meta-wearables-webapp-game framework code (renderer/input-agnostic architecture, project structure/tooling, Three.js-vs-DOM rendering split, 2D/3D asset loading, audio, localization, and logging/debugging on a device with no console). Invoke this when the user explicitly asks for it, when the create-webapp-game skill runs (it reads these docs before scaffolding), or when a project's CLAUDE.md or similar directive instructs the agent to consult the Meta Display Glasses platform / meta-wearables-webapp-game framework docs before planning or writing code. Do not auto-trigger merely because a project looks like a Meta Display Glasses app — a create-webapp-game project opts in via its own CLAUDE.md./update-webapp-game-frameworkUpdate an existing webapp game's managed framework code (`src/framework/`) to the latest version bundled with this plugin. Use after updating the plugin to pull the newest renderer / input / game-loop / math engine code into a game project without touching game files — i.e. "get the latest framework code", "upgrade the game framework", "re-sync src/framework"./validate-webapp-gameValidate a webapp game against its project guidelines. Six checks: (1) input — UI may be HTML/DOM, but NO input handled through the DOM (no inline on*= attributes, no addEventListener for input events); all input flows through the InputManager; (2) localization — all user-facing text goes through i18next (t('key'), data-i18n), no hardcoded DOM strings; (3) preload — no assets loaded over the network at runtime; (4) logging — game code logs through the framework logger, never console.*; (5) layering — gameplay stays renderer-, input- and audio-agnostic (only src/models.ts imports three, only src/main.ts + src/hud/ + src/log.ts touch the DOM, no game code touches the Web Audio API); (6) drag opt-in — pointerDrag, touch-action:none and use of the movement delta must agree, so a tap-only game never ships the drag flag. Use when the user wants to validate, lint, or check a Meta Display Glasses game project, or verify its input-handling, localization, asset-loading, logging, layering, or drag opt-in conventions./webapp-game-directorAct as a demanding creative director for a game project — run a collaborative, milestone-structured iteration loop that holds a high quality bar and treats real playtesting as the ground truth. It surveys the game, presents a ranked slate of issues and lets the user pick where to start, works each issue with them (plan → build → user playtest feedback) before moving on, then re-surveys for the next milestone. Use whenever the user wants to improve, polish, iterate on, critique, review, tighten, or "make more fun" a game; when they ask "is my game good / is it ready to ship / what should I do next"; or when they want a playtest-driven quality pass. Project-agnostic (any engine/language/platform) with extra Meta Display Glasses awareness — it is the iterate/improve phase of the meta-wearables-webapp-game skill family (create → iterate → ship). Not a feature-order-taker: it questions, prioritizes, and pushes the work toward better before it ships.npx claudepluginhub meta/meta-wearables-webapp --plugin meta-wearables-webapp-gameOther plugins' skills for the same job