wren/glyph Public Public: anyone can read this; nobody can change it.
forked from apps/glyph
workbenchthis machine
Files e45e4989a79ef3f801c453528dd5b471f91bea4f
| 1 | # glyph |
| 2 | |
| 3 | Type a prompt, get SVG logos and icons drawn by Claude; preview in your theme, copy or download. |
| 4 | |
| 5 | Describe something — "a hex chip with a circuit b", "a lighthouse for a |
| 6 | monitoring app" — pick a kind (logo mark, app icon, badge, spot |
| 7 | illustration), and Claude draws four different takes as SVG in about a |
| 8 | minute. Switch palette (Sage, Moss, Neon, Mono, Blueprint) to see them in |
| 9 | any theme, then **Copy** the SVG or **Save** it as a file in that palette. |
| 10 | |
| 11 | ## What is real |
| 12 | |
| 13 | - **The drawing is real**: the app runs Claude Code (`claude -p`, no tools, |
| 14 | model `claude-opus-5-5`) with the token in `CLAUDE_CODE_OAUTH_TOKEN`. Set it |
| 15 | in Settings → App → Environment (make one with `claude setup-token`). |
| 16 | Without it a drawing fails at once with a sentence saying exactly that. |
| 17 | - **Every SVG is rebuilt from an allowlist** (`src/glyph.ts` `sanitize`): |
| 18 | shapes, `title` and plain attributes only. No script, style, link, image, |
| 19 | `url(…)` or event handler survives, and previews are `<img>` data URIs, so |
| 20 | nothing in a drawing can run on the page. A saved file is served with a |
| 21 | sandboxing CSP. |
| 22 | - **Colours**: Claude draws in two placeholder colours (ink and glow, |
| 23 | `design/palettes.json`); a palette swaps those two. Downloads carry the |
| 24 | palette's real colours. |
| 25 | - **Drawings are private to whoever asked** (`contract.json`); an admin sees |
| 26 | everyone's. One drawing at a time per person, three at once for everyone. |
| 27 | A drawing left half done by a restart is marked failed with a reason. |
| 28 | - Also an API (`/api/drawings`, `POST` answers `202` then the row fills in; |
| 29 | listen on `/events` for `drawing.changed`), MCP tools (`draw`, |
| 30 | `get_drawing`, `list_drawings`, `delete_drawing`) and a terminal (list and |
| 31 | ask; a terminal can't show pictures). |
| 32 | - On the forge an app reaches the internet only through its egress proxy: |
| 33 | `forge.json` declares `api.anthropic.com` and `claude.ai`. |
| 34 | |
| 35 | This is an app: the forge runs it. Production follows the default branch; |
| 36 | every open pull gets a preview at its own address with its own copy of the |
| 37 | data. Everything the app keeps lives under `FORGE_APP_DATA`, which is what |
| 38 | makes "production data" and "preview data" two different things. |
| 39 | |
| 40 | sh |
| 41 | PORT=8080 FORGE_APP_DATA=./data bun run src/server.ts # run it here |
| 42 | bun test # what `forge.json`'s app.test runs on every push |
| 43 | FORGE_APP_DATA=./data bun run src/tty.ts # the terminal |
| 44 | FORGE_APP_DATA=./data bun run src/db.ts --check # schema version, integrity |
| 45 | bun run lint:design # no colour but the tokens' |
| 46 | bun run contract:emit # rewrite contract/openapi.json from the routes |
| 47 | |
| 48 | |
| 49 | `app.test` in `forge.json` runs beside `app.run` in every deploy, not before |
| 50 | it: the preview comes up the moment the app answers, and says `live`, or |
| 51 | `serving · tests failed` the moment the suite disagrees. |
| 52 | |
| 53 | ## The shape |
| 54 | |
| 55 | One implementation, many doors. `src/actions.ts` is every operation as a |
| 56 | plain function — `(db, who, input)` in, data or a named failure out — and |
| 57 | the page, the JSON API, the MCP server and the terminal all call it and |
| 58 | decide nothing themselves. `AGENTS.md` says how to add to it. |
| 59 | |
| 60 | | file | what it is | |
| 61 | | ---------------------------------- | -------------------------------------------------------------- | |
| 62 | | `src/actions.ts` | start, list, read, delete a drawing; the audit trail, read | |
| 63 | | `src/glyph.ts` | the ask, the reply read back, the SVG allowlist, palettes | |
| 64 | | `src/draw.ts`, `src/claude.ts` | the work after the response: Claude Code, run with no tools | |
| 65 | | `design/palettes.json` | the drawing palettes and the two placeholder colours | |
| 66 | | `contract.json` | who may do what: roles, and the least role each verb needs | |
| 67 | | `src/contract.ts`, `src/can.ts` | the table, read at boot; the forge's evaluator, verbatim | |
| 68 | | `src/security.ts` | the door: rationing, same origin, the table before the body | |
| 69 | | `src/audit.ts` | every change and every refused one, as a row | |
| 70 | | `src/who.ts` | who is asking, from the forge's signed headers | |
| 71 | | `src/db.ts` | SQLite under `FORGE_APP_DATA`, WAL, forward-only migrations | |
| 72 | | `src/live.ts` | the in-process bus and `GET /events` | |
| 73 | | `src/mcp.ts` | the actions as MCP tools at `POST /mcp` | |
| 74 | | `src/routes.ts` | every path, in one table, each API route described beside it | |
| 75 | | `src/openapi.ts` | the routes as OpenAPI; committed at `contract/openapi.json` | |
| 76 | | `src/page.ts` | the HTML, rendered on the server, with its share metadata | |
| 77 | | `design/tokens.json`, `src/tokens.ts` | the look as data, light and dark; compiled to `/tokens.css` | |
| 78 | | `src/http.ts` | the floor: headers, body cap, files | |
| 79 | | `src/server.ts` | boot: open the database, serve | |
| 80 | | `src/tty.ts` | the terminal, over the same actions | |
| 81 | | `src/env.ts` | what the forge told this process | |
| 82 | | `static/app.css`, `static/live.js` | the look in the tokens' words, and the board that stays current | |
| 83 | | `static/glyph.js` | copy, the palette swapped in place, the example prompts | |
| 84 | |
| 85 | ## What every app stands on |
| 86 | |
| 87 | - **The door.** Before a route sees a request, `src/security.ts` rations |
| 88 | writes (and a stranger's API calls), refuses a write from another site, |
| 89 | and turns away — before the body is read — anyone the table lets through |
| 90 | a resource's door for no row at all: 401 for a stranger, 403 for anyone |
| 91 | else. The action still decides about the real row. |
| 92 | - **The audit trail.** Every change, and every change refused, is a row: |
| 93 | who, which resource and verb, which row, when, and whether they were |
| 94 | let. Admins read it at `GET /api/audit`. A row that cannot be written |
| 95 | is a log line, never a failed request. |
| 96 | - **The API, described.** `GET /openapi.json` is `contract/openapi.json`, |
| 97 | written from the routes by `bun run contract:emit`; each operation names |
| 98 | its cell of the table (`x-contract`). `bun test` fails while it is stale. |
| 99 | - **Up, or not.** `GET /healthz` answers `{ ok, version, uptime }`; the |
| 100 | forge waits on it before it sends anyone to a deploy. |
| 101 | - **The look.** `design/tokens.json` holds every colour, space and size, |
| 102 | light and dark; nothing else spells out a colour (`bun run lint:design`), |
| 103 | and every pair a person reads meets 4.5:1 in both themes. |
| 104 | - **The open web.** A shared link unfurls (description, Open Graph, a |
| 105 | card); `/robots.txt` keeps crawlers to the page, and out of previews |
| 106 | entirely; `/.well-known/security.txt` sends a reporter to the forge |
| 107 | that runs the app. |
| 108 | |
| 109 | ## Who you are |
| 110 | |
| 111 | The forge says who is asking on every request it proxies, and the app |
| 112 | verifies the signature (`src/who.ts`); nothing else is trusted. Three tiers: |
| 113 | |
| 114 | - **anon** — anyone. Sees the page and is asked to sign in; nothing else. |
| 115 | - **user** — signed in to the forge and able to see this app. Draws, as |
| 116 | themselves, and sees and removes their own drawings. |
| 117 | - **admin** — able to write this repository. Sees and removes any drawing. |
| 118 | |
| 119 | "Sign in" is `/__forge/signin?to=<path>` and "Sign out" is |
| 120 | `/__forge/signout`; the forge answers both on the app's own host, and |
| 121 | `/__forge/report` too: it sends anyone, with no account, to report a |
| 122 | problem on this app's repository, if that repository is public. |
| 123 | |
| 124 | ## Any interface |
| 125 | |
| 126 | The same actions, the same rules, at every door. A script is the person |
| 127 | whose forge grant it carries; a bare script is anonymous. |
| 128 | |
| 129 | sh |
| 130 | curl -X POST https://<app>/api/drawings -H 'content-type: application/json' -d '{"prompt":"a fox made of circuit traces","kind":"mark"}' |
| 131 | curl https://<app>/api/drawings/1 # status: drawing → done, with svgs[] |
| 132 | curl -X DELETE https://<app>/api/drawings/1 |
| 133 | |
| 134 | |
| 135 | As an MCP server, for Claude Code or Claude Desktop — `draw`, |
| 136 | `get_drawing`, `list_drawings`, `delete_drawing`: |
| 137 | |
| 138 | sh |
| 139 | claude mcp add --transport http glyph https://<app>/mcp |
| 140 | |
| 141 | |
| 142 | json |
| 143 | { |
| 144 | "mcpServers": { "glyph": { "type": "http", "url": "https://<app>/mcp" } } |
| 145 | } |
| 146 | |
| 147 | |
| 148 | The page stays current over `/events`: a drawing fills in on its own when |
| 149 | Claude is done, without a reload. Without JavaScript it is the same page, one |
| 150 | reload behind. |
| 151 | |
| 152 | The terminal opens with the exact command in `FORGE_APP_SSH` when the app |
| 153 | runs (`ssh -p 2222 <name>@<forge>` — the app is the login name, the forge |
| 154 | the host; `<name>--<pull>@<forge>` for a preview's). It is `src/tty.ts` on |
| 155 | a real pty over the same data, as the account at the keyboard. |
| 156 | |
| 157 | The forge sets `PORT`, `FORGE_APP_DATA`, `FORGE_APP_ENV` (`production` or |
| 158 | `preview`), `FORGE_APP_URL`, `FORGE_APP_COMMIT`, `FORGE_APP_SSH` and |
| 159 | `FORGE_APP_IDENTITY_KEY` when it starts the app. `forge.json` says how. |