3.3 KiB
3.3 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
- Front end: create
app/static/js/tools/<id>.jsexportingmount(root, ctx):- append the UI to
root; start withel('div.tool', {}, toolbar, …)so it fills the view (.toolbar,.btn,.segmented,.pane,.statusbarare the shared building blocks incss/style.css); ctx.restis the path after the tool's own (/paste/abc→abc),ctx.querythe 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.
- append the UI to
- 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 toCATEGORY_ORDERif it should not sort last. Optional:opensPaste: trueif the tool loads?paste=<id>(it then shows in a paste's "Open in" menu; callmarkRead(id)frompaste-state.jswhen it does, and don't overwrite the local draft), andbadge: () => numberfor a count on its nav item (dispatchtools:badgesonwindowwhen it changes). Share buttons usecreatePaste(text, { share: true }). - Server side, only if needed: add
app/tools/<id>.pyexposingrouter(a FastAPIAPIRouter) with routes under/api/<id>/…, and optionalasync startup()/shutdown().main.pymounts every module intools/automatically. Persistent files go under$DATA_DIR(/data, bind-mounted from/opt/tools/data). Keep it light: it shares a small server with other workloads (container capped at 192 MB / 0.5 CPU). - 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
storefromui.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. ui.jshas the shared pieces:el,segmented,modal,dropdown,toast,copyText,copyRich(HTML + plain text),downloadText,openTextFile,tabIndent,store,debounce. Noteel()sets string values as attributes; assigninnerHTMLwithObject.assign.- Formatters in
code-format.jsmust stay whitespace-only for the built-in languages. After changing one, run the tests and also the formatter over a large set of real files, checking thatsquash(out) === squash(src)and that formatting is idempotent (that's how the current rules were validated: 1000+ Kotlin/Java/C/C++ files, 0 problems). - Heavy libraries (Prettier, sql-formatter) are loaded with
import()on first use only; keep the initial page light (the server's upstream is slow). - Run
node --test tests/and check the page in a browser before deploying;deploy.shrefuses to deploy if the tests fail. - This repo is public. Never commit anything about the machines it runs on: no IPs, SSH
targets, hostnames, providers, network layout or tunnel setup. The deploy target lives in the
gitignored
.deploy.env; operational notes belong in the private homelab docs.