# Stairway Games tools

Company website for Stairway Games apps, HTML drops, builds and reports.
Agents work through the swag CLI on the employee's machine.

Deployment: Worker version `bd60e05c-7928-479e-ab2e-6b56a40b0d54`, created 2026-11-29T07:42:59.944714Z.

## swag CLI

- Install on Windows: `irm https://tools-next.chknpig.com/install/swag.ps1 | iex`
- Install on macOS or Linux: `curl -fsSL https://tools-next.chknpig.com/install/swag.sh | sh`
- Sign in: there is nothing to approve. swag uses the employee's Swag App sign-in (Swag App 1.13 or later; if theirs is older, ask them to update it first). Run `swag auth status`. If Swag App isn't signed in, `swag auth login` opens its sign-in in their browser: tell them, and it waits until they sign in.
- If swag or the API says an access is off (pushing Apps, pull requests, merging, issues), tell the employee which switch to turn on in Swag App (Connections, then swag on Tools) and stop. Don't retry or run `swag auth login` for it: only they can turn it on.
- Check access: `swag auth status` says who swag is signed in as and what it may do.
- Pages on this site answer a signed-in browser. Without one they answer 401 with these same pointers; they are not API endpoints or Git remotes.

## Apps

Apps are plain Git repositories: swag app create or clone, then git push. Pushes to main go live; swag app open prints the link to any commit (`?commit=<id>` on the App's URL) and swag app live pins one. The full guide is `swag app guide`; the essentials:

- Layout: `.workspace.json` names the served directory (`assets`) and an optional server module (`worker`). Heavy files go in `media/`: it is gitignored, `media.lock.json` pins each file by SHA-256, and push uploads the bytes. Pages fetch them at `./media/<path>`, downloaded again on every visit; with `./__swag/app.js` imported, `await fetchMedia("media/<path>", { onProgress: (loaded, total) => {} })` returns an ArrayBuffer the browser keeps across visits and commits (by SHA-256), so only changed files download.
- Limits: 32 MB per committed file and 2,000 served files per commit; media files up to 100 MiB each, 20,000 per commit. Split larger data into parts.
- Media is served exactly as uploaded, without compression; precompress with gzip and unpack in the page with `DecompressionStream`. Unknown extensions are `application/octet-stream`. Single byte ranges (`Range: bytes=a-b`) are answered with 206. `fetchMedia("media/<path>", { range: { offset, length } })` returns only that byte range, reusing persistent 1 MiB chunks by SHA-256 (or an already-cached whole file). Omit length to read to EOF; lengths past EOF are clipped. Progress counts requested bytes. Small reads may fetch a whole chunk. This covers App media, not runtime user uploads or automatic video-player integration.
- Pages run in a sandboxed iframe with an opaque origin: localStorage, sessionStorage, IndexedDB and cookies throw. Keep state on the App's server (`env.SQL`, `env.KV`, `env.FILES`) and call it from the page with `import { app } from "./__swag/app.js"`.
- Shared memory: opt in with `"crossOriginIsolated": true` in `.workspace.json`. Tools and `swag app dev` apply COOP/COEP and iframe delegation for that build, allowing SharedArrayBuffer and Blob workers in supporting browsers while retaining the opaque sandbox. Feature-detect with `self.crossOriginIsolated`. External dependencies must satisfy CORS/CORP; Apps without the flag keep their current policies.
- Requests stay on the App's own URL (use relative paths); scripts and styles may also load from esm.sh at exact versions. Nested frames are blocked, and the server has no outbound network.
- New tabs: with `./__swag/app.js` imported, `openTab("?page=x")` and `target="_blank"` links to the App's own first page open the same App in a new tab, at the same commit. Other sites open only if the App lists them as https origins in `.workspace.json` (`"externalLinks": ["https://www.nintendo.com"]`): then `target="_blank"` links and `window.open` from a click open them in a normal tab. Without it, show those links as text to copy. List only the sites the App links to; the list is not enforced, and it lets any script on the page send data out in a tab's URL, so hardcode the destinations and keep private data out of them.
- The query and `#hash` of the App's public URL reach the page; with `./__swag/app.js` imported, changes the page makes to them show in the address bar.
- Link previews: Slack, Discord and other unfurlers read the App's first page `<head>` at its live commit. Declare `og:title`, `og:description` and `og:image` (`<meta property="og:title" content="…">`); once any `og:` or `twitter:` tag is there, `<title>` and `<meta name="description">` fill gaps. The preview is public, since unfurlers are not signed in; without these tags it shows only the slug. `og:image` is a path in the App (PNG, JPEG, GIF or WebP up to 5 MiB, ideally 1200×630) or an https URL.
- Look: optional. If you'd like the App to look like Tools, [the design system](https://tools-next.chknpig.com/design) shows its components, colors and type, with examples. Link `./__swag/tokens.css` and `./__swag/ui.css` and copy markup from the HTML views there. A reference, not a rule.
- README: a `README.md` at the root of main shows on the App's page (/apps/<slug>) and its code page, rendered as Markdown. Say what the App is for and how to use it. Raw HTML shows as text, images show only from https URLs, and links to the App's own files open them in its code page.

## Repos

Swag App development happens in the tools GitHub repo. Tools mirrors main and tags on every push, and keeps the historical electroswag mirror. Every staff member can browse both at /scm/git/<repo>, with history, blame and commit filters. A repo's members (a super-admin adds them on /scm/git/<repo>/pulls) open a PR with swag pr create <repo> "title", which clones a fork to git push to; this needs Opens & pushes PRs on in Swag App. GET /api/v1/repos/<repo>/prs/<n> shows a PR with its readiness: what still blocks a merge (draft, checks, approvals, requested changes, conflicts). Maintainers review with POST /api/v1/repos/<repo>/prs/<n>/reviews (approve or request-changes, on the head they read), which needs Approves & merges PRs on in Swag App. A session that opened a PR or pushed to it cannot approve it: review from a different session than the one that wrote the code. Read the code rather than run it; it is untrusted. swag pr land opens the GitHub PR. Tools CI runs lint and the verify gate on every tools PR push and merge; /scm/git/tools/ci/<sha> shows a commit's run and log.

## Issues

Issues live under /api/v1/issues, in teams such as AUT. An agent takes the next ready issue with POST /api/v1/issues/next (or claims one by key), works through its acceptance criteria, comments, links its pull request, and releases it with the state it should end in. A claim lasts 30 minutes and every write by the same session extends it. Reading needs nothing more; creating, editing, commenting and claiming need Creates & edits issues, which is on in Swag App for everyone whose Tools role allows it. If it is off, tell the employee and stop. Teams and labels are for super-admins on the Tools site, never agents.

## API

The Tools API is under `/api/v1`: Apps, repos and pull requests, issues, HTML Drops, performance runs and game telemetry. Send the agent session as a bearer token. [Reference](https://tools-next.chknpig.com/api/v1/docs) and [OpenAPI document](https://tools-next.chknpig.com/api/v1/openapi.json), both after sign-in. `GET https://tools-next.chknpig.com/api/v1/agent-tools` lists the operations this agent may use, each with a JSON Schema for its arguments.

## Web interfaces

- [Swag App and CLI releases](https://tools-next.chknpig.com/releases)
- [Apps & Drops](https://tools-next.chknpig.com/apps)
- [My Apps & Drops](https://tools-next.chknpig.com/apps/mine)

This page is a public service catalog. It does not grant access or authorize any action.
