Developing Hatch
How to run Hatch from this repo, what each package does, and the checks to run. Agents: read AGENTS.md first.
Run it
pnpm install
pnpm dev # web, http://localhost:5173
pnpm dev:desktop # desktop app, opens ~/Documents/Hatch
pnpm test # unit tests
pnpm typecheck
Open another folder on desktop with HATCH_VAULT=/path/to/vault pnpm dev:desktop, or use the vault button in the sidebar.
Accounts (optional)
pnpm --filter @hatch/server start # http://localhost:8787, SQLite in apps/server/data
VITE_HATCH_SERVER=http://localhost:8787 pnpm dev
To open the app from another device (a phone on your Tailscale network, say), serve the account server through the dev server so both share one address: VITE_HATCH_SERVER=/ HATCH_DEV_SERVER=http://localhost:8787 pnpm dev. Add that address to the server's HATCH_ORIGINS, and to Vite's allowed hosts with __VITE_ADDITIONAL_SERVER_ALLOWED_HOSTS=<host>.
Add VITE_HATCH_REQUIRE_ACCOUNT=true to require sign-in before using the app. The same server stores synced vaults and published sites in SQLite.
Publishing settings on the server:
HATCH_SITES_HOST=sites.example.comgives every site its own address, likenotes.sites.example.com. Point a wildcard DNS record at the server. Private sites need this. For local testing,sites.localhost:8787works in Chrome.- Without it, sites are served at
/s/<address>/in a sandbox, and only public sites are allowed. HATCH_MAIL=resendorpostmark, withHATCH_MAIL_KEYandHATCH_MAIL_FROM, sends email. Invite-only sites need it, because invited people sign in with a link sent to their email.HATCH_MAIL=logprints email instead, for development.- Email updates for sites also need
HATCH_MAIL. With Postmark, setHATCH_MAIL_BROADCAST_STREAMto your broadcast stream. HATCH_ABUSE_EMAILgets abuse reports about hosted sites, with a link to take a site down. See deploy.md.HATCH_ERROR_DSNsends crash reports from the server, andVITE_HATCH_ERROR_DSNfrom the apps (at build time). Reports never include note content. See errors.md.HATCH_MAX_SITES(default 10),HATCH_MAX_SITE_BYTES(default 500 MB) andHATCH_MAX_SUBSCRIBERS(default 5000 per site) set the limits.
Plans and billing (optional):
STRIPE_SECRET_KEYturns on plans. Accounts start on Free and pay for Pro or Careers through Stripe Checkout. Products, prices and the billing portal's settings are made in Stripe on first use. Without it, every account gets every feature, up to the limits above.STRIPE_WEBHOOK_SECRETis the signing secret of a webhook endpoint athttps://<server>/api/billing/webhook, sendingcheckout.session.completedandcustomer.subscription.created,.updatedand.deleted. Plans only change when Stripe calls it, so the server won't start with a key but no webhook secret.- Plans, their prices and what each turns on are in
apps/server/src/plans.ts. A plan can lower a limit, never raise it past the server's.
Mobile
cd apps/mobile
pnpm add:ios # once, needs Xcode
pnpm ios # builds, syncs and opens Xcode
Android works the same way with add:android and android.
Layout
Every package is standalone and could live in its own repo.
| Package | What it does |
|---|---|
@hatch/markdown | Markdown parser and serializer. Lossless for unchanged blocks |
@hatch/vault | Files, index, link resolution, backlinks, search, attachments |
@hatch/editor | Editor kit on ProseMirror with a typed extension API |
@hatch/plugin-api | Plugin host, permissions, community plugin loader |
@hatch/plugins | The built-in plugins |
@hatch/theme | Tokens, built-in themes, contrast checks, theme files |
@hatch/platform | The only shell-specific seam: web, desktop, mobile |
@hatch/account | Optional account client (bearer tokens) |
@hatch/sync | Two-way file sync engine with conflict-safe writes |
@hatch/import | Importers, with their own HTML parser and zip reader |
@hatch/publish | Vault to website: docs, blog and portfolio templates, search, RSS, SEO |
@hatch/blocks | Markdown components: chart, progress, tabs, button, toc, form. Checks, suggestions and HTML |
@hatch/highlight | Syntax highlighting for code blocks, colored by theme tokens |
@hatch/app | The React UI shared by all three apps |
@hatch/mcp | MCP server over a vault |
Apps: apps/web, apps/desktop, apps/mobile, and apps/server (Hono and Better Auth).
Checks
scripts/check.sh runs all of these: typecheck, unit tests and every browser suite, with its own builds and servers. scripts/check.sh quick skips the browser suites. Working on the code with an agent? Start with AGENTS.md, which lists every command.
| Command | What it covers |
|---|---|
pnpm test | Markdown round-trip and edit safety, editor bridge, vault, plugins, themes, MCP, accounts |
python3 scripts/e2e.py <url> | Typing, shortcuts, tasks, links, image paste, palette, undo |
python3 scripts/e2e-safety.py <url> | Agent appends, outside edits, rename and delete races, vault switch, failed saves |
python3 scripts/e2e-plugins.py <url> | Community plugin consent, lifecycle and sandbox isolation, panels in frames, community themes |
python3 scripts/e2e-images.py <url> | Image resizing, full-size view, attachments panel |
python3 scripts/e2e-theme-studio.py <url> | Making and saving a theme |
python3 scripts/a11y-check.py <url> | Keyboard and focus behavior from the accessibility audit |
python3 scripts/e2e-sync.py <url> | Two devices: link, edit, conflict, new notes (needs the server) |
python3 scripts/e2e-sharing.py <url> | Two accounts: invite, accept, edit both ways, remove (needs the server) |
python3 scripts/e2e-publish.py <url> | Build, download, publish and share a site (needs the server) |
python3 scripts/e2e-canvas.py <url> | Canvas boards: draw, connect, keyboard, save |
python3 scripts/e2e-git-backup.py <url> | Git backup, history and restore, against a fake GitHub |
python3 scripts/e2e-history.py <url> | Version history on this device: compare, copy, restore, renames, deleted notes |
python3 scripts/e2e-import.py <url> | Notion import through the dialog |
python3 scripts/e2e-bigvault.py <url> | 3,000-note folder: virtualized tree, keyboard reach, reveal |
python3 scripts/perf.py <url> | Startup, large-note typing latency, save cost, search latency |
python3 scripts/perf-ab.py main . | Whether a change made startup, typing or boards slower: two builds measured in turns |
npx tsx bench/vault.bench.ts | Index, search and backlinks on a 5,000-note vault |
Past reviews and their fixes are in reviews/.
Which tests to keep
Proving a fix and keeping a test are different things. Every fix needs proof in its pull request: a failing test that now passes, a repro command, or before and after screenshots. Keep a new test only when both are true:
- It catches a mistake that types, lint and the tests we already have would miss.
- People would hit it and we'd drop everything to fix it, or it guards something that's costly to get wrong: the user's files (round-trip, never rewriting what they didn't change), sync, sharing and roles, sign-in, server input, stored formats and migrations, or a perf budget.
Leave out tests of wording, spacing, order and other looks, of what types already guarantee, and of rare edge cases with harmless outcomes. Proof for those is a screenshot.
Browser suites are the slow part of scripts/check.sh. Add to an existing suite before starting a new e2e-*.py, and test logic with a unit test beside the code, not through the browser. When a shared helper fixes several places, test one of them.