Reddit adapter for browserkit. Phase 1: unauthenticated public content via old.reddit.com.
Phase 2 (planned): authenticated feeds, saved posts, notifications.
- Language: TypeScript 5.x → compiled to
dist/ - Runtime: Node.js 20+
- Browser: Patchright (Playwright fork, anti-detection) via
@browserkit-dev/core - Key deps:
@browserkit-dev/core(peer),patchright(peer),zod
src/
index.ts # adapter definition — tools, isLoggedIn, selectors, rateLimit
scraper.ts # DOM extraction helpers
selectors.ts# CSS/ARIA selectors (edit here when site DOM changes)
tests/
reddit.test.ts # L1 unit — metadata, schemas, helpers (no browser)
reddit.integration.test.ts# L2 live scraping — real browser, real network
mcp-protocol.test.ts # L3 MCP protocol — server lifecycle, tool dispatch
harness.test.ts # Harness guards — isLoggedIn contract, pkg.json checks
dist/ # compiled output (gitignored; included in npm publish via "files")
npm install # install deps
npm run build # tsc → dist/
npm test # unit + harness tests (no browser)
npm run test:integration # live browser tests (requires internet)
make agent-check # full verification gate — run before declaring doneisLoggedInmust returnfalseby default when not authenticated — never use body-content length, cookie presence, or other heuristics; only returntruewhen a specific auth element is confirmed present (a hard lesson:bodyText.length > 100matched the public homepage).- Auth selectors must be exclusive to logged-in state — never
[aria-label*="account"](matches "Create an account" and other public nav). Usedata-testidordata-component. package.jsonmust have"files": ["dist", "README.md"]— without it, npm follows.gitignoreand ships source-only packages that the daemon can't load.repository.urlrequired — npm provenance rejects publishes without it.prepublishOnly: "tsc"— ensuresdist/is always rebuilt beforenpm publish.- Selectors belong in
selectors.ts— never hardcode CSS strings inindex.tsorscraper.ts. - No
anytypes — useunknownwith type narrowing or Zod schemas. - Phase 1 targets
old.reddit.comexclusively — stable HTML, no React SPA churn. Never switch towww.reddit.comselectors. isLoggedInhardcoded totruein Phase 1 — Phase 2 will replace it with real auth detection.
A task is complete when ALL of the following pass:
-
npm run buildexits 0 (no TypeScript errors) -
npm testpasses (L1 unit + harness tests, no browser needed) -
make agent-checkpasses (build + test in one command) -
npm pack --dry-runshowsdist/files in the tarball -
isLoggedInharness test passes with mock page (no regression)
- Phase 1 (current): public
old.reddit.com—get_subreddit,get_thread,search,get_user - Phase 2 (planned): authenticated feeds, saved posts —
isLoggedInwill navigate to/feed/
- Architecture:
../../ARCH.md(monorepo) orREADME.mdin this repo - Selector maintenance: update
src/selectors.tswhen the site changes DOM - Publishing: push to
main→ CI builds and publishes via OIDC (no token needed)