@lago-morph/create-prototype-app 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/README.md +9 -2
- package/bin/create-prototype-app.js +26 -10
- package/lib/create.mjs +115 -2
- 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/template/.claude/settings.json +27 -0
- package/template/README.md +12 -29
- package/template/gitignore +3 -0
- package/template/package.json +5 -2
package/README.md
CHANGED
|
@@ -14,7 +14,14 @@ npm run dev
|
|
|
14
14
|
2. names the app after the folder: `package.json` `name`, and the app name in `src/app.ts` and `index.html` (1 to 20 lowercase letters and digits; pass `--name` to choose another);
|
|
15
15
|
3. pins `@lago-morph/prototype-framework` at the release that matches this package's version;
|
|
16
16
|
4. copies the Claude Code skill for the framework into `.claude/skills/prototype-framework/`, so Claude Code finds it in the app's folder;
|
|
17
|
-
5. runs `npm install
|
|
17
|
+
5. runs `npm install`;
|
|
18
|
+
6. runs `git init` (unless the folder is already inside a git repository);
|
|
19
|
+
7. sets a random local value for each of the app's secrets in `.dev.vars`, and makes sure `.gitignore` lists `.env.cloudflare`;
|
|
20
|
+
8. makes the first commit.
|
|
21
|
+
|
|
22
|
+
It asks for no account. If git is missing or a git step fails, it warns and carries on. It ends with what to do next: `cd my-app`, then `npm run dev`, or open the folder in Claude Code and say what to build.
|
|
23
|
+
|
|
24
|
+
Later, `npm run upgrade` moves the app to a newer framework release and refreshes its skill copy, and `npm run version-check` says whether that is worth doing.
|
|
18
25
|
|
|
19
26
|
Node.js 22.22.0 is what the framework requires.
|
|
20
27
|
|
|
@@ -26,7 +33,7 @@ Pass options after `--` with `npm create`, for example `npm create @lago-morph/p
|
|
|
26
33
|
| --- | --- |
|
|
27
34
|
| `--name <app>` | App name instead of one made from the folder name |
|
|
28
35
|
| `--framework <spec>` | Another dependency spec for the framework, such as a `file:` tarball path |
|
|
29
|
-
| `--no-install` | Skip `npm install
|
|
36
|
+
| `--no-install` | Skip `npm install`, and the local secrets that need it |
|
|
30
37
|
| `--no-skill` | Do not copy the skill (install the plugin instead, below) |
|
|
31
38
|
| `--force` | Overwrite files in a folder that is not empty |
|
|
32
39
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
// `npm create @lago-morph/prototype-app <dir>` runs this (npm maps @scope/name to
|
|
3
|
-
// @scope/create-name). See README.md for the options.
|
|
3
|
+
// @scope/create-name). See README.md for the options. Asks for no account (plan-setup-wizard §3.1).
|
|
4
4
|
import { spawnSync } from "node:child_process";
|
|
5
5
|
import { existsSync, readFileSync } from "node:fs";
|
|
6
6
|
import { dirname, join, relative } from "node:path";
|
|
7
7
|
import { fileURLToPath } from "node:url";
|
|
8
|
-
import { create } from "../lib/create.mjs";
|
|
8
|
+
import { create, firstCommit, initRepo, localSetupLines, nextStep } from "../lib/create.mjs";
|
|
9
9
|
|
|
10
10
|
const USAGE = `usage: create-prototype-app <dir> [--name <app>] [--framework <spec>] [--no-install] [--no-skill] [--force]
|
|
11
11
|
|
|
@@ -13,7 +13,7 @@ const USAGE = `usage: create-prototype-app <dir> [--name <app>] [--framework <sp
|
|
|
13
13
|
--name <app> app name: 1-20 lowercase letters and digits (default: from <dir>)
|
|
14
14
|
--framework <spec> dependency spec for @lago-morph/prototype-framework
|
|
15
15
|
(default: this package's version, the matching framework release)
|
|
16
|
-
--no-install do not run npm install
|
|
16
|
+
--no-install do not run npm install (nor the local setup, which needs it)
|
|
17
17
|
--no-skill do not copy the Claude Code skill into .claude/skills/
|
|
18
18
|
--force overwrite files in a non-empty <dir>`;
|
|
19
19
|
|
|
@@ -89,13 +89,29 @@ if (opts.install) {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
npm run dev # serve the app locally
|
|
96
|
-
npm run verify # check everything before calling a change done
|
|
92
|
+
// Git problems warn and never fail (owner, 2026-10-26).
|
|
93
|
+
const repo = initRepo(result.target);
|
|
94
|
+
if (repo.message !== undefined) (repo.status === "warned" ? console.error : console.log)(repo.message);
|
|
97
95
|
|
|
98
|
-
The
|
|
99
|
-
|
|
96
|
+
// The framework's local setup: local secrets and .env.cloudflare in .gitignore (dependencies are installed above).
|
|
97
|
+
// Never fails the starter: a failure is a warning, and the first commit and the next step follow (exit 0).
|
|
98
|
+
if (opts.install) {
|
|
99
|
+
const { notes, warnings } = await localSetupLines(result.target);
|
|
100
|
+
for (const n of notes) console.log(n);
|
|
101
|
+
for (const w of warnings) console.error(w);
|
|
102
|
+
} else {
|
|
103
|
+
console.log("Skipped npm install and the local setup (--no-install): no local secret values were set.");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (repo.status === "initialized") {
|
|
107
|
+
const commit = firstCommit(result.target, `Start ${result.appName} from @lago-morph/create-prototype-app ${self.version}`);
|
|
108
|
+
if (commit.ok) console.log("Made the first git commit.");
|
|
109
|
+
else console.error(commit.message);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (!result.skill) {
|
|
113
|
+
console.log(`Claude Code: install the skill as a plugin:
|
|
100
114
|
/plugin marketplace add lago-morph/cloud-app
|
|
101
115
|
/plugin install prototype-framework@lago-morph`);
|
|
116
|
+
}
|
|
117
|
+
console.log(`\n${nextStep(rel, { installed: opts.install })}`);
|
package/lib/create.mjs
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
// Core of `npm create @lago-morph/prototype-app`: copy the template app into a new folder, give it
|
|
2
|
-
// its own name, pin the framework at the published version, and add the Claude Code skill
|
|
2
|
+
// its own name, pin the framework at the published version, and add the Claude Code skill; then
|
|
3
|
+
// the git repository and its first commit, around the framework's local setup (plan-setup-wizard §3.1).
|
|
3
4
|
// Node built-ins only: the package has no runtime dependencies.
|
|
5
|
+
import { spawnSync } from "node:child_process";
|
|
4
6
|
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, writeFileSync } from "node:fs";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
5
8
|
import { basename, join, relative, resolve, sep } from "node:path";
|
|
9
|
+
import { pathToFileURL } from "node:url";
|
|
6
10
|
|
|
7
11
|
export const FRAMEWORK_PACKAGE = "@lago-morph/prototype-framework";
|
|
8
12
|
|
|
@@ -40,6 +44,26 @@ export function copyTree(from, to, skip) {
|
|
|
40
44
|
});
|
|
41
45
|
}
|
|
42
46
|
|
|
47
|
+
/** The skill's version marker: one line, the version the skill was released at (DEC-0592). */
|
|
48
|
+
export const SKILL_VERSION_FILE = "VERSION";
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Copy the skill in `from` to `to` (SKILL_SKIP left out) and give the copy its version marker:
|
|
52
|
+
* from the plugin manifest of the repository's skill/, or the marker an earlier copy carries.
|
|
53
|
+
* Returns the version, or undefined when `from` has neither.
|
|
54
|
+
*/
|
|
55
|
+
export function copySkill(from, to) {
|
|
56
|
+
copyTree(from, to, SKILL_SKIP);
|
|
57
|
+
const manifest = join(from, ".claude-plugin", "plugin.json");
|
|
58
|
+
if (existsSync(manifest)) {
|
|
59
|
+
const { version } = JSON.parse(readFileSync(manifest, "utf8"));
|
|
60
|
+
writeFileSync(join(to, SKILL_VERSION_FILE), `${version}\n`);
|
|
61
|
+
return version;
|
|
62
|
+
}
|
|
63
|
+
const marker = join(to, SKILL_VERSION_FILE);
|
|
64
|
+
return existsSync(marker) ? readFileSync(marker, "utf8").trim() : undefined;
|
|
65
|
+
}
|
|
66
|
+
|
|
43
67
|
/** The app name derived from a folder name: lowercase letters and digits only, cut to 20. */
|
|
44
68
|
export function appNameFrom(dir) {
|
|
45
69
|
return basename(resolve(dir)).toLowerCase().replace(/[^a-z0-9]/g, "").slice(0, 20);
|
|
@@ -110,7 +134,96 @@ export function create({ target, templateDir, skillDir = null, frameworkSpec, ap
|
|
|
110
134
|
replaceOnce(join(dir, "index.html"), "<title>template</title>", `<title>${name}</title>`);
|
|
111
135
|
|
|
112
136
|
const skill = skillDir !== null && existsSync(join(skillDir, "SKILL.md"));
|
|
113
|
-
if (skill)
|
|
137
|
+
if (skill) copySkill(skillDir, join(dir, SKILL_TARGET));
|
|
114
138
|
|
|
115
139
|
return { target: dir, appName: name, packageName, skill };
|
|
116
140
|
}
|
|
141
|
+
|
|
142
|
+
/** Runs git in `dir`; `{ error }` when git is missing or cannot start. */
|
|
143
|
+
function runGit(git, dir, args) {
|
|
144
|
+
const r = spawnSync(git, args, { cwd: dir, encoding: "utf8", stdio: ["ignore", "pipe", "pipe"] });
|
|
145
|
+
if (r.error !== undefined) return { error: r.error };
|
|
146
|
+
return { status: r.status, stderr: (r.stderr ?? "").trim().split("\n")[0] ?? "" };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* `git init` in `dir` (DEC-0596). Never throws: git missing or failing is a warning. A folder that
|
|
151
|
+
* is already inside a git work tree (a repository checkout) is left to that repository.
|
|
152
|
+
*
|
|
153
|
+
* @returns {{ status: "initialized" | "inside-repo" | "warned", message?: string }}
|
|
154
|
+
*/
|
|
155
|
+
export function initRepo(dir, { git = "git" } = {}) {
|
|
156
|
+
const inside = runGit(git, dir, ["rev-parse", "--is-inside-work-tree"]);
|
|
157
|
+
if (inside.error !== undefined) {
|
|
158
|
+
return { status: "warned", message: "WARNING: git was not found, so this folder is not a git repository. Install git, then run `git init` here." };
|
|
159
|
+
}
|
|
160
|
+
if (inside.status === 0) return { status: "inside-repo", message: "This folder is inside an existing git repository: no new repository, and nothing committed." };
|
|
161
|
+
const r = runGit(git, dir, ["init", "-q"]);
|
|
162
|
+
if (r.error !== undefined || r.status !== 0) {
|
|
163
|
+
return { status: "warned", message: `WARNING: git init failed${r.stderr ? ` (${r.stderr})` : ""}, so this folder is not a git repository. Run \`git init\` here.` };
|
|
164
|
+
}
|
|
165
|
+
return { status: "initialized" };
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/**
|
|
169
|
+
* The first commit of everything not ignored (DEC-0596). Never throws: a failure (for example
|
|
170
|
+
* no `user.name` / `user.email`) is a warning naming the commands to run.
|
|
171
|
+
*
|
|
172
|
+
* @returns {{ ok: boolean, message?: string }}
|
|
173
|
+
*/
|
|
174
|
+
export function firstCommit(dir, message, { git = "git" } = {}) {
|
|
175
|
+
const add = runGit(git, dir, ["add", "-A"]);
|
|
176
|
+
const commit = add.error === undefined && add.status === 0 ? runGit(git, dir, ["commit", "-q", "-m", message]) : add;
|
|
177
|
+
if (commit.error !== undefined || commit.status !== 0) {
|
|
178
|
+
const why = commit.error === undefined && commit.stderr ? ` (${commit.stderr})` : "";
|
|
179
|
+
return { ok: false, message: `WARNING: the first commit failed${why}. Commit yourself: git add -A && git commit -m "First commit"` };
|
|
180
|
+
}
|
|
181
|
+
return { ok: true };
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* The framework's local setup (`runLocalSetup`, DEC-0591), loaded from the app's installed
|
|
186
|
+
* framework, so the starter and `cloudflare-setup` run the same steps. Undefined when the
|
|
187
|
+
* installed framework does not have it.
|
|
188
|
+
*/
|
|
189
|
+
export async function loadLocalSetup(appDir) {
|
|
190
|
+
try {
|
|
191
|
+
const entry = createRequire(join(appDir, "package.json")).resolve(`${FRAMEWORK_PACKAGE}/provision`);
|
|
192
|
+
const mod = await import(pathToFileURL(entry).href);
|
|
193
|
+
return typeof mod.runLocalSetup === "function" ? { runLocalSetup: mod.runLocalSetup, describeLocalSetup: mod.describeLocalSetup } : undefined;
|
|
194
|
+
} catch {
|
|
195
|
+
return undefined;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Runs the local setup in `appDir` and returns what to print. Never throws: a framework without
|
|
201
|
+
* it, or a run that throws, is a warning naming how to set the secrets by hand. The app stays
|
|
202
|
+
* usable either way (`dev` generates the framework's own keys), so the starter carries on to the
|
|
203
|
+
* first commit and exits 0 (DEC-0596).
|
|
204
|
+
*
|
|
205
|
+
* @returns {Promise<{ notes: string[], warnings: string[] }>}
|
|
206
|
+
*/
|
|
207
|
+
export async function localSetupLines(appDir, { load = loadLocalSetup } = {}) {
|
|
208
|
+
const byHand = "set the app's secrets with `npm run secrets -- set <name> --target local --stage local`.";
|
|
209
|
+
let setup;
|
|
210
|
+
try {
|
|
211
|
+
setup = await load(appDir);
|
|
212
|
+
} catch {
|
|
213
|
+
setup = undefined;
|
|
214
|
+
}
|
|
215
|
+
if (setup === undefined) return { notes: [], warnings: [`WARNING: the installed framework has no local setup; ${byHand}`] };
|
|
216
|
+
try {
|
|
217
|
+
const outcomes = await setup.runLocalSetup(appDir);
|
|
218
|
+
const said = outcomes.filter((o) => o.message !== undefined);
|
|
219
|
+
return { notes: said.filter((o) => o.result !== "warned").map((o) => o.message), warnings: said.filter((o) => o.result === "warned").map((o) => o.message) };
|
|
220
|
+
} catch (error) {
|
|
221
|
+
return { notes: [], warnings: [`WARNING: the local setup failed (${error instanceof Error ? error.message : String(error)}). Run \`npm run dev\` once, then ${byHand}`] };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** The closing line (plan §3.1): what to do next, with the folder as the owner would type it. */
|
|
226
|
+
export function nextStep(rel, { installed = true } = {}) {
|
|
227
|
+
const run = installed ? "`npm run dev`" : "`npm install` and `npm run dev`";
|
|
228
|
+
return rel === "." ? `Run ${run}, or open this folder in Claude Code and say what to build.` : `cd ${rel}, then ${run}, or open this folder in Claude Code and say what to build.`;
|
|
229
|
+
}
|
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>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://json.schemastore.org/claude-code-settings.json",
|
|
3
|
+
"permissions": {
|
|
4
|
+
"deny": [
|
|
5
|
+
"Read(.env.cloudflare)",
|
|
6
|
+
"Edit(.env.cloudflare)",
|
|
7
|
+
"Bash(grep *.env.cloudflare*)",
|
|
8
|
+
"Bash(rg *.env.cloudflare*)",
|
|
9
|
+
"Bash(awk *.env.cloudflare*)",
|
|
10
|
+
"Bash(less *.env.cloudflare*)",
|
|
11
|
+
"Bash(more *.env.cloudflare*)",
|
|
12
|
+
"Bash(source *.env.cloudflare*)",
|
|
13
|
+
"Bash(. *.env.cloudflare*)",
|
|
14
|
+
"Bash(echo *CLOUDFLARE_API_TOKEN*)",
|
|
15
|
+
"Bash(echo *CLOUDFLARE_BOOTSTRAP_TOKEN*)",
|
|
16
|
+
"Bash(env)",
|
|
17
|
+
"Bash(env -0)",
|
|
18
|
+
"Bash(printenv *)",
|
|
19
|
+
"Bash(set)",
|
|
20
|
+
"Bash(export)",
|
|
21
|
+
"Bash(export -p)",
|
|
22
|
+
"Bash(declare -p*)",
|
|
23
|
+
"Bash(declare -x*)",
|
|
24
|
+
"Bash(* /proc/*environ*)"
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
}
|
package/template/README.md
CHANGED
|
@@ -4,7 +4,7 @@ This is the smallest app built on the prototype framework. It uses each capabili
|
|
|
4
4
|
|
|
5
5
|
This page lists everything the owner does by hand, as copy-and-paste steps. Run the commands in a terminal, in this app's folder, on macOS or Linux with Node 22.22.0. Replace the `<…>` parts. Never paste a secret value into a command line, a committed file or a chat.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
This release runs apps locally (§1) and on Cloudflare (§2 on). The short version of everything here is the framework's [QUICKSTART.md](https://github.com/lago-morph/cloud-app/blob/main/QUICKSTART.md).
|
|
8
8
|
|
|
9
9
|
People sign in with an email address and a password. **Anyone who signs up and verifies their address is a user.** Admins are users holding the `admin` role, granted with the `admins` command (§8); nothing about people is kept in configuration. `<domain>` below is the account's email domain.
|
|
10
10
|
|
|
@@ -22,7 +22,7 @@ People sign in with an email address and a password. **Anyone who signs up and v
|
|
|
22
22
|
```sh
|
|
23
23
|
APP=$(npm run --silent build -- --target local --stage local | sed -n 's/^built \([^ ]*\) for .*/\1/p'); echo "$APP"
|
|
24
24
|
```
|
|
25
|
-
3.
|
|
25
|
+
3. The app's secret `apiKey`, which the admin page checks, needs a local value. An app made with `npm create @lago-morph/prototype-app` already has a random one, set when it was made (and `npm run cloudflare-setup` sets any that is missing). `npm run dev` generates only the framework's own development keys. To set or change the value yourself (in the framework's repository, do this once), run the command, paste any value, press Enter, then press Ctrl-D:
|
|
26
26
|
```sh
|
|
27
27
|
npm run secrets -- set apiKey --target local --stage local
|
|
28
28
|
```
|
|
@@ -47,36 +47,19 @@ People sign in with an email address and a password. **Anyone who signs up and v
|
|
|
47
47
|
```
|
|
48
48
|
7. To start again from empty local data (the database, files and logs), run `npm run reset-local`. Your code, configuration and `.dev.vars` stay.
|
|
49
49
|
|
|
50
|
-
## 2. Cloudflare
|
|
50
|
+
## 2. Cloudflare setup (once per account)
|
|
51
51
|
|
|
52
|
-
|
|
53
|
-
2. Copy your **Account ID**. Open Account home, choose your account, and copy the Account ID from its overview page. The Cloudflare dashboard menu names on this page are **not yet verified**.
|
|
54
|
-
3. Create two **account API tokens**: go to Manage Account → Account API Tokens → Create Token → Create Custom Token (not yet verified). The email domain must be a zone on this account with Cloudflare DNS active. For each token, under Account Resources include only your account, and under Zone Resources the email domain's zone. Create the token, then copy it. Cloudflare shows it only once.
|
|
55
|
-
- The **everyday token**, named `prototype-framework`, for every command except `setup-account`. **Account** permissions: Workers Scripts: Edit, Workers R2 Storage: Edit, D1: Edit, Email Sending: Read. **Zone** permissions: Zone: Read, Analytics: Read. It cannot create API tokens.
|
|
56
|
-
- The **setup token**, named `prototype-framework-setup`, for `setup-account` only (§3), which you run rarely. **Account** permissions: Workers Scripts: Edit, Workers R2 Storage: Edit, Account API Tokens: Edit (it creates the file-signing credential all stages share), Email Sending: Edit, Email Routing Addresses: Edit. **Zone** permissions: Email Routing Rules: Edit, DNS: Edit, Zone Settings: Edit, Zone: Read. Keep it apart from the everyday token.
|
|
57
|
-
|
|
58
|
-
These lists are checked against the Cloudflare API: a token with exactly the everyday permissions passed every read `deploy` makes before it changes anything. A command that lacks a permission names it.
|
|
59
|
-
4. In every new terminal where you deploy, set both values. `read` keeps the token out of your shell history. Paste the everyday token when it waits, then press Enter:
|
|
60
|
-
```sh
|
|
61
|
-
export CLOUDFLARE_ACCOUNT_ID='<your Account ID>'
|
|
62
|
-
read -rs CLOUDFLARE_API_TOKEN && export CLOUDFLARE_API_TOKEN
|
|
63
|
-
```
|
|
64
|
-
5. Check the token. The output must contain `"success":true`:
|
|
65
|
-
```sh
|
|
66
|
-
curl -sS -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/tokens/verify"
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
If a command says it needs `NODE_USE_ENV_PROXY=1`, you are behind an HTTPS proxy. Put `NODE_USE_ENV_PROXY=1 ` in front of that command.
|
|
70
|
-
|
|
71
|
-
## 3. One-time account setup
|
|
72
|
-
|
|
73
|
-
Set the **setup token** first, the same way as in §2 step 4 (`read -rs CLOUDFLARE_API_TOKEN && export CLOUDFLARE_API_TOKEN`, paste the setup token). Run:
|
|
52
|
+
You need a Cloudflare account on the Workers Paid plan and a domain on it with Cloudflare DNS active (`<domain>` below). Run, in this app's folder (in Claude Code, say "set up Cloudflare"):
|
|
74
53
|
|
|
75
54
|
```sh
|
|
76
|
-
npm run
|
|
55
|
+
npm run cloudflare-setup
|
|
77
56
|
```
|
|
78
57
|
|
|
79
|
-
|
|
58
|
+
It prints two pre-filled dashboard links, one per token, and where to put the values (`.env.cloudflare` in this folder, or the environment). Make the tokens, put them there, and run it again until it says everything is set up. It never prints a token value, and every later command reads the tokens itself. The steps, and what to do when it stops: [QUICKSTART.md](https://github.com/lago-morph/cloud-app/blob/main/QUICKSTART.md) and the skill's `reference/owner-tasks.md` §2 (in this app, `.claude/skills/prototype-framework/reference/owner-tasks.md`).
|
|
59
|
+
|
|
60
|
+
## 3. What the account setup creates
|
|
61
|
+
|
|
62
|
+
Setup creates the account's shared resources once, 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 account's `workers.dev` address, sending from `no-reply@<domain>`, and a test mailbox for agents: mail to `sink+<tag>@t.<domain>` is kept for a day. Running it again changes only what is missing. `deploy` never creates these resources; if any is missing, it says to run the setup again.
|
|
80
63
|
|
|
81
64
|
## 4. Deploy a test stage, test it, remove it
|
|
82
65
|
|
|
@@ -191,7 +174,7 @@ npm run admins -- list --target cloudflare --stage "$STAGE" --confirm-production
|
|
|
191
174
|
Every error response has a `requestId`. A failed login returns to `/?authError=login_failed&requestId=<id>`. Each log entry is a file in the R2 bucket `prototype-logs`, under `template/<stage>/<yyyy>/<mm>/<dd>/`. The date is UTC, and the file name ends in `-<requestId>.json`.
|
|
192
175
|
|
|
193
176
|
- **Dashboard** (menu names not yet verified)**:** open Storage & databases → R2 → `prototype-logs`, then the folders `template` / `<stage>` / year / month / day. Open the file whose name ends in the request ID.
|
|
194
|
-
- **Command line:**
|
|
177
|
+
- **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. With the tokens only in `.env.cloudflare` (§2), the variables are empty and the requests fail: use the dashboard route above. Never `source` or `cat` `.env.cloudflare` to fill them in. List today's entries of a stage, and keep only the line with the request ID. `APP` must be set (§1 step 2):
|
|
195
178
|
```sh
|
|
196
179
|
STAGE='<stage>'; DAY=$(date -u +%Y/%m/%d)
|
|
197
180
|
curl -sS -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
|
@@ -205,7 +188,7 @@ Every error response has a `requestId`. A failed login returns to `/?authError=l
|
|
|
205
188
|
curl -sS -H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
|
|
206
189
|
"https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/r2/buckets/prototype-logs/objects/$(node -p 'encodeURIComponent(process.argv[1])' "$KEY")"
|
|
207
190
|
```
|
|
208
|
-
- **No entry?** Watch the Worker's output while you repeat the request: `npx wrangler tail "$APP-$STAGE" --format pretty
|
|
191
|
+
- **No entry?** Watch the Worker's output while you repeat the request: `npx wrangler tail "$APP-$STAGE" --format pretty` (it too needs both values in the environment; otherwise open the Worker's logs in the dashboard, Workers & Pages → `template-<stage>` → Logs, menu names not yet verified). More help is in the skill's troubleshooting reference, `skill/reference/troubleshooting.md` in the framework repository.
|
|
209
192
|
|
|
210
193
|
## 11. Cost: what stays billable while idle
|
|
211
194
|
|
package/template/gitignore
CHANGED
package/template/package.json
CHANGED
|
@@ -15,13 +15,16 @@
|
|
|
15
15
|
"start": "prototype-framework start",
|
|
16
16
|
"secrets": "prototype-framework secrets",
|
|
17
17
|
"setup-account": "prototype-framework setup-account",
|
|
18
|
+
"cloudflare-setup": "prototype-framework cloudflare-setup",
|
|
18
19
|
"check-login": "prototype-framework check-login",
|
|
19
20
|
"reset-local": "prototype-framework reset-local",
|
|
20
21
|
"mail": "prototype-framework mail",
|
|
21
|
-
"admins": "prototype-framework admins"
|
|
22
|
+
"admins": "prototype-framework admins",
|
|
23
|
+
"version-check": "prototype-framework version-check",
|
|
24
|
+
"upgrade": "prototype-framework upgrade"
|
|
22
25
|
},
|
|
23
26
|
"dependencies": {
|
|
24
|
-
"@lago-morph/prototype-framework": "0.1.
|
|
27
|
+
"@lago-morph/prototype-framework": "0.1.1",
|
|
25
28
|
"hono": "4.13.13",
|
|
26
29
|
"zod": "4.6.7"
|
|
27
30
|
},
|