caelum0x 45e59d6882 docs: SCR-DIR AGENTS.md says a new table reaches the REST API about 3 s after the SQL commits
Measured on a clean clone: 404 schema cache for 2.5 s after setup.sql, then 200.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-30 21:11:57 +03:00

99 lines
3.9 KiB
Markdown

# AGENTS.md
For a coding agent (Claude Code, Codex, Cursor, Windsurf or any other) working
in a clone of `cloudflare-worker-scribase-starter`. Do these steps in order. No person is needed until
step 4, and no account, password or email check is needed at all.
## 1. Install, then create the backend
```bash
npm install
npx scribase init --temp --yes --json
```
This creates a real Postgres project on [Scribase](https://scribase.com?ref=cloudflare-worker-scribase-starter)
with auth and a REST API, free for 72 hours, and prints one JSON object.
It takes about a minute. Check that `ok` is `true` and keep `api_url`,
`claim_url` and `deleted_at_utc`.
It writes `.env` with `SUPABASE_URL` and `SUPABASE_ANON_KEY`, the two values this
app reads, plus `SCRIBASE_ACCESS_TOKEN`, the token the next commands use.
`.env` is gitignored. Never commit it and never print the token.
## 2. Confirm the first request
`init` has already made it. Before it exits it reads the sample `todos` table
through the project's REST API with the public key and returns the result:
```json
"first_request": { "ok": true, "method": "GET", "status": 200, "row_count": 2 }
```
`first_request.ok: true` with rows means the backend answers real queries.
If it is `false`, run the curl in the first `next_steps` entry and read
`first_request.error`. Do not tell the human the backend works before this
is true.
## 3. Create this app's table and run the app
```bash
npx scribase sql --file supabase/setup.sql --json
```
Expect `"status":"committed"`. The file turns row level security on. Keep it
on: Scribase refuses a public table that has none.
The REST API sees a new table about 3 seconds after the SQL commits. If a
request answers that `notes` is not in the schema cache, wait 5 seconds and
try again. Do not create the table a second time.
```bash
grep '^SUPABASE_' .env > .dev.vars # wrangler reads .dev.vars for local dev
npm run dev
```
In a second terminal:
```bash
curl -X POST http://localhost:8787/notes -H 'content-type: application/json' -d '{"body":"hello from the edge"}'
curl http://localhost:8787/notes
```
The second call must return the note you just added. That is the check that
this Worker reads and writes the real table.
## 4. Hand the human the claim link
Give the human `claim_url` exactly as printed, the whole line including the
part after `#`. That part is the claim secret and the link does nothing
without it. Say these four things with it:
1. The project is temporary and is deleted at `deleted_at_utc` unless claimed.
2. Claiming is a sign-up: free for 14 days, no card, and one project stays
free after that.
3. The URL and keys stay the same, so nothing in `.env` changes.
4. After claiming, they should name a production approver (see below).
You cannot claim the project yourself and should not sign up for the human.
## Rules for changes after this
- New tables go through `npx scribase sql` or `npx scribase migrate`, always
with row level security and a policy.
- `npx scribase sql` runs a statement that removes data (`DROP`, `TRUNCATE`,
`DELETE` without `WHERE`) only with `--confirm`. Add it only when the human
asked for that exact change.
- On a claimed project with a production approver, a destructive change to
production from your token is answered with `202 approval_required`.
Nothing has run. Do not send it again and do not look for another way to
run it. Tell the human who the approver is (the `approver` field) and wait
on `status_url`; on approve, Scribase runs the stored request as sent.
- Do not ask for an admin token and do not try to set the approver. A token
that could name its own approver would approve itself.
- To deploy, the human needs their own Cloudflare account: `npx wrangler secret put SUPABASE_URL`,
`npx wrangler secret put SUPABASE_ANON_KEY`, `npm run deploy`. Do not copy
`SCRIBASE_ACCESS_TOKEN` into the Worker.
- `npx scribase doctor` prints one fix per problem if any step fails.
Docs: https://docs.scribase.com/docs/agents/prod-approver