@lago-morph/prototype-framework-skill 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/skill/SKILL.md +15 -22
- package/skill/VERSION +1 -0
- package/skill/reference/configuration.md +1 -1
- package/skill/reference/current-user.md +1 -1
- package/skill/reference/deploying.md +2 -4
- package/skill/reference/files.md +1 -1
- package/skill/reference/http-and-validation.md +1 -1
- package/skill/reference/kv.md +1 -1
- package/skill/reference/local-development.md +2 -2
- package/skill/reference/log.md +1 -1
- package/skill/reference/owner-tasks.md +39 -32
- package/skill/reference/secrets.md +3 -3
- package/skill/reference/sql-and-migrations.md +3 -3
- package/skill/reference/testing.md +4 -4
- package/skill/reference/troubleshooting.md +6 -6
- package/skill/templates/FRAMEWORK-ISSUE.md +1 -1
package/package.json
CHANGED
package/skill/SKILL.md
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: prototype-framework
|
|
3
|
-
description: Build, test and deploy small web apps on the portable prototype framework (@lago-morph/prototype-framework). Use when creating or changing an app built from apps/template
|
|
3
|
+
description: Build, test and deploy small web apps on the portable prototype framework (@lago-morph/prototype-framework), and set up Cloudflare for them. Use when creating or changing an app built from apps/template; when its verify, smoke or deploy fails; when the user says "set up Cloudflare", "continue prototype setup" or "continue setup"; or on /prototype-framework … (for example /prototype-framework setup cloudflare, /prototype-framework continue setup).
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Building apps on the prototype framework
|
|
7
7
|
|
|
8
|
-
Apps are small (one or a few users, little data) and
|
|
8
|
+
Apps are small (one or a few users, little data) and run unchanged locally and on Cloudflare. The framework gives each request handler SQL, KV, files, configuration, secrets, a log and the current user; app code never sees which cloud it runs on. Package: `@lago-morph/prototype-framework` (server code), `/client` (browser code), `/testing` (tests). Commands: `npm run <command>` (flags after `--`), or `npm exec --no -- prototype-framework <command>`; never plain `npx`, which fetches a stranger's package of that name when the app is not installed.
|
|
9
|
+
|
|
10
|
+
**First step of every session:** run `npm run version-check`. It changes nothing; relay its suggestions as it prints them, and its "newer npm release" one only once per session. If the app is not installed yet (no `node_modules`), skip the check until `npm install` has run. Then run the git checks of [Cloudflare setup](#cloudflare-setup).
|
|
9
11
|
|
|
10
12
|
Read this page, then only the references your task needs (task map below).
|
|
11
13
|
|
|
@@ -13,7 +15,7 @@ Read this page, then only the references your task needs (task map below).
|
|
|
13
15
|
|
|
14
16
|
1. **Use only the framework's public exports**: `@lago-morph/prototype-framework` in server code, `/client` in browser code, `/testing` in tests, plus `hono` and `zod`. No platform SDKs, database drivers, Node built-ins or other framework subpaths.
|
|
15
17
|
2. **Never insert user text as HTML.** Build elements and set `textContent`; no `innerHTML` or other raw-HTML sinks.
|
|
16
|
-
3. **Pass `
|
|
18
|
+
3. **Pass `npm run verify` before declaring any work done.** Never disable, suppress or weaken a check (`eslint-disable`, `@ts-ignore`, `any`, `as` casts, editing lint configuration).
|
|
17
19
|
4. **Claim an app works on a cloud only after its smoke test has passed on a deployed stage there** (`smoke --target <t> --stage test-…`). Local success says nothing about a cloud.
|
|
18
20
|
5. **Never change framework version pins**: the exact versions of `@lago-morph/prototype-framework`, `hono`, `zod`, `typescript`, `vite` and `vitest` in the app's `package.json`.
|
|
19
21
|
6. **Never work around the framework.** If you suspect a framework defect (a contract or reference that does not hold, a check that rejects code the references allow, a capability that is missing for the task), add an entry to `FRAMEWORK-ISSUE.md` at the app's root instead of patching, copying or bypassing framework code. Each entry states:
|
|
@@ -25,7 +27,14 @@ Read this page, then only the references your task needs (task map below).
|
|
|
25
27
|
|
|
26
28
|
Use [templates/FRAMEWORK-ISSUE.md](templates/FRAMEWORK-ISSUE.md).
|
|
27
29
|
7. **After recording an entry**, stop work on the blocked requirement; continue only work that does not depend on it; report the issue and the list of unfinished requirements to the user; and do not declare the app done.
|
|
28
|
-
8. **A
|
|
30
|
+
8. **A cloud run that cannot go ahead is not a framework issue** (Cloudflare not set up yet, a run paused, a quota used up). Do not add a `FRAMEWORK-ISSUE.md` entry for it; in your build record, list each check that needs it as `blocked` with the reason.
|
|
31
|
+
|
|
32
|
+
## Cloudflare setup
|
|
33
|
+
|
|
34
|
+
On "set up Cloudflare", "continue prototype setup" or "continue setup", run `npm run cloudflare-setup` and relay its output as is: links, template and next prompt unchanged. It does only what is missing, so run it again whenever asked. Exit status 1 with a message is a stop for the user, not a failure to work around. What to do when it stops: [owner-tasks.md](reference/owner-tasks.md) §2.
|
|
35
|
+
|
|
36
|
+
- **Never open, print or search `.env.cloudflare`**, and never echo `CLOUDFLARE_API_TOKEN` or `CLOUDFLARE_BOOTSTRAP_TOKEN`. The CLI reads them itself. Never ask for a token in the chat.
|
|
37
|
+
- **Git checks**, when a session starts work on the app and before every commit or push: `git check-ignore -q .env.cloudflare` and `git ls-files --error-unmatch .env.cloudflare`. Each time the file is not ignored (the first exits non-zero) or is tracked (the second exits 0), remind the user and point to [owner-tasks.md](reference/owner-tasks.md) §2. Never refuse to commit because of it.
|
|
29
38
|
|
|
30
39
|
## Task map
|
|
31
40
|
|
|
@@ -43,26 +52,10 @@ Read this page, then only the references your task needs (task map below).
|
|
|
43
52
|
| Test (in-process, time-dependent, smoke) | [testing.md](reference/testing.md) |
|
|
44
53
|
| Deploy, run the smoke test on a cloud, remove a stage | [deploying.md](reference/deploying.md) |
|
|
45
54
|
| Diagnose a failing request or deploy; a `verify` diagnostic | [troubleshooting.md](reference/troubleshooting.md), and the reference the diagnostic names |
|
|
46
|
-
|
|
|
55
|
+
| Set up Cloudflare; steps the owner performs (tokens and email domain, secrets, sign-up and sign-in, admins, deploy and remove, logs) | [owner-tasks.md](reference/owner-tasks.md) |
|
|
47
56
|
|
|
48
57
|
Every `verify` diagnostic ends with `(read skill/reference/<file>.md)`; that file has a "Check rules that send you here" section for the rule.
|
|
49
58
|
|
|
50
|
-
## References
|
|
51
|
-
|
|
52
|
-
- [http-and-validation.md](reference/http-and-validation.md): routes, guards, validation, error codes, browser calls, HTML safety.
|
|
53
|
-
- [sql-and-migrations.md](reference/sql-and-migrations.md): tables, the portable query subset, `atomic`, migrations.
|
|
54
|
-
- [kv.md](reference/kv.md): key-value storage.
|
|
55
|
-
- [files.md](reference/files.md): tickets, the safe upload pattern, downloads.
|
|
56
|
-
- [secrets.md](reference/secrets.md): declaring, reading and setting secrets; HMAC signing.
|
|
57
|
-
- [configuration.md](reference/configuration.md): config keys and per-stage values files.
|
|
58
|
-
- [current-user.md](reference/current-user.md): levels, the admin role, login, login tests.
|
|
59
|
-
- [log.md](reference/log.md): writing entries and where they go.
|
|
60
|
-
- [local-development.md](reference/local-development.md): scaffolding, `dev`, local state.
|
|
61
|
-
- [testing.md](reference/testing.md): `createTestApp`, fake timers, the smoke test.
|
|
62
|
-
- [deploying.md](reference/deploying.md): stages, deploy, smoke, remove.
|
|
63
|
-
- [troubleshooting.md](reference/troubleshooting.md): finding log entries, error codes, login failures.
|
|
64
|
-
- [owner-tasks.md](reference/owner-tasks.md): the owner's copy-and-paste steps.
|
|
65
|
-
|
|
66
59
|
## Examples and templates
|
|
67
60
|
|
|
68
61
|
Examples are whole files copied unchanged from the framework's template and compliance reference app, which CI type-checks and tests: [endpoint-and-page](examples/endpoint-and-page.md), [notes-sql](examples/notes-sql.md), [status-kv](examples/status-kv.md), [files-tickets](examples/files-tickets.md), [admin-and-current-user](examples/admin-and-current-user.md), [secrets](examples/secrets.md), [configuration](examples/configuration.md), [tests](examples/tests.md). Start from the template, not from any other app.
|
|
@@ -71,4 +64,4 @@ A new app starts from the template: `npm create @lago-morph/prototype-app@latest
|
|
|
71
64
|
|
|
72
65
|
## Done means
|
|
73
66
|
|
|
74
|
-
`
|
|
67
|
+
`npm run verify` passes; every requirement is implemented and tested; for each cloud you claim, the smoke test passed on a deployed test stage there; and `FRAMEWORK-ISSUE.md` has no open entry blocking a requirement. Cloud runs that could not go ahead are listed as unfinished (`not-run` or `blocked`, hard rule 8), not raised as issues.
|
package/skill/VERSION
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.1.1
|
|
@@ -59,4 +59,4 @@ App code reads configuration only through `c.var.config`. Never read `process.en
|
|
|
59
59
|
|
|
60
60
|
## Stopping condition
|
|
61
61
|
|
|
62
|
-
Stop reading when each setting is declared with a type, read through `c.var.config.get`, given values in each stage's committed file (or a default), and `
|
|
62
|
+
Stop reading when each setting is declared with a type, read through `c.var.config.get`, given values in each stage's committed file (or a default), and `npm run verify` passes.
|
|
@@ -62,4 +62,4 @@ The mock chooses the level directly: it reads no roles.
|
|
|
62
62
|
|
|
63
63
|
## Stopping condition
|
|
64
64
|
|
|
65
|
-
Stop reading when every private route has a guard and filters by `c.var.user.id`, admin routes use `requireAdmin()`, the stage's values file has the lists the owner wants, your tests cover anonymous, user and admin callers, and `
|
|
65
|
+
Stop reading when every private route has a guard and filters by `c.var.user.id`, admin routes use `requireAdmin()`, the stage's values file has the lists the owner wants, your tests cover anonymous, user and admin callers, and `npm run verify` passes.
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
# Deploying
|
|
2
2
|
|
|
3
|
-
Read this when you deploy, smoke-test, stop, start or remove a stage on a cloud.
|
|
3
|
+
Read this when you deploy, smoke-test, stop, start or remove a stage on a cloud. Cloudflare setup (the tokens and the email domain), secrets, sign-up and admins are in [owner-tasks.md](owner-tasks.md).
|
|
4
4
|
|
|
5
|
-
Commands run in the app's directory,
|
|
6
|
-
|
|
7
|
-
**Status in this phase:** every command on this page is **not yet verified on Cloudflare in this phase**. The framework's cloud commands have run only against a simulated Cloudflare. Only the Cloudflare API call that `stop` and `start` use (§4) was tried on a real Worker. AWS is a future release: this release deploys to Cloudflare only.
|
|
5
|
+
Commands run in the app's directory, after `npm run cloudflare-setup` has said everything is set up ([owner-tasks.md](owner-tasks.md) §2); each reads the tokens itself, from the environment or `.env.cloudflare`. Each `npm run <command> -- …` is the same as `npm exec --no -- prototype-framework <command> …`. Behind an HTTPS proxy, put `NODE_USE_ENV_PROXY=1 ` in front of every cloud command; the command says so if it is needed.
|
|
8
6
|
|
|
9
7
|
## 1. Test stages and production stages
|
|
10
8
|
|
package/skill/reference/files.md
CHANGED
|
@@ -62,4 +62,4 @@ The ticket is the same JSON on every target: `{ url, method?, headers?, expiresA
|
|
|
62
62
|
|
|
63
63
|
## Stopping condition
|
|
64
64
|
|
|
65
|
-
Stop reading when your server builds every file name itself, authorizes from your records, issues tickets with explicit content types, checks uploads with `head` before making them visible, serves content only through `downloadUrl`, and `
|
|
65
|
+
Stop reading when your server builds every file name itself, authorizes from your records, issues tickets with explicit content types, checks uploads with `head` before making them visible, serves content only through `downloadUrl`, and `npm run verify` passes.
|
|
@@ -88,4 +88,4 @@ API responses are never cached (`Cache-Control: no-store`); you need not set cac
|
|
|
88
88
|
|
|
89
89
|
## Stopping condition
|
|
90
90
|
|
|
91
|
-
Stop reading when your route has a guard (or is deliberately open), validates its input, throws only the four codes above, returns a shared type, has a test, and `
|
|
91
|
+
Stop reading when your route has a guard (or is deliberately open), validates its input, throws only the four codes above, returns a shared type, has a test, and `npm run verify` passes. For storage inside the route, read only the reference for that capability.
|
package/skill/reference/kv.md
CHANGED
|
@@ -38,4 +38,4 @@ KV behaves identically on every target; you never see where it is stored.
|
|
|
38
38
|
|
|
39
39
|
## Stopping condition
|
|
40
40
|
|
|
41
|
-
Stop reading when every key your code builds has a fixed prefix plus trusted IDs, values stay under 4,096 bytes, `list` callers pass the cursor back with the same prefix, and `
|
|
41
|
+
Stop reading when every key your code builds has a fixed prefix plus trusted IDs, values stay under 4,096 bytes, `list` callers pass the cursor back with the same prefix, and `npm run verify` passes.
|
|
@@ -32,7 +32,7 @@ Then:
|
|
|
32
32
|
|
|
33
33
|
## Commands
|
|
34
34
|
|
|
35
|
-
Run them in the app directory, as `npm run <command>` or `
|
|
35
|
+
Run them in the app directory, as `npm run <command>` (flags after `--`) or `npm exec --no -- prototype-framework <command>` (never plain `npx`: before `npm install` it would fetch an unrelated package of that name from the registry):
|
|
36
36
|
|
|
37
37
|
| Command | Does |
|
|
38
38
|
| --- | --- |
|
|
@@ -70,4 +70,4 @@ Run them in the app directory, as `npm run <command>` or `npx prototype-framewor
|
|
|
70
70
|
|
|
71
71
|
## Stopping condition
|
|
72
72
|
|
|
73
|
-
Stop reading when `npm run dev` serves your app at `http://localhost:<port>/`, you can log in with the mock, and `
|
|
73
|
+
Stop reading when `npm run dev` serves your app at `http://localhost:<port>/`, you can log in with the mock, and `npm run verify` passes. For deploying to a cloud, read [deploying.md](deploying.md).
|
package/skill/reference/log.md
CHANGED
|
@@ -51,4 +51,4 @@ On a connected test stage (`connectTestStage`) `logs()` throws: entries are in t
|
|
|
51
51
|
|
|
52
52
|
## Stopping condition
|
|
53
53
|
|
|
54
|
-
Stop reading when your code logs what only it knows, without secrets or personal data, does not duplicate the framework's error entries, your error displays show the request ID, and `
|
|
54
|
+
Stop reading when your code logs what only it knows, without secrets or personal data, does not duplicate the framework's error entries, your error displays show the request ID, and `npm run verify` passes.
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
# Owner tasks
|
|
2
2
|
|
|
3
|
-
Read this when the app's owner (or an agent acting for them) must do something outside the code: set up
|
|
3
|
+
Read this when the app's owner (or an agent acting for them) must do something outside the code: set up Cloudflare (its two tokens and the email domain), set secrets, create a production stage, sign up and sign in, make someone an admin, or keep costs down. Give the owner these steps as written. The owner does not read code.
|
|
4
4
|
|
|
5
5
|
Commands run in a terminal, in the app's directory, on macOS or Linux with Node 22.22.0. Replace `<…>` parts; `<domain>` is the account's email domain. Never paste a secret value into a command line, a file in the repository, or a chat.
|
|
6
6
|
|
|
7
|
-
**Status in this phase.** The local steps are verified. The Cloudflare steps have run against a simulated Cloudflare, and the email setup once against the real account; treat the rest as **not yet verified on Cloudflare**. If a step fails, follow [troubleshooting.md](troubleshooting.md).
|
|
8
|
-
|
|
9
7
|
## 1. Before anything else (once per checkout)
|
|
10
8
|
|
|
11
9
|
In this repository the framework is built from source. Run this at the repository root. The last line goes back to the app's directory (here the template's), where every later command runs:
|
|
@@ -16,7 +14,7 @@ npm run build -w packages/framework
|
|
|
16
14
|
cd apps/template
|
|
17
15
|
```
|
|
18
16
|
|
|
19
|
-
An app made with
|
|
17
|
+
An app made with `npm create` is already installed.
|
|
20
18
|
|
|
21
19
|
Set the stage's name in `STAGE` once in each new terminal (`<stage>` is for example `test-abc` or `prod`):
|
|
22
20
|
|
|
@@ -24,36 +22,46 @@ Set the stage's name in `STAGE` once in each new terminal (`<stage>` is for exam
|
|
|
24
22
|
STAGE='<stage>'
|
|
25
23
|
```
|
|
26
24
|
|
|
27
|
-
## 2. Cloudflare
|
|
25
|
+
## 2. Cloudflare: two links and one command
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
2. Copy your **Account ID** from the account's overview page (menu names here are not yet verified).
|
|
31
|
-
3. Create two **account API tokens**: Manage Account → Account API Tokens → Create Token → Create Custom Token. Account resources: this account only; zone resources: the email domain's zone. Copy each token when shown; Cloudflare shows it only once.
|
|
32
|
-
- **Everyday token** `prototype-framework`, for every command but `setup-account`, including `stop`, `start` and the backup a production `remove` writes. Account: Workers Scripts Edit, Workers R2 Storage Edit, D1 Edit, Email Sending Read. Zone: Zone Read, Analytics Read. It cannot create tokens. It needs no Billing permission: if Cloudflare refuses a new database because the account has too many, the message names both plans' limits (put `PROTOTYPE_FRAMEWORK_CLOUDFLARE_PLAN=free` or `=paid` in front of the command to name yours).
|
|
33
|
-
- **Setup token** `prototype-framework-setup`, for `setup-account` only (§3), used rarely. Account: Workers Scripts Edit, Workers R2 Storage Edit, Account API Tokens Edit, Email Sending Edit, Email Routing Addresses Edit. Zone: Email Routing Rules Edit, DNS Edit, Zone Settings Edit, Zone Read. Store it apart from the everyday token.
|
|
27
|
+
You need a Cloudflare account on the **Workers Paid** plan (sign-in sends email, which needs it), and a **domain on that account with Cloudflare DNS active** (Websites → Add a site). Its mail can stay where it is.
|
|
34
28
|
|
|
35
|
-
|
|
36
|
-
4. In each new terminal, set both values; paste the everyday token when `read` waits, then press Enter (`read` keeps it out of your shell history):
|
|
37
|
-
```sh
|
|
38
|
-
export CLOUDFLARE_ACCOUNT_ID='<your Account ID>'
|
|
39
|
-
read -rs CLOUDFLARE_API_TOKEN && export CLOUDFLARE_API_TOKEN
|
|
40
|
-
```
|
|
41
|
-
5. Check the token. The output must contain `"success":true`:
|
|
29
|
+
1. Run the setup. It prints no token value and does only what is missing:
|
|
42
30
|
```sh
|
|
43
|
-
|
|
31
|
+
npm run cloudflare-setup
|
|
44
32
|
```
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
33
|
+
With no tokens yet, it prints two links, a template, where the values go, and the next prompt.
|
|
34
|
+
2. Open each link while logged in to the dashboard. The permissions and name are filled in. Pick your account if asked and keep the email domain's zone included; for the bootstrap token, under TTL set an end date 7 days away or sooner (PAR-380). Then Continue to summary, Create Token, and copy it: Cloudflare shows it only once.
|
|
35
|
+
- **Everyday token** `prototype-framework` (7 permissions), kept for every command. It cannot create tokens and has no zone write permission.
|
|
36
|
+
- **Bootstrap token** `prototype-framework-bootstrap` (12 permissions), used once: setup deletes it when done.
|
|
37
|
+
|
|
38
|
+
Both permission lists are in the framework repository's [QUICKSTART.md](https://github.com/lago-morph/cloud-app/blob/main/QUICKSTART.md). Setup names any permission a token lacks.
|
|
39
|
+
3. Put the values where setup reads them, in the four lines of the template (`CLOUDFLARE_BOOTSTRAP_TOKEN`, `CLOUDFLARE_API_TOKEN`, `CLOUDFLARE_EMAIL_DOMAIN`, and `CLOUDFLARE_ACCOUNT_ID` only if your tokens see more than one account):
|
|
40
|
+
- **In a Claude Code cloud session:** the environment's settings (environment menu → Edit → Environment variables), then start a new session.
|
|
41
|
+
- **On your computer:** the file `.env.cloudflare` in the app's folder (setup writes the template there; git ignores it), in your editor; or the environment. The environment wins when both are set.
|
|
42
|
+
4. Run `npm run cloudflare-setup` again (in Claude Code, say **"continue prototype setup"**), until it says everything is set up. On success it deletes the bootstrap token, comments out its line, and fills in an empty account and email domain: copy `.env.cloudflare` into another app's folder to start that one. In a cloud session you may then remove the bootstrap variable.
|
|
43
|
+
|
|
44
|
+
**When setup stops** (exit status 1), it says what is missing with the link or command to use. Do that, then run it again; it exits 0 only when all is set up:
|
|
45
|
+
|
|
46
|
+
| It says | Do this |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| two tokens are needed (no everyday token) | steps 2–4 |
|
|
49
|
+
| a setting's token is not accepted, not active, the same in both settings, of another account, or lacks a permission | make it again from the link it prints; replace its line |
|
|
50
|
+
| the bootstrap token cannot read API tokens ("was the everyday token pasted there?"), or is a user token | make it from the bootstrap link (an account token) |
|
|
51
|
+
| several accounts, by name | copy the chosen account's ID from the dashboard into `CLOUDFLARE_ACCOUNT_ID` |
|
|
52
|
+
| which domain should the emails come from | set `CLOUDFLARE_EMAIL_DOMAIN`, or run `npm run cloudflare-setup -- --email-domain <domain>`; with no domain, add one |
|
|
53
|
+
| the plan is Workers Free | upgrade it (Workers & Pages → Plans) |
|
|
54
|
+
| this needs the bootstrap token once (with the reasons) | make it from the link and set `CLOUDFLARE_BOOTSTRAP_TOKEN`; the everyday token keeps its value |
|
|
55
|
+
| the everyday token must be made again (wrong zone or account, a denied permission) | make it from the everyday link; setup kept the bootstrap token to check it |
|
|
56
|
+
| the tokens belong to another account than this project's | remove the old account's stages first if you want, with its everyday token, then `npm run cloudflare-setup -- --switch-account` |
|
|
57
|
+
| a host is blocked | allow `api.cloudflare.com`, `*.r2.cloudflarestorage.com` and `*.workers.dev` in the environment's network access settings |
|
|
58
|
+
| `.env.cloudflare` is not ignored, or is tracked | setup adds the `.gitignore` line unless it holds `# keep-env-cloudflare-tracked`. Tracked: delete both tokens, `git rm --cached .env.cloudflare`, commit, make new ones |
|
|
59
|
+
|
|
60
|
+
The git warnings never stop a command. Setup never updates or deletes a token whose ID is in `PROTOTYPE_FRAMEWORK_PROTECTED_TOKEN_IDS` (comma-separated). `npm run setup-account -- --target cloudflare --email-domain <domain>` is the account-setup step alone, for scripts.
|
|
61
|
+
|
|
62
|
+
## 3. What the account setup creates
|
|
63
|
+
|
|
64
|
+
Setup creates the shared resources once per account, including the file-signing credential every stage uses: the log bucket `prototype-logs`, the deploy-state bucket `sst-state`, the backup bucket `prototype-backups` (a removed production stage's data, kept 30 days), the `workers.dev` address, sending from `no-reply@<domain>`, and the test mailbox: mail to `sink+<tag>@t.<domain>` is stored for a day, so an agent can read it. It records what it did in `framework/account.json` in `sst-state`. When it creates the mailbox rule it waits about a minute. To change the domain, set the new `CLOUDFLARE_EMAIL_DOMAIN` and run it again (it needs the bootstrap token). `deploy` never creates these resources; if they are missing, it says to run the setup. When a run replaces the file-signing credential, it says so: then redeploy every deployed stage (`npm run deploy -- --target cloudflare --stage <stage>`), because each one keeps the old key, and its file uploads and downloads fail, until its next deploy.
|
|
57
65
|
|
|
58
66
|
## 4. Secrets
|
|
59
67
|
|
|
@@ -133,12 +141,11 @@ It prints the account's user ID (as `/api/auth/me` shows it) and its roles, neve
|
|
|
133
141
|
|
|
134
142
|
## 8. Checking the real login (optional)
|
|
135
143
|
|
|
136
|
-
`npm run check-login -- --target cloudflare --stage "$STAGE"`
|
|
144
|
+
`npm run check-login -- --target cloudflare --stage "$STAGE"` checks sign-up with real mail, sign-in, the admin grant, a password reset and the rate limit on a production stage. It needs no input, prints no address or password, writes an evidence record under `validation/`, and leaves one test account (no role).
|
|
137
145
|
|
|
138
146
|
## 9. Cost
|
|
139
147
|
|
|
140
148
|
- Stopped or idle stages cost nothing for compute, but storage remains: the stage's D1 database and R2 file bucket, the shared `prototype-logs` bucket, and the `sst-state` bucket. Log entries are never deleted automatically. Test mail in the sink is deleted after a day.
|
|
141
|
-
- On Cloudflare's free plan, D1 allows about **100,000 rows written per day** per account. The limit for reads is larger. When a limit is used up, database requests fail until it resets at 00:00 UTC.
|
|
142
149
|
- Keep test stages small: a few rows of data, one test stage at a time, and `remove` it right after use. An account holds at most **10 D1 databases**, and a deploy that changes the schema briefly uses two per stage.
|
|
143
150
|
- See [deploying.md](deploying.md) for deploy, stop/start and remove.
|
|
144
151
|
|
|
@@ -14,8 +14,8 @@ Values are not cached across requests (a value is reused only within one request
|
|
|
14
14
|
|
|
15
15
|
A secret's value is read from standard input, never from a command-line argument or a file in the repository.
|
|
16
16
|
|
|
17
|
-
- Local development: `printf '%s' 'the-value' |
|
|
18
|
-
- A cloud stage: `
|
|
17
|
+
- Local development: `printf '%s' 'the-value' | npm run secrets -- set apiKey --target local --stage local`. It writes the git-ignored `.dev.vars` file and prints the name and location, never the value. `dev` also generates the framework's own local keys there on first start.
|
|
18
|
+
- A cloud stage: `npm run secrets -- set apiKey --target cloudflare --stage <stage>`, then type or paste the value and end input. On Cloudflare the stage's Worker must exist, so on a stage's first deploy `deploy` stops, names each unset secret, and asks you to set them and deploy again.
|
|
19
19
|
- The owner's copy-and-paste steps for this are in [owner-tasks.md](owner-tasks.md).
|
|
20
20
|
|
|
21
21
|
A deploy's health check fails when any declared secret has no value, so a secret the app declares must be set on every stage it is deployed to.
|
|
@@ -39,4 +39,4 @@ For a signed token such as a share link, copy the template's `src/server/signing
|
|
|
39
39
|
|
|
40
40
|
## Stopping condition
|
|
41
41
|
|
|
42
|
-
Stop reading when every secret is declared in `secrets`, read only through `c.var.secrets.get`, never returned or logged, set on each stage with `secrets set`, given a value in tests, and `
|
|
42
|
+
Stop reading when every secret is declared in `secrets`, read only through `c.var.secrets.get`, never returned or logged, set on each stage with `secrets set`, given a value in tests, and `npm run verify` passes.
|
|
@@ -65,9 +65,9 @@ Build every write on the step's own `w`, never on `c.var.sql`; do not `await` in
|
|
|
65
65
|
## Migrations
|
|
66
66
|
|
|
67
67
|
1. Change the tables in `src/server/schema.ts`.
|
|
68
|
-
2. Run `npm run generate-migration` (or `
|
|
68
|
+
2. Run `npm run generate-migration` (or `npm run generate-migration -- --name <slug>`). It writes a pair of files, `migrations/sqlite/<nnnn>_<slug>.sql` and `migrations/postgres/<nnnn>_<slug>.sql`, plus snapshots under `meta/`, and records their checksums in `migrations/checksums.json`.
|
|
69
69
|
3. Commit all of them. Never edit a generated file. A migration that was never deployed to any cloud stage may be deleted (both files, their `meta/` snapshots) and generated again.
|
|
70
|
-
4. `
|
|
70
|
+
4. `npm run verify` checks both histories give the same schema and that only supported changes are used.
|
|
71
71
|
|
|
72
72
|
Supported changes: add a table; add a column that is nullable or has a static default; drop a column; drop a table; add or drop an index or a unique constraint.
|
|
73
73
|
|
|
@@ -101,4 +101,4 @@ Locally, `dev` and `createTestApp` apply pending migrations. On a cloud, `deploy
|
|
|
101
101
|
|
|
102
102
|
## Stopping condition
|
|
103
103
|
|
|
104
|
-
Stop reading when your tables use only the helpers above, your queries use only the allowed column, a migration pair has been generated and committed for every schema change, and `
|
|
104
|
+
Stop reading when your tables use only the helpers above, your queries use only the allowed column, a migration pair has been generated and committed for every schema change, and `npm run verify` passes on both dialects.
|
|
@@ -4,8 +4,8 @@ Read this when you write or fix app tests, write the smoke test, test time-depen
|
|
|
4
4
|
|
|
5
5
|
## What runs your tests
|
|
6
6
|
|
|
7
|
-
- `
|
|
8
|
-
- `
|
|
7
|
+
- `npm run verify` runs every `tests/**/*.test.ts` file (PAR-116) with Vitest twice, once on SQLite and once on Postgres, each in its own process, with 60 s test and hook timeouts. It fails if any test fails or if no test passed. Tests must need no network.
|
|
8
|
+
- `npm run smoke -- --target <t> --stage <s>` runs only `tests/smoke/**/*.test.ts`, against the running `dev` server (`--target local`) or against a deployed **test** stage (a stage whose name starts with `test-`). It refuses to run when tracked files differ from the last commit (the evidence record names the commit), writes an evidence record to `validation/<target>/<runId>.json` at the top of the git repository that holds the app (the app directory when the app is its own repository; commit the record with the run's commit), and prints the stage's log location for the day.
|
|
9
9
|
- An app is not done on a cloud until its smoke test has passed on a deployed stage there.
|
|
10
10
|
- Your tests and your smoke test reach the app only through its API; behaviour that exists only in the page (how text renders, the clipboard, an image displaying) is checked by the framework's browser tests, not the app's, so keep page text to `textContent` (`no-raw-html`), test the API side, and do not add a browser driver or raise this as a framework issue.
|
|
11
11
|
|
|
@@ -38,7 +38,7 @@ Keep it short: the health route (`GET /api/__framework/health` answers 204), one
|
|
|
38
38
|
|
|
39
39
|
`t.request` sends only to the app: a URL on any other origin is refused before anything is sent, on both test apps, so the stage's session cookie never leaves the stage. An upload or download ticket a route returns is JSON `{ url, method?, headers?, expiresAt }` on every target. Locally and in-process its `url` is a path on the app, sent with `t.request(url, { method, headers, body })`; on a cloud it is an absolute signed storage URL, sent with plain `fetch(url, { method: ticket.method ?? "GET", headers: ticket.headers, body })` and no cookie. Choose with `/^\/(?![\/\\])/.test(ticket.url) ? t.request(…) : fetch(…)`, so `//host` and `/\host` URLs go to `fetch` too. Behind a proxy, `smoke` needs `NODE_USE_ENV_PROXY=1` for that `fetch`.
|
|
40
40
|
|
|
41
|
-
To run it on a cloud, deploy a test stage first, for example `
|
|
41
|
+
To run it on a cloud, deploy a test stage first, for example `npm run deploy -- --target cloudflare --stage test-1`, then `npm run smoke -- --target cloudflare --stage test-1`, and remove the stage afterwards ([deploying.md](deploying.md)). Test stages use `config/<target>/test.json` and the authentication mock and hold no real data.
|
|
42
42
|
|
|
43
43
|
## Failures
|
|
44
44
|
|
|
@@ -52,4 +52,4 @@ To run it on a cloud, deploy a test stage first, for example `npx prototype-fram
|
|
|
52
52
|
|
|
53
53
|
## Stopping condition
|
|
54
54
|
|
|
55
|
-
Stop reading when each route has tests for success, access level, invalid input and other users' data, the smoke test covers each capability you use, and `
|
|
55
|
+
Stop reading when each route has tests for success, access level, invalid input and other users' data, the smoke test covers each capability you use, and `npm run verify` passes on both dialects. For deploying and running the smoke test on a cloud, read [deploying.md](deploying.md).
|
|
@@ -35,7 +35,7 @@ The date and time are UTC. `smoke` prints today's prefix.
|
|
|
35
35
|
|
|
36
36
|
**Dashboard (no setup; these menu names are not yet verified).** Open Storage & databases → R2 → `prototype-logs`. Then open the folders `<app>` / `<stage>` / year / month / day. The file name ends in the request ID. Open the file and choose Download to read it.
|
|
37
37
|
|
|
38
|
-
**Command line,
|
|
38
|
+
**Command line, only where both values are in the environment.** These commands need `CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN` in the shell's environment, for example in a cloud session whose environment settings hold them. When the tokens are only in `.env.cloudflare` (the usual case, [owner-tasks.md](owner-tasks.md) §2), the variables are empty and the requests fail: use the dashboard route above instead. Never `source`, `cat` or otherwise read `.env.cloudflare` to fill them in. These two `curl` commands are **verified on Cloudflare**: on a real test stage, the list command found a failed request's key and the read command returned its `CORE.INTERNAL` entry (E2E-011, Cloudflare pass 2–5; the framework repository's `validation/cloudflare/pass-2to5/SUMMARY.md` and `logs/5-trouble.log`). List one day's keys:
|
|
39
39
|
|
|
40
40
|
```sh
|
|
41
41
|
STAGE='<stage>'; DAY=$(date -u +%Y/%m/%d)
|
|
@@ -70,7 +70,7 @@ Not yet verified on Cloudflare in this phase.
|
|
|
70
70
|
```sh
|
|
71
71
|
npx wrangler tail "$APP-$STAGE" --format pretty
|
|
72
72
|
```
|
|
73
|
-
It needs `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID`
|
|
73
|
+
It needs `CLOUDFLARE_API_TOKEN` and `CLOUDFLARE_ACCOUNT_ID` in the shell's environment, as the `curl` commands above do; with the tokens only in `.env.cloudflare`, use the dashboard instead (Workers & Pages → `<app>-<stage>` → Logs, menu names not yet verified). Not yet verified on Cloudflare in this phase.
|
|
74
74
|
- If entries are printed as lines starting `[prototype-framework:log]` in `wrangler tail`, the Worker has no `LOGS` binding. Run `deploy` again.
|
|
75
75
|
- Locally, entries reach `.logs/` only while `npm run dev` runs. In-process tests write no files.
|
|
76
76
|
|
|
@@ -103,8 +103,8 @@ Every stage signs people in with email and password. A failed attempt writes one
|
|
|
103
103
|
|
|
104
104
|
No mail arrives:
|
|
105
105
|
- Locally nothing is sent: read `.mail/` with `npm run mail -- last --to '<address>'`. On a test stage the mail is captured, not sent.
|
|
106
|
-
- On a production stage, look for a `MAIL` entry `mail send failed: <code>` (§1). The sender is `no-reply@<domain>`; if `deploy` or
|
|
107
|
-
- A test address `sink+<tag>@t.<domain>`: read it with `npm run mail -- last --to '<address>' --target cloudflare`. Only `sink+…` addresses reach the test mailbox. Right after
|
|
106
|
+
- On a production stage, look for a `MAIL` entry `mail send failed: <code>` (§1). The sender is `no-reply@<domain>`; if `deploy` or setup said the domain is not verified for sending, run `npm run cloudflare-setup` again.
|
|
107
|
+
- A test address `sink+<tag>@t.<domain>`: read it with `npm run mail -- last --to '<address>' --target cloudflare`. Only `sink+…` addresses reach the test mailbox. Right after setup created the mailbox rule, a send may be rejected for a minute.
|
|
108
108
|
|
|
109
109
|
Signed in, but not admin: the `admin` role is granted per stage with `admins grant` ([owner-tasks.md](owner-tasks.md) §7); check with `admins list`.
|
|
110
110
|
|
|
@@ -112,8 +112,8 @@ Signed in, but not admin: the `admin` role is granted per stage with `admins gra
|
|
|
112
112
|
|
|
113
113
|
`deploy` prints the failed step, the stage's state and the next action. Follow the next action. Common messages:
|
|
114
114
|
|
|
115
|
-
- `run setup-account … first`: the account's shared resources are missing.
|
|
116
|
-
- A missing `CLOUDFLARE_API_TOKEN` or `CLOUDFLARE_ACCOUNT_ID`,
|
|
115
|
+
- `run setup-account … first`: the account's shared resources are missing. Run `npm run cloudflare-setup` ([owner-tasks.md](owner-tasks.md) §2).
|
|
116
|
+
- A missing `CLOUDFLARE_API_TOKEN` or `CLOUDFLARE_ACCOUNT_ID`, a missing permission, or "R2 signing credential … missing": run `npm run cloudflare-setup`, which says what to fix ([owner-tasks.md](owner-tasks.md) §2). "Account API Tokens Write" is the bootstrap token's only.
|
|
117
117
|
- `NODE_USE_ENV_PROXY`: you are behind an HTTPS proxy. Put `NODE_USE_ENV_PROXY=1 ` in front of the command.
|
|
118
118
|
- `required secrets are not set: …`: this happens on the first deploy of a stage. Set each named secret with `--target cloudflare`, then run `deploy` again.
|
|
119
119
|
- An error about the number of D1 databases: an account holds at most 10, and a schema-changing deploy briefly holds two per stage. Remove unused test stages ([deploying.md](deploying.md)).
|
|
@@ -7,7 +7,7 @@ Suspected framework defects found while building this app. Each entry is reprodu
|
|
|
7
7
|
- **Status:** open
|
|
8
8
|
- **Task attempted:** <the requirement or step you were implementing>
|
|
9
9
|
- **Contract or reference consulted:** <file and section, for example `skill/reference/files.md`, "The safe upload pattern">
|
|
10
|
-
- **Minimal reproduction:** <the smallest code, and the exact command that shows the problem, for example `
|
|
10
|
+
- **Minimal reproduction:** <the smallest code, and the exact command that shows the problem, for example `npm run verify`>
|
|
11
11
|
- **Observed code or diagnostic:** <copied exactly: error code and status, the `verify` line, the request ID>
|
|
12
12
|
- **Expected:** <what the contract or reference says should happen>
|
|
13
13
|
- **Workaround not taken:** <what you could have done instead, and did not>
|