Client side atproto account migrator in your web browser, along with services for backups and adversarial migrations. pdsmoover.com
pds-moover AGENTS.md
8.2 kB · 131 lines
Markdown
at main

AGENTS.md #

PDS MOOver: tools to migrate an atmosphere account to a new PDS, find missing blobs, keep backups and restore from them. The repo is two halves that only meet over XRPC:

  • Rust (Cargo workspace: web, worker, cron-worker, admin_cli, shared, lexicon_types_crate): the backup service and its XRPC API. It does not serve or build the UI.
  • JavaScript (pnpm workspace: web-ui and packages/*): the frontend and the migration logic.

JavaScript layout #

  • web-ui/ – SvelteKit 2 + Svelte 5 (runes) app. The user signs in through their own PDS with atproto OAuth and all migration logic runs in the browser. The server only serves pages and /oauth-client-metadata.json (web-ui/src/routes/oauth-client-metadata.json/+server.ts), whose public URL is the OAuth client_id.
  • packages/moover/ – @pds-moover/moover, the migration logic (Migrator, MissingBlobs, BackupService, Restore, PlcOps, rotation key helpers). Platform agnostic: no SvelteKit, no browser globals, no storage. Sessions and storage are handed in by the caller.
  • packages/lexicons/ – @pds-moover/lexicons, generated TypeScript for the JSON in /lexicons.
  • packages/mock-atmosphere/ – in-memory mock network for tests (see Testing).

Commands #

Run from the repo root (pnpm only; the packageManager pin and .npmrc engine-strict live there).

  • pnpm install
  • pnpm dev – the web ui. Must be http://127.0.0.1:5173: dev uses an atproto loopback OAuth client, authorization servers only redirect to 127.0.0.1, and the OAuth client refuses to run on localhost.
  • pnpm lint – ESLint (web-ui)
  • pnpm check – svelte-check for web-ui, tsc --noEmit for packages/moover
  • pnpm test – vitest in web-ui and packages/moover (colocated *.test.ts), node:test in packages/mock-atmosphere. Single file: pnpm --filter @pds-moover/moover test lib/plc-ops.test.ts
  • pnpm test:e2e – builds the mock, then runs Playwright in web-ui
  • pnpm build – builds every package (lexicons first, in dependency order)

Verify changes with:

pnpm lint && pnpm check && pnpm test && pnpm test:e2e

Workspace rules #

  • Workspace packages export their TypeScript source (exports points at lib/*.ts), so nothing needs building for dev, typecheck or tests. publishConfig.exports swaps in dist/ on publish.
  • In web-ui/package.json the workspace packages are devDependencies on purpose: adapter-node leaves dependencies as runtime imports, and those would resolve to .ts files. As devDependencies (plus ssr.noExternal in web-ui/vite.config.ts) they are bundled.
  • @atproto/lex* versions are pinned once, in the catalog of pnpm-workspace.yaml. The migration code does instanceof checks against their classes, so the workspace (and the bundle: see dedupe in web-ui/vite.config.ts) must contain exactly one copy.

Lexicons (generated code) #

packages/lexicons/lib/lexicons/** is generated from /lexicons by pnpm lex:generate (@atproto/lex codegen). Never hand-edit it: add or change the lexicon JSON under /lexicons, rerun the script, import from @pds-moover/lexicons. The Rust types in lexicon_types_crate are generated separately (jacquard) from the same JSON and are not part of the JS workflow.

Formatting #

Formatter is oxfmt (.oxfmtrc.json: no semicolons, single quotes, arrowParens: avoid). It is not a devDependency: run oxfmt (or pnpm dlx oxfmt). ESLint enforces single quotes; oxlint (.oxlintrc.json, pnpm --filter web-ui exec oxlint) is a secondary linter with no package script. Older files keep the style they were written in; match the file you are editing.

OAuth architecture notes #

  • Each page requests only the scopes it needs (web-ui/src/lib/oauth/scopes.ts); the client metadata advertises the union (ALL_SCOPES).
  • Dev = loopback client (client_id = http://localhost?redirect_uri=...&scope=...); prod = hosted client_id https://<PUBLIC_APP_URL>/oauth-client-metadata.json.
  • The source account is the OAuth session (persisted by the browser OAuth client in IndexedDB). The destination account is a password session (@atproto/lex-password-session) cached in localStorage (web-ui/src/lib/sessionCache.ts + per-flow wrappers) so a migration can resume after a refresh.
  • The package never imports the OAuth client. It takes any AccountAgent (did + fetchHandler), which both an OAuth session and a password session satisfy.

Sentry #

  • @sentry/sveltekit in web-ui only. Both sides read PUBLIC_SENTRY_DSN at runtime and stay off when it is unset (local dev, e2e). Browser init is web-ui/src/hooks.client.ts, server init is web-ui/src/instrumentation.server.ts (loaded via kit.experimental.instrumentation).
  • Browser events go through the same-origin tunnel web-ui/src/routes/cowbell/+server.ts, which only forwards envelopes addressed to our DSN. Keep the path free of words like "sentry" or "monitoring" that ad blockers match on.
  • web-ui/src/lib/sentryScrub.ts strips the user block, hostname and URL query strings from every event and breadcrumb. IP-derived location is removed on the Sentry side by the project's "Prevent Storing of IP Addresses" setting, not by the SDK.
  • Events are tagged side: browser|server. Flow pages tag source_pds / target_pds (hostnames only) through web-ui/src/lib/sentryContext.ts in a $effect that clears them on leave.
  • Caught errors go through reportError(error, op) in web-ui/src/lib/sentryReport.ts, next to the existing console.error. It drops conditions the UI handles itself (2FA prompts, wrong passwords, bad invite codes or PLC tokens, rate limits, aborted requests) and tags the rest with op (e.g. migration.run). Use level: 'warning' for best-effort work the page recovers from. Never put handles, DIDs or emails in extra.
  • Source maps upload on vite build when SENTRY_AUTH_TOKEN is available (gitignored web-ui/.env.sentry-build-plugin, mounted into the image build as a secret by just release).

Testing #

  • Unit – vitest, node environment. Package logic is tested in packages/moover/lib, client modules in web-ui/src.
  • mock-atmosphere – one process, five listeners: source PDS :31001, dest PDS :31002, plc.directory :31003, slingshot :31004, PDS MOOver directory API :31005. Each PDS is also its own OAuth authorization server (src/roles/oauth.ts) that approves on the spot; DPoP proofs are required but never verified. /_mock/reset seeds a scenario, /_mock/state snapshots it. Its own node:test files run the package against it with a password session, which is the check that the package works outside a browser.
  • E2E – web-ui/e2e, Playwright, Chromium, one worker (the mock state is shared). Specs sign in through the real @atproto/oauth-client-browser against the mock. The app runs on 127.0.0.1:5183 so it never attaches to a dev server you have open. External origins are routed to the mock in e2e/support/routes.ts; the two server-side fetches (directory lookup and describeServer for /moover/<pds>) are routed by e2e/support/ssr-fetch-rewrite.mjs, preloaded into the dev server. There is no test-only code in the app itself.
  • Pages are server-rendered, so use gotoApp/gotoSignIn/signInWithOAuth from e2e/support/fixtures.ts: typing into a form before hydration loses the input.

Deploy #

Images are built from Dockerfiles/ and pushed with the justfile (just release); production composes are in ProductionComposes/. just test-build-ui builds the web ui image locally without pushing. Every image builds from the repo root: Dockerfiles/web-ui.Dockerfile copies web-ui plus packages/lexicons and packages/moover, so a new workspace package the ui imports has to be added there too. The web ui is a Node server (@sveltejs/adapter-node, node build) that reads PUBLIC_APP_URL, ORIGIN and PUBLIC_XRPC_BASE at start-up (documented in web-ui/.env.example). Destination PDSs come from the public com.pdsmoover.pds.listPds/searchPds directory endpoints on the PUBLIC_XRPC_BASE API.