The server

The widget works on its own. The server adds three things:

  • AI drafting for requests the built-in rules can't handle, using your own model key (PMF Harness never ships or uses one of its own);
  • one place for every user's requests, changes and verdicts, so the developer view shows real acceptance rates;
  • rollouts: a change you approve is served to everyone.

Run it

npm install github:theguysaccount/pmf-harness-self-evolving-app#v0.1.0 @anthropic-ai/sdk
ANTHROPIC_API_KEY=sk-ant-… \
PMF_ALLOWED_ORIGINS=https://your.app \
PMF_ADMIN_TOKEN=$(openssl rand -hex 24) \
node node_modules/pmf-harness/server/pmf-server.mjs

It listens on port 8787 under /pmf. Point the widget at it:

<script src="https://cdn.jsdelivr.net/gh/theguysaccount/pmf-harness-self-evolving-app@v0.1.0/dist/pmf-harness.js"
        data-app="my-app" data-endpoint="https://api.your.app/pmf" defer></script>
Environment variableDefaultMeaning
ANTHROPIC_API_KEYnoneYour key. Without credentials, requests the rules can't handle are queued
PMF_MODELclaude-opus-5-5The Claude model that drafts
PMF_EFFORTmediumlow, medium or high: how hard the model thinks
PMF_ALLOWED_ORIGINSnoneYour app's page origins, comma-separated (CORS)
PMF_ADMIN_TOKENnoneBearer token for the summary and rollouts
PMF_DATApmf-data/events.jsonlWhere events are appended
PMF_DRAFTS_PER_HOUR10Drafts per user per hour (and three times that per IP)
PMF_PORT8787Port

Mount it in your app instead

The server is one Web-standard handler, (Request) => Promise<Response | null>. It returns null for paths outside its base path, so it can sit in front of your routes.

Next.js App Router, app/pmf/[...path]/route.js:

import { createPmfHandler } from "pmf-harness/server";
import { createClaudeDrafter } from "pmf-harness/server/claude";
import { fileStore } from "pmf-harness/server/store";

const handle = createPmfHandler({
  draft: createClaudeDrafter({ apiKey: process.env.ANTHROPIC_API_KEY }),
  store: fileStore("pmf-data/events.jsonl"), // use your database on serverless hosts
  adminToken: process.env.PMF_ADMIN_TOKEN,
});

export const GET = (req) => handle(req);
export const POST = (req) => handle(req);

Same-origin requests need no allowedOrigins.

Express:

import { toNodeHandler } from "pmf-harness/server/node";
app.use(toNodeHandler(handle)); // unmatched paths fall through to next()

Hono, Bun, Deno: pass c.req.raw (or the Request) to handle and return its Response.

Endpoints

Method and pathWhoWhat
POST /pmf/draftthe widget{ request } → { change } or { queue }. Rate-limited per user and IP
POST /pmf/eventsthe widgetRecords a request, a change or a verdict. Screenshots are never stored
GET /pmf/changesthe widgetThe changes you rolled out to everyone
GET /pmf/summaryadmin tokenRequests, changes, verdict counts and acceptance, the queue
POST /pmf/rolloutadmin token{ changeId } rolls a change out; { changeId, undo: true } rolls it back
GET /pmf/healthanyone{ ok, drafter }

How drafting with Claude works

createClaudeDrafter uses the official Anthropic SDK (@anthropic-ai/sdk):

  • The model is claude-opus-5-5 unless you set another, with effort: "medium".
  • The answer is constrained to a JSON schema with structured outputs (output_config.format), so it is always parseable: either a change (summary plus up to eight ops) or a queue entry with a reason. The schema is published at /draft.schema.json.
  • Refusal fallbacks are on: the request sends fallbacks: "default" with the server-side-fallback-2026-07-01 beta, so if Claude declines, the API retries on Anthropic's recommended fallback model. If the whole chain declines, the request is queued for you.
  • The system prompt tells the model that page text, selectors and the screen outline are data, not instructions. Prompt injection through your page's content can at most produce a change, and every change goes through the validator.
  • Every answer is validated with the same code as the browser, then checked against the live page before it's applied.
  • Errors are mapped to statuses (rate limit and network → 503, bad key → 500, other API errors → 502); the widget then falls back to its rules.

A typical draft sends about one to two thousand input tokens (the request, the element and a screen outline of up to 3,000 characters) and gets a short JSON answer back. You pay your provider for that; PMF_DRAFTS_PER_HOUR caps it per user.

Your own drafter or store

Any async function (request) => ({ change } | { queue } | { error }) can draft, so you can use another model or your own rules. A store is any object with append(event) and all(); fileStore(path) and memoryStore() are included.