tools/CLAUDE.md
neil 9d910eb147 Tools site: Markdown editor, JSON editor, 24-hour pastebin
Single FastAPI container with a registry-driven single-page front end, so
new tools are one module plus one registry entry. Runs as one container behind a reverse proxy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-01 23:32:22 -08:00

1.9 KiB

CLAUDE.md

See README.md for what this is and how it's deployed. This file is how to extend it.

Adding a tool

  1. Front end: create app/static/js/tools/<id>.js exporting mount(root, ctx):
    • append the UI to root; start with el('div.tool', {}, toolbar, …) so it fills the view (.toolbar, .btn, .segmented, .pane, .statusbar are the shared building blocks in css/style.css);
    • ctx.rest is the path after the tool's own (/paste/abc → abc), ctx.query the search params, ctx.navigate(path) client-side navigation, ctx.setTitle(text) the top-bar suffix;
    • return a cleanup function if you add global listeners or timers.
  2. Register it in app/static/js/registry.js (id, name, path, category, icon, description, load). The sidebar, home grid, /-search and router all come from that list. Add a new category to CATEGORY_ORDER if it should not sort last.
  3. Server side, only if needed: add app/tools/<id>.py exposing router (a FastAPI APIRouter) with routes under /api/<id>/…, and optional async startup()/shutdown(). main.py mounts every module in tools/ automatically. Persistent files go under $DATA_DIR (/data, bind-mounted from /opt/tools/data). Keep it light: this runs on the shared server (container capped at 192 MB / 0.5 CPU).
  4. Prefer running in the browser. Vendor any library into static/vendor/ (pinned version in the filename comment or README); the CSP allows scripts from 'self' only, no CDNs.

Conventions

  • Persist per-browser state with store from ui.js (namespaced, never throws), and flush debounced saves on leave (onLeave, debounce(...).flush).
  • Never render user content as HTML without DOMPurify (the Markdown preview) or textContent.
  • Run node --test tests/ and check the page in a browser before deploying; deploy.sh refuses to deploy if the tests fail.