Operate

Self-hosting.

HalfTime is a Next.js 15 app deployed to Cloudflare Workers through OpenNext. Every page is prerendered at build time; the Worker serves them from static assets and runs the API routes and /mcp.

What you need

  • Node.js 20 or later and pnpm 10 (the repository pins pnpm@10.14.0).
  • A Cloudflare account, and Wrangler logged in (npx wrangler login).
  • Optional: an Anthropic API key, only if you want the server-side model routes (/api/extract, /api/baseline, /api/ocr). Without one, the site works exactly like the hosted one: visitors read new papers with their own key.

Deploy to Cloudflare Workers

  1. Clone and install.
Terminal
git clone https://github.com/Prashant-thakur77/HalfTime
cd HalfTime
pnpm install
  1. Create a KV namespace for the rate-limit counters, the spend total and the response cache, and put its id in apps/web/wrangler.jsonc under the binding CACHE.
Terminal
cd apps/web
npx wrangler kv namespace create CACHE
  1. In wrangler.jsonc, set your own Worker name, and change or remove routes (it points at the hosted custom domain).
  2. Build with OpenNext and deploy. These are the scripts in apps/web/package.json:
ScriptRuns
pnpm cf:buildopennextjs-cloudflare build
pnpm cf:previewopennextjs-cloudflare build && opennextjs-cloudflare preview
pnpm cf:deployopennextjs-cloudflare build && opennextjs-cloudflare deploy
pnpm cf-typegenwrangler types --env-interface CloudflareEnv cloudflare-env.d.ts
Terminal (in apps/web)
pnpm cf:preview     # build and run the Worker locally
pnpm cf:deploy      # build and deploy

open-next.config.ts uses the static-assets incremental cache: prerendered HTML is served straight from Workers static assets and never revalidated.

wrangler.jsonc

apps/web/wrangler.jsonc
{
  "$schema": "node_modules/wrangler/config-schema.json",
  "name": "halftime",
  "main": ".open-next/worker.js",
  "compatibility_date": "2026-10-01",
  "compatibility_flags": ["nodejs_compat", "global_fetch_strictly_public"],
  "assets": { "directory": ".open-next/assets", "binding": "ASSETS" },
  "kv_namespaces": [{ "binding": "CACHE", "id": "ab8653fd0915462ab7b923f92a93f3ca" }],
  "vars": { "DAILY_SPEND_CAP_USD": "15" },
  "observability": { "enabled": true },
  "routes": [{ "pattern": "halftime.prashantthakur.dev", "custom_domain": true }]
}
SettingWhy
main, assetsThe Worker and the static assets that OpenNext writes to .open-next/.
compatibility_flagsnodejs_compat for the Node APIs the server code uses; global_fetch_strictly_public so fetch() always goes out over the public internet.
kv_namespaces: CACHERate-limit counters, the daily spend total and cached model responses. Without it, the model routes skip limits and /mcp counts in memory.
vars: DAILY_SPEND_CAP_USDThe daily spend cap in US dollars for the model routes. The code defaults to 15 when it is unset.
observabilityWorkers logs. Error logs record only the error kind and status, never document text.
routesThe hosted custom domain. Change or remove it for your own deployment.

Secrets and variables

NameKindEffect
ANTHROPIC_API_KEYsecret, optionalTurns on /api/extract, /api/baseline and /api/ocr. Without it they answer 503 and the rest of the site is unaffected.
DAILY_SPEND_CAP_USDvariableStops the model routes for the rest of the day once the recorded spend reaches it (503).
CACHEKV bindingSee above.
Terminal (in apps/web)
npx wrangler secret put ANTHROPIC_API_KEY

Keep keys out of the repository

Never commit a key. .env* files and .dev.vars are ignored by git, and CI fails the build if a key-shaped string appears in the client bundle.

Local development

Terminal (repository root)
pnpm --filter web dev            # http://localhost:3000
  • next.config.ts calls initOpenNextCloudflareForDev(), so getCloudflareContext() works under next dev. If no context is available, the server falls back to process.env.
  • To try the server-side model routes locally, export ANTHROPIC_API_KEY in your shell before starting the dev server. Without KV, they run without rate limits or a spend cap.
  • Builds can go to a separate folder with NEXT_DIST_DIR, for example NEXT_DIST_DIR=.next-docs npx next build and NEXT_DIST_DIR=.next-docs npx next start -p 3199.

Rebuilding the data

The site ships with pre-computed data in apps/web/src/data/. To rebuild it with your own key (responses are cached under .cache/, so reruns are free):

Terminal (repository root)
export ANTHROPIC_API_KEY=...
pnpm samples:run                       # pre-run Claude on the twelve sample orders
npx tsx scripts/build-agent-run.ts     # the recorded docket-agent run
pnpm eval                              # the evaluation → eval/report.json and report.md
pnpm facts                             # every number on the site → facts.json

Running the tests

Terminal (repository root)
pnpm test                                      # every unit test: law, reader, agent, MCP, web
pnpm -r typecheck
pnpm --filter @halftime/law test:coverage      # fails under 100% coverage
pnpm eval:offline                              # the evaluation replayed from the recording
pnpm --filter web build && pnpm --filter web exec playwright test     # end-to-end and axe, four browsers
BASE_URL=https://your-deployment.example pnpm --filter web exec playwright test --project=chromium

The end-to-end suite starts next start on port 3100 unless BASE_URL is set. See TESTING.md for what each layer covers.

CI and the production check

CI (on every push to main and every pull request)

JobSteps
Typecheck, lint and unit tests
  • pnpm -r typecheck
  • pnpm --filter web lint
  • Law engine (100% branch coverage enforced)
  • Reader (normalizer, verifier, baselines, drafts)
  • MCP server (every tool through a real MCP client)
  • Web server routes (API validation, rate limits, /mcp)
  • Evaluation replays offline and matches eval/report.json
End-to-end and accessibility
  • pnpm --filter web build
  • pnpm --filter web exec playwright test
No secrets in the client bundle
  • pnpm --filter web build
  • Grep the build for key patterns

Production check (every 30 minutes)

.github/workflows/prod-check.yml runs every 30 minutes (*/30 * * * *) against the live site: every page must answer 200 (/, /sweep, /playground, /vs-chatbot, /results, /law, /story, /connect, /case/S01, /case/S01/application), /api/health must report "status":"ok", /mcp must list sweep_jail and answer a lookup_section call, and the security headers must be present. Point BASE at your own domain to reuse it.