# AGENTS.md ## Orientation - This repo is a **spec-first** project. `schema.arch` (the signed arch-llm spec) is the single source of truth for the backend. `paste_bin/` is generated from it and verified against frozen owner tests; `ui/client.js` + `ui/openapi.json` are emitted from it (deterministic, no LLM). The SPA (`ui/index.html`, `ui/app.js`) is the only hand-maintained frontend code. - The old Flask implementation still lives on `main` (single-file `app.py`). This branch (`fastapi-port`) replaces it. Port report: repo wiki, **FastAPI port (arch-llm pipeline)**. ## Hard rules - **Never hand-edit `paste_bin/*.py`** (except `app.py`/glue if you understand the deterministic-glue invariant) or `ui/client.js` / `ui/openapi.json`. Change `schema.arch` (or the design session), re-sign, rebuild, re-emit. The next build overwrites hand-edits. - **Never weaken or modify `tests/`** — they are owner-authored ground truth, frozen into `tests/manifest.json` for every build. A failing test means the spec or the generation is wrong, not the test. - The SPA must call **only** `window.PasteBinAPI` (the generated client). No hand-rolled `fetch`, no hardcoded endpoints, no second copy of error literals except the client-side-feedback mirror in `ui/app.js` (keep it in sync with `x-error-literals` when re-emitting). - Keep the deployed UI same-origin: API paths + SPA + contract artifacts under one origin via `ui/Caddyfile`. - Paste IDs: `^[a-f0-9]{16}$`. Validate before any filesystem access (path-traversal guard). - Image uploads: magic-byte validation (PNG/JPEG/GIF/BMP/WEBP-as-RIFF+`WEBP`@8..11/ TIFF); SVG rejected. Mimetype derived server-side from extension — never trust the client's. ## Commands ```sh # backend docker build -t paste-bin . docker run -d --name paste-bin -p 18900:8080 -v paste-bin-data:/app/data paste-bin pytest # 51 owner tests # spec pipeline (requires the arch-llm CLI + the `paste-bin` design session) archllm build --session paste-bin --out /tmp/paste-bin-build # regenerate backend (signoff-gated) archllm openapi paste-bin --client --out ui # re-emit contract artifacts ``` Editing the spec: prefer the arch-llm design session (canvas / spec-ops), which owns `draft/schema.arch` + `draft/tests/`; `design paste-bin signoff` after edits, then rebuild. Editing `schema.arch` in this repo directly also works — just re-run the build against it (`archllm build schema.arch ...`) and update `signoff.yaml` provenance. ## Deploy notes - Caddy 2.6.2 quirk: the `root` directive is site-level (a `root` inside a `handle` block fails the Caddyfile adapter). `ui/Caddyfile` uses the flat idiom: `handle` per API path (reverse proxy) + site-level `file_server`. Run it **from the `ui/` directory** (`root * .` resolves against CWD): `cd ui && caddy run --config Caddyfile`. - Backend container: uvicorn on `:8080` inside, data under `/app/data` (`store/` metadata JSON, `.txt` text content, `uploads/` image/file bytes). Volume `paste-bin-data` persists it; `docker restart paste-bin` resets the in-process rate limiter (10 uploads / 60 s per IP) but not the data. - HEAD requests must work on API routes (Flask-compat; FastAPI needs an explicit `methods=["GET", "HEAD"]` — the spec pins this). ## Verified state (provenance) - Build r3 (2026-11-18, qwen27b): `status=ok`, 51/51 tests, 92.5% coverage, boot ok. - Signoff: schema `07e1c8b9e27e…` / tests `ce3bef1efa30…` (see `signoff.yaml`). - Live probe: 62/62 assertions green (headers, roundtrips, all 7 bug-fix cases, 400/404/413/429 with exact error strings, expiry-delete, restart persistence).