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
- Clone and install.
git clone https://github.com/Prashant-thakur77/HalfTime cd HalfTime pnpm install
- Create a KV namespace for the rate-limit counters, the spend total and the response cache, and put its id in
apps/web/wrangler.jsoncunder the bindingCACHE.
cd apps/web npx wrangler kv namespace create CACHE
- In
wrangler.jsonc, set your own Workername, and change or removeroutes(it points at the hosted custom domain). - Build with OpenNext and deploy. These are the scripts in
apps/web/package.json:
| Script | Runs |
|---|---|
| pnpm cf:build | opennextjs-cloudflare build |
| pnpm cf:preview | opennextjs-cloudflare build && opennextjs-cloudflare preview |
| pnpm cf:deploy | opennextjs-cloudflare build && opennextjs-cloudflare deploy |
| pnpm cf-typegen | wrangler types --env-interface CloudflareEnv cloudflare-env.d.ts |
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
{
"$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 }]
}| Setting | Why |
|---|---|
| main, assets | The Worker and the static assets that OpenNext writes to .open-next/. |
| compatibility_flags | nodejs_compat for the Node APIs the server code uses; global_fetch_strictly_public so fetch() always goes out over the public internet. |
| kv_namespaces: CACHE | Rate-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_USD | The daily spend cap in US dollars for the model routes. The code defaults to 15 when it is unset. |
| observability | Workers logs. Error logs record only the error kind and status, never document text. |
| routes | The hosted custom domain. Change or remove it for your own deployment. |
Secrets and variables
| Name | Kind | Effect |
|---|---|---|
| ANTHROPIC_API_KEY | secret, optional | Turns on /api/extract, /api/baseline and /api/ocr. Without it they answer 503 and the rest of the site is unaffected. |
| DAILY_SPEND_CAP_USD | variable | Stops the model routes for the rest of the day once the recorded spend reaches it (503). |
| CACHE | KV binding | See above. |
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
pnpm --filter web dev # http://localhost:3000
next.config.tscallsinitOpenNextCloudflareForDev(), sogetCloudflareContext()works undernext dev. If no context is available, the server falls back toprocess.env.- To try the server-side model routes locally, export
ANTHROPIC_API_KEYin 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 exampleNEXT_DIST_DIR=.next-docs npx next buildandNEXT_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):
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
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)
| Job | Steps |
|---|---|
| Typecheck, lint and unit tests |
|
| End-to-end and accessibility |
|
| No secrets in the client bundle |
|
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.