@stagepass/cli 2.4.1 → 2.6.0

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 CHANGED
@@ -6,7 +6,7 @@ The CLI sets up and manages the local Stagepass infrastructure (`.sp` domains, C
6
6
 
7
7
  ## Install
8
8
 
9
- Published CLI 2.4.0 requires Node.js **20.17+** (`engines.node`: `>=20.17.0`) on **macOS** with Homebrew, because `@inquirer/prompts@8` requires it. Node 18 is no longer supported; stay on `@stagepass/cli@2.2.7` if you must remain on Node 18. Development and CI use Node 22 or 24.
9
+ Published CLI 2.5.0 requires Node.js **20.17+** (`engines.node`: `>=20.17.0`) on **macOS** with Homebrew, because `@inquirer/prompts@8` requires it. Node 18 is no longer supported; stay on `@stagepass/cli@2.2.7` if you must remain on Node 18. Development and CI use Node 22 or 24.
10
10
 
11
11
  ```bash
12
12
  npm install -g @stagepass/cli@2
@@ -21,7 +21,7 @@ npx @stagepass/cli@2 setup
21
21
  ## Requirements
22
22
 
23
23
  - **macOS** (system commands refuse other platforms with exit code 1; this is not a breaking change because those commands never worked off macOS)
24
- - Published CLI 2.4.0: Node.js `>=20.17.0`. Use Node 22 or 24 for local development and CI
24
+ - Published CLI 2.5.0: Node.js `>=20.17.0`. Use Node 22 or 24 for local development and CI
25
25
  - Homebrew
26
26
 
27
27
  `stagepass --version` and `stagepass --help` work on any platform. For tests/CI only, set `STAGEPASS_SKIP_PLATFORM_CHECK=1` to bypass the macOS guard (not for production use).
@@ -65,15 +65,15 @@ Linked: https://my-project.sp -> /absolute/path/to/project
65
65
  | `stagepass new [name]` | Scaffold a lean Webflow project (TypeScript + SCSS by default). |
66
66
  | `stagepass build` | Run `npm run build` in the current project (forwards exit code). |
67
67
  | `stagepass watch` | Run `npm run watch` in the current project (forwards exit code). If Stagepass is not running, asks to start it (TTY) or prints a `stagepass start` hint (non-TTY / CI); warns with `stagepass link` when the cwd is not linked. |
68
- | `stagepass dev` | Like `stagepass watch`, plus live reload on the linked `.sp` domain (CSS can swap without a full reload). Same running check as watch; requires `stagepass link` (hard error if unlinked). |
69
- | `stagepass upgrade` | Bump `@stagepass/*`, sync declared modules, `AGENTS.md`, the Cursor rule and `types`, print Webflow snippets. Since 2.4.1, writes a missing PHP `.htaccess` when `"php": true`. |
68
+ | `stagepass dev` | Like `stagepass watch`, plus live reload on the linked `.sp` domain (CSS can swap without a full reload). Same running check as watch; requires `stagepass link` (hard error if unlinked). When `stagepass.json` has `"php": true`, also watches `api/` and `.php/` (same SSE stream and debounce; ignores `.env`, `.php/.env`, `.php/rate-limit/`, logs, pid files, key and certificate files, and editor temp files). A missing folder does not stop the command. |
69
+ | `stagepass upgrade` | Bump `@stagepass/*`, sync declared modules, `AGENTS.stagepass.md`, the short pointer in `AGENTS.md`, the Cursor rule and editor types (`types` or `stagepass.d.ts`), print Webflow snippets. Since 2.4.1, writes a missing PHP `.htaccess` when `"php": true`. |
70
70
 
71
71
  All commands support `-v, --verbose` where applicable.
72
72
 
73
73
  ### Doctor / certificates / autostart
74
74
 
75
75
  - `doctor` and `certs check` are read-only. They never delete keychain items or certificate files.
76
- - Prefer CDN major pin `@2` in Webflow custom code. Doctor warns on unpinned CDN URLs (`@latest`, bare `@1`, or unversioned `@stagepass/loader` / `@stagepass/modules` in recommended snippets and in the current project's `README.md`, `stagepass.json`, and `*.html` files directly in the project root and in `snippets/`; non-recursive, regular files ≤ 1 MB, symlinks skipped).
76
+ - CLI 2.6.0 (not yet published) generates Webflow snippets on `https://cdn.stagepass.one` with exact pins and full file paths. `stagepass new --cdn jsdelivr` keeps the jsDelivr major pin `@2`. Doctor warns on unpinned CDN URLs on that host, on jsDelivr, and on existing unpkg (`@latest`, bare `@1`, or unversioned `@stagepass/loader` / `@stagepass/modules` in recommended snippets and in the current project's `README.md`, `stagepass.json`, and `*.html` files directly in the project root and in `snippets/`; non-recursive, regular files ≤ 1 MB, symlinks skipped).
77
77
  - `certs renew` is opt-in and confirmation-gated. Site repair only deletes `certificates/local/<linked-domain>` after checks fail. `--root` moves the CA folder to a timestamped backup (never deletes; needs two interactive confirmations without `--yes`, or `--yes --i-understand-root-renewal`). `--yes` alone always aborts for `--root` (TTY or not). Do not combine `--root` with `--remove-orphans`; run them as separate commands. Orphans are removed only by SHA-1 via `renew --remove-orphans`.
78
78
  - Chrome may require Local Network Access permission for public HTTPS pages that load `https://*.sp` assets.
79
79
  - Autostart runs as your user (same privilege model as interactive `caddy start`). `start` kickstarts the agent when present; `stop` bootouts until the next login. If port 443 cannot be bound, `daemon` logs a clear error, may notify, and exits `0` so launchd KeepAlive does not restart-loop. Interactive `start` confirms before signalling any non-caddy listener (name + PID; SIGTERM then optional SIGKILL). Own processes are signalled without elevated rights first; `sudo` only when needed after confirmation. There is no standby `sudo -v`.
@@ -120,19 +120,21 @@ Scaffold a project with flags for every choice (interactive prompts only on a TT
120
120
  | `--link` / `--no-link` | After scaffolding, run `stagepass link` (macOS only). Default: off; interactive macOS may offer it. |
121
121
  | `--git` / `--no-git` | `git init` (default: yes). |
122
122
  | `--remote <url>` | Set `origin` after git init (rejects URLs with embedded credentials). |
123
+ | `--cursor-rule` | Write `.cursor/rules/stagepass.mdc` even when the target has no `.cursor/` directory. Without this flag the rule is written only if `.cursor/` already exists. |
123
124
  | `--install` / `--no-install` | Run `npm install` (default: no). |
125
+ | `--cdn stagepass\|jsdelivr` | CDN for generated Webflow snippets, stored as `cdn` in `stagepass.json` (default: `stagepass`, exact pins on `https://cdn.stagepass.one`). `stagepass upgrade` reads it back. CLI 2.6.0 (not yet published). |
124
126
  | `-y, --yes` | Non-interactive; use defaults for omitted flags. |
125
127
  | `--dry-run` | Print the file plan without writing. |
126
128
 
127
- The name must be DNS-safe (lowercase `a-z`, `0-9`, hyphens; 1 to 63 chars; no leading/trailing hyphen). Existing files are never overwritten. Generated projects include `scripts/build.mjs` (content-hashed `dist/` + SRI `integrity` in `manifest.json`), scripts `build` / `watch` / `dev` (`dev` aliases `watch`), Webflow head/footer snippets (jsDelivr `@2`, loader plus the declared modules), `stagepass.json`, an `AGENTS.md` with the full `sp` API reference, `.cursor/rules/stagepass.mdc`, and a `.gitignore`. `@stagepass/loader` / `@stagepass/modules` are added as `^2` (same major as the CDN pin `@2`; npm installs the newest published 2.x). Per-module types are written only when the published or installed `@stagepass/modules` ships them (2.2.0 and later); otherwise `types` lists the umbrella `@stagepass/modules`.
129
+ The name must be DNS-safe (lowercase `a-z`, `0-9`, hyphens; 1 to 63 chars; no leading/trailing hyphen). Existing files are never overwritten. Generated projects include `scripts/build.mjs` (content-hashed `dist/` + SRI `integrity` in `manifest.json`), scripts `build` / `watch` / `dev` (`dev` aliases `watch`), Webflow head/footer snippets (Stagepass CDN first, exact pins, full file path, no `/dist/` segment; pass `--cdn jsdelivr` for the jsDelivr major pin `@2` alternative), `stagepass.json`, `AGENTS.stagepass.md` (the CLI-owned guide), a short pointer in `AGENTS.md`, and a `.gitignore`. `.cursor/rules/stagepass.mdc` (`alwaysApply: true`, pointer to `@AGENTS.stagepass.md`) is written only when the target already has a `.cursor/` directory or you pass `--cursor-rule`. `@stagepass/loader` / `@stagepass/modules` are added as `^2` (same major as the jsDelivr pin `@2`; the Stagepass CDN default uses an exact pin; npm installs the newest published 2.x). CLI 2.6.0 (not yet published). Per-module types are written only when the published or installed `@stagepass/modules` ships them (2.2.0 and later); otherwise `types` lists the umbrella `@stagepass/modules`.
128
130
 
129
- Interactively (macOS), `new` runs a read-only `doctor` preflight and can offer `stagepass setup` if the local stack looks incomplete (never automatic, never under `--yes` / no-TTY, never sudo by itself). Without a TTY (or with `--yes`) it uses `--site-modules`, then `--site` detection, else `[]` with a hint. The interactive wizard always asks whether to enable PHP unless `--php` / `--no-php` was passed. Staging / production prompts, `--staging` detection, and `link` reading `origin` / `production` from `stagepass.json` are part of this release.
131
+ Interactively (macOS), `new` runs a read-only `doctor` preflight and can offer `stagepass setup` if the local stack looks incomplete (never automatic, never under `--yes` / no-TTY, never sudo by itself). Without a TTY (or with `--yes`) it uses `--site-modules`, then `--site` detection, else `[]` with a hint. The interactive wizard always asks for the snippet CDN (`stagepass` first, or `jsdelivr`) unless `--cdn` was passed, and whether to enable PHP unless `--php` / `--no-php` was passed. Staging / production prompts, `--staging` detection, and `link` reading `origin` / `production` from `stagepass.json` are part of this release.
130
132
 
131
133
  ### PHP
132
134
 
133
135
  `--php` writes a plain PHP 8.2 boilerplate: `api/action.php` is the only public entry, actions are an allowlist in `api/actions.php`, and `.php/config.php` sits in the same folder as `api/`. That folder is the document root (the project root locally, `dist/` after `stagepass build`). Copy `api/.env.example` to `.env` in the project root (or use `.php/.env`) and set `ALLOWED_ORIGINS` (include `https://<name>.sp`). There is no mail. `load_config()` reads that project-root `.env` and `.php/.env`. It never reads `api/.env`.
134
136
 
135
- Caddy already returns 404 for any path segment that starts with `.` (`/.env`, `/api/.env`, `/.php/`). Since 2.4.1, `stagepass new --php` ships a web-root `.htaccess` with the Apache rule below, and `stagepass build` copies it into `dist/` when the project has one. Published CLI 2.4.0 does not ship that file. `stagepass new` refuses to overwrite an existing `.htaccess`. nginx does not read `.htaccess`; add the snippet below in the server block before `location ~ \.php$`. Prefer real environment variables so a `.env` file is not required in the web root.
137
+ Caddy already returns 404 for any path segment that starts with `.` (`/.env`, `/api/.env`, `/.php/`). Since 2.4.1, `stagepass new --php` ships a web-root `.htaccess` with the Apache rule below, and `stagepass build` copies it into `dist/` when the project has one. CLI 2.4.0 and older do not ship that file. `stagepass new` refuses to overwrite an existing `.htaccess`. nginx does not read `.htaccess`; add the snippet below in the server block before `location ~ \.php$`. Prefer real environment variables so a `.env` file is not required in the web root.
136
138
 
137
139
  `stagepass new` and `doctor` warn when `php` is missing, older than 8.2, or has no `php-fpm` / `php-cgi` (`brew install php` on macOS). `stagepass dev` and `stagepass watch` on a `"php": true` project do the same check and start Homebrew php-fpm (`brew services start php`, and `brew services restart php` only if start fails), the same helper `stagepass start` has used since 2.3. The JS build still runs. `stagepass build` copies `api/` to `dist/api/`, `.php/config.php` to `dist/.php/config.php`, and a project-root `.htaccess` to `dist/.htaccess` when `"php": true` and the file exists. It does not copy `.env`, `.php/.env`, or `.php/rate-limit/`. The copy also skips logs, pid files, and key, certificate, or database files (`.pem`, `.key`, `.p12`, `.pfx`, `.crt`, `.cer`, `.sqlite`, `.db`). It keeps `.htaccess` and `.env.example`. A `dist/.htaccess` already on disk stays when the project has none. Upload `dist/` (the folder that contains `api/`). That folder is the web root, so `.php/` is public on Apache and nginx unless hidden paths are denied. The public URL stays `/api/action.php`.
138
140
 
@@ -156,9 +158,9 @@ location ~* /\.(?!well-known\/) {
156
158
  }
157
159
  ```
158
160
 
159
- Both rules were tested on 12 November 2026 on php:8.2-apache (`AllowOverride All`, `a2enmod rewrite`) and on nginx 1.27 with php:8.2-fpm. `/.env`, `/.php/config.php`, `/api/.env.example`, and `/.git/HEAD` returned HTTP 403, with no secret or config leak. `/api/action.php?action=ping` returned HTTP 200, `{"status":"success","data":{"pong":true},"message":null}`. `/.well-known/test.txt` returned HTTP 200, body `well-known-ok`. `/.well-known/` as a directory with no index file returned HTTP 403 on both servers (no DirectoryIndex). Visible files under `/.well-known/` stay reachable. Published CLI 2.4.0 still needs these rules added by hand. Since 2.4.1 the Apache rule ships in the PHP scaffold, and `stagepass upgrade` writes a missing project `.htaccess` when `"php": true` ([quYArF43](https://trello.com/c/quYArF43)). nginx still needs the snippet on the host.
161
+ Both rules were tested on 12 November 2026 on php:8.2-apache (`AllowOverride All`, `a2enmod rewrite`) and on nginx 1.27 with php:8.2-fpm. `/.env`, `/.php/config.php`, `/api/.env.example`, and `/.git/HEAD` returned HTTP 403, with no secret or config leak. `/api/action.php?action=ping` returned HTTP 200, `{"status":"success","data":{"pong":true},"message":null}`. `/.well-known/test.txt` returned HTTP 200, body `well-known-ok`. `/.well-known/` as a directory with no index file returned HTTP 403 on both servers (no DirectoryIndex). Visible files under `/.well-known/` stay reachable. CLI 2.4.0 and older still need these rules added by hand. Since 2.4.1 the Apache rule ships in the PHP scaffold, and `stagepass upgrade` writes a missing project `.htaccess` when `"php": true` ([quYArF43](https://trello.com/c/quYArF43)). nginx still needs the snippet on the host.
160
162
 
161
- `stagepass dev` / `watch` serve PHP from the project root, so edits show up on the next request. From the folder that contains `api/`, `php -S 127.0.0.1:8080 -t .` matches `/api/action.php`. `php -S` does not apply Caddy's hidden-path 404. Do not point it at a folder that already contains a real `.env`. Prefer `stagepass dev` or the linked `.sp` domain. `sp.resolveLocalUrl` returns a URL only during an active `.sp` session. On Webflow, `window.location.origin` is the Webflow host, which does not run PHP. Fetch the absolute PHP host, for example `https://php.example.com/api/action.php`. `rate_limit_allows()` is fail-open and `client_ip()` uses only `REMOTE_ADDR`, never `X-Forwarded-For` (do not trust that header without a proxy allowlist). Behind a reverse proxy every visitor can share one counter. Still open: [sgt7wKlT](https://trello.com/c/sgt7wKlT). `stagepass upgrade` does not add the `api/` or `.php/` boilerplate. When `"php": true` and the project root has no `.htaccess`, it writes the shipped template (same bytes as `stagepass new --php`). An existing `.htaccess` is left unchanged. If that file has no `RewriteRule "(^|/)\." - [F]` line, upgrade prints a hint and still exits 0. Published CLI 2.4.0 does not write that file. The website guide is live at [https://stagepass.one/docs/php/](https://stagepass.one/docs/php/) (source outline: [docs/php.md](https://github.com/arobertherz/stagepass/blob/master/docs/php.md)).
163
+ `stagepass dev` / `watch` serve PHP from the project root, so edits show up on the next request. When `"php": true`, `stagepass dev` also watches `api/` and `.php/` and reloads the browser on that same live-reload stream and debounce as `dist/`. It ignores `.env`, `.php/.env`, `.php/rate-limit/`, logs, pid files, key, certificate, and database files (`.pem`, `.key`, `.p12`, `.pfx`, `.crt`, `.cer`, `.sqlite`, `.db`), and editor temp files (`~`, `.swp`, `.DS_Store`). A missing `api/` or `.php/` does not stop the command. The start log names those directories. Without `"php": true` live reload stays on the output directory. From the folder that contains `api/`, `php -S 127.0.0.1:8080 -t .` matches `/api/action.php`. `php -S` does not apply Caddy's hidden-path 404. Do not point it at a folder that already contains a real `.env`. Prefer `stagepass dev` or the linked `.sp` domain. `sp.resolveLocalUrl` returns a URL only during an active `.sp` session. On Webflow, `window.location.origin` is the Webflow host, which does not run PHP. Fetch the absolute PHP host, for example `https://php.example.com/api/action.php`. `rate_limit_allows()` logs storage faults (directory, file, `flock`, or a thrown error). The response is HTTP 503, JSend `error`, `Retry-After: 60`, and no internals, unless `APP_ENV` is `local`, `development`, or `dev` (trimmed, any case). Empty, unset, and every other value stay closed. A limit hit stays HTTP 429. `client_ip()` uses `REMOTE_ADDR` unless that peer is in `TRUSTED_PROXIES`, then reads `TRUSTED_PROXY_HEADER` (`x-forwarded-for` or RFC 7239 `forwarded`) from right to left. This applies to projects created with CLI 2.5.0. CLI 2.4.1 and older stay fail-open and use only `REMOTE_ADDR`. `stagepass upgrade` does not change `api/`. Copy `api/lib/security.php`, `api/lib/request.php`, `api/lib/config.php`, `.php/config.php`, and `api/action.php` from a new scaffold, or re-scaffold. [sgt7wKlT](https://trello.com/c/sgt7wKlT). `stagepass upgrade` does not add the `api/` or `.php/` boilerplate. When `"php": true` and the project root has no `.htaccess`, it writes the shipped template (same bytes as `stagepass new --php`). An existing `.htaccess` is left unchanged. If that file has no `RewriteRule "(^|/)\." - [F]` line, upgrade prints a hint and still exits 0. CLI 2.4.0 and older do not write that file. The website guide is live at [https://stagepass.one/docs/php/](https://stagepass.one/docs/php/) (source outline: [docs/php.md](https://github.com/arobertherz/stagepass/blob/master/docs/php.md)).
162
164
 
163
165
  ### Declared modules (`stagepass.json`)
164
166
 
@@ -168,8 +170,9 @@ Both rules were tested on 12 November 2026 on php:8.2-apache (`AllowOverride All
168
170
 
169
171
  `modules` is `[]` (loader only), a list of `inject`, `cookies`, `maintenance`, or `["all"]`. It must match what your Webflow site loads. From it the CLI generates:
170
172
 
171
- - the managed block in `AGENTS.md` (between `<!-- stagepass:begin -->` and `<!-- stagepass:end -->`): loader API always, full sections for declared modules, a "not available; enable by …" line for the others, and the rule never to use undeclared `sp.<module>`;
172
- - `.cursor/rules/stagepass.mdc` (globs `src/**`) with the same content;
173
+ - `AGENTS.stagepass.md` (CLI-owned): feature set, safe rules, local workflow, editor types, the loader API, full sections for declared modules, a "not available; enable by …" line for the others, and the rule never to use undeclared `sp.<module>`. When `stagepass.json` has `"php": true` and `api/lib/` is present, it also documents the PHP helpers. The first line is `<!-- stagepass:managed cli=<version> sha256=<body> -->`. Do not edit it by hand. `stagepass upgrade` rewrites it. Your notes belong in `AGENTS.md`.
174
+ - a short pointer in `AGENTS.md` (between `<!-- stagepass:begin -->` and `<!-- stagepass:end -->`) that tells agents to read `AGENTS.stagepass.md`;
175
+ - `.cursor/rules/stagepass.mdc` with `alwaysApply: true` and a pointer to `@AGENTS.stagepass.md`, only when `.cursor/` already exists or `--cursor-rule` is set (`AGENTS.md` stays the tool-neutral guide);
173
176
  - `compilerOptions.types` in `tsconfig.json` / `jsconfig.json`: `@stagepass/loader` plus `@stagepass/modules/<module>` for each declared module (`@stagepass/modules` for `all`), so undeclared modules are type errors. Published `@stagepass/loader` 2.5.0 `global.d.ts` augments `Window` with `sp` and `stagepass` (both `StagepassAPI`) and declares global `var sp` / `var stagepass`. The scaffold `src/main.ts` still narrows `sp` to `log` for the ready line. The official types are wider.
174
177
 
175
178
  The legacy boolean `"modules": true|false` is still read; `upgrade` replaces it with a list (`true` becomes `["all"]` without a TTY).
@@ -178,7 +181,7 @@ The legacy boolean `"modules": true|false` is still read; `upgrade` replaces it
178
181
 
179
182
  `new --site`, `upgrade` and `doctor` read the modules from the live site: one public `GET` of the origin, https only, no cookies or auth headers, about 5 s timeout, a size cap, at most 3 redirects (all https). Only `<script src>` attributes are parsed with a regex (HTML comments ignored); nothing is executed. Recognised:
180
183
 
181
- - CDN (`cdn.jsdelivr.net/npm/` or `unpkg.com/`): full `/dist/{loader,inject,cookies,maintenance,all}(.min).js` paths, any version (`@2`, `@2.0.0`, none), and package-root URLs such as `…/@stagepass/loader@2` or `…/@stagepass/modules@2` (optional trailing slash / query). Package-root maps from each package’s `main` field (loader → `loader`, modules → `all`); there is no `unpkg` / `jsdelivr` / `exports` override in those packages.
184
+ - the Stagepass CDN (`cdn.stagepass.one`) first: full file paths such as `/loader@2.5.0/loader.min.js` and short aliases such as `/loader@2.5.0` (no `/dist/` segment). jsDelivr (`cdn.jsdelivr.net/npm/`) and existing unpkg (`unpkg.com/`) tags are still recognised so current sites keep working: full `/dist/{loader,inject,cookies,maintenance,all}(.min).js` paths, any version (`@2`, `@2.0.0`, none), and package-root URLs such as `…/@stagepass/loader@2` or `…/@stagepass/modules@2` (optional trailing slash / query). Package-root maps from each package’s `main` field (loader → `loader`, modules → `all`); there is no `unpkg` / `jsdelivr` / `exports` override in those packages. Recommended new embeds use `https://cdn.stagepass.one` (full file path, no `/dist/` segment).
182
185
  - Self-hosted: a Stagepass build filename under a `/stagepass/` path segment (relative or other-origin absolute), a relative `…/@stagepass/…` path (e.g. copied from `node_modules`), or the same filename on a `<script>` that also has a `data-stagepass-*` attribute; renamed loader files that carry a loader-config attribute (`data-stagepass-version`, `data-stagepass-live-src`, …). Result `cdn` is `self`. Bare `loader.js` / `all.min.js` from other libraries without a Stagepass hint are ignored. Absolute URLs on foreign hosts that only mimic an `@stagepass` CDN path (no `/stagepass/` segment and no data attribute) are ignored.
183
186
 
184
187
  Still not recognised: tags without `src`, `data-src` only, other hosts without a Stagepass hint, and module ids that cannot be inferred from the filename. `upgrade` syncs the detected modules list into the project; it does not rewrite self-hosted embeds to CDN URLs (printed Webflow snippets remain the recommended CDN form). The npm dependency in `package.json` is only a hint.
@@ -191,19 +194,32 @@ Still not recognised: tags without `src`, `data-src` only, other hosts without a
191
194
  | `--site <host>` | Live site to detect modules from (default: the origin linked in `~/.stagepass/projects.json` for this folder). Stored in `stagepass.json` when given. |
192
195
  | `--site-modules <list>` | Set the modules list directly (`none`, `all`, or a comma list). |
193
196
  | `--skip-site` | Do not fetch the live site. |
194
- | `-y, --yes` | Accept the detected or existing list without asking. With `--yes`, CLI 2.4.0 also replaces an unmodified `scripts/build.mjs`. |
197
+ | `-y, --yes` | Accept the detected or existing list without asking. Also replaces an unmodified `scripts/build.mjs`, and a hand-edited `AGENTS.stagepass.md`. Required for those replacements when there is no TTY. |
195
198
  | `--dry-run` | Print every planned change; write no file. |
199
+ | `--cursor-rule` | Write `.cursor/rules/stagepass.mdc` even when the project has no `.cursor/` directory. |
196
200
 
197
201
  `upgrade` bumps `@stagepass/*` in `package.json`, then resolves the modules list (`--site-modules`, else live detection, confirmed interactively; if the site is unreachable or no origin is known it asks; without a TTY it keeps the existing list or `[]` and prints a hint). It then syncs the project:
198
202
 
199
- - `stagepass.json`: writes the `modules` list.
200
- - `AGENTS.md`: created if missing, otherwise only the managed block is replaced (or appended when there is none). Your own text stays. Broken markers are left alone with a hint.
201
- - `.cursor/rules/stagepass.mdc`: created if missing, otherwise only its managed block is refreshed.
202
- - `tsconfig.json` / `jsconfig.json`: only `compilerOptions.types` changes, the rest of the JSON is preserved. Files with comments, or without a `types` array, are skipped with a hint.
203
- - `scripts/build.mjs`: CLI 2.4.0 replaces it when it is still an unmodified scaffold from an earlier CLI (line endings ignored; `src/main.js` / `src/main.ts` and `src/styles.css` / `src/styles.scss` still count). The interactive prompt defaults to yes. Without a TTY, and with `--yes`, the file is replaced. `--dry-run` writes nothing. An edited script is left unchanged and the CLI prints what `stagepass build`, `stagepass watch` and `stagepass dev` do now. A missing script stays missing. Published CLI 2.3.1 does not replace that file.
204
- - `.htaccess`: since 2.4.1, when `stagepass.json` has `"php": true` and the project root has no `.htaccess`, upgrade writes the shipped template (same bytes as `stagepass new --php`). An existing file is not modified. If it has no `RewriteRule "(^|/)\." - [F]` line, a hint points at https://stagepass.one/docs/php/ and `api/README.md` and the command still exits 0. A symlink or directory at that name is left in place. Projects without `"php": true` are unchanged. `--dry-run` writes nothing. Published CLI 2.4.0 does not write this file.
203
+ - `stagepass.json`: writes the `modules` list. Reads `cdn` (`stagepass` or `jsdelivr`; missing or unknown values use the Stagepass CDN) so `AGENTS.stagepass.md` and the printed snippets share that host and one sanitized loader pin.
204
+ - `AGENTS.stagepass.md`: created when missing. Rewritten when the managed hash still matches and the generated text changed. A hand edit (hash mismatch, or no `stagepass:managed` header) is replaced only with `--yes` or a TTY confirmation (default yes). Without a TTY and without `--yes`, the file stays and the CLI prints a hint that names `--yes`. A second run writes nothing when the file is already current. A symlink is left unchanged.
205
+ - `AGENTS.md`: created if missing (title plus the short pointer). Otherwise only the pointer between the markers is replaced, or appended when there are none. Text outside the markers stays byte for byte, including older generated sections. Upgrade prints a hint when those older sections are still outside the markers. Broken markers are left alone with a hint.
206
+ - `.cursor/rules/stagepass.mdc`: not created unless `.cursor/` already exists or `--cursor-rule` is set. An existing rule is never deleted. With stagepass markers, only the managed block is refreshed (`alwaysApply: true`, pointer to `@AGENTS.stagepass.md`). The previous generated frontmatter (`globs: src/**`, `alwaysApply: false`) is updated when it is still unchanged. A rule without markers is left alone. `stagepass doctor` does not warn about a missing rule when `.cursor/` is absent. When `.cursor/` exists, a missing or stale rule is a warning.
207
+ - `CLAUDE.md`: when the file already exists, the same short pointer is inserted or refreshed. The file is not created.
208
+ - `tsconfig.json` / `jsconfig.json`: a plain JSON file that already has `compilerOptions.types` is updated in place. The rest of the JSON is preserved. Comments, invalid JSON, and a missing `types` array are not edited. See [Types in existing projects](#types-in-existing-projects).
209
+ - `scripts/build.mjs`: replaced when it is still an unmodified scaffold from an earlier CLI (line endings ignored; `src/main.js` / `src/main.ts` and `src/styles.css` / `src/styles.scss` still count). The TTY prompt defaults to yes. `--yes` replaces it without asking, including when there is no TTY. Without a TTY and without `--yes`, the file stays and the CLI prints a hint that names `--yes`. `--dry-run` writes nothing. An edited script is left unchanged and the CLI prints what `stagepass build`, `stagepass watch` and `stagepass dev` do now. A missing script stays missing. Published CLI 2.3.1 does not replace that file. CLI 2.4.1 and older replace it even without a TTY and without `--yes`.
205
210
 
206
- Every change is printed as `file: action` (unchanged files are not listed; skipped files appear as hints). `npm install` is printed, not run. Snippets use the major pin `@2` plus an optional exact pin note.
211
+ Those two replacements (`scripts/build.mjs` when it is still a known scaffold, and `AGENTS.stagepass.md` when it was edited by hand or has no managed header) are the upgrade writes that wait for a TTY answer or `--yes`. A managed `AGENTS.stagepass.md` whose hash still matches is refreshed without asking. The others stay non-interactive, with or without a TTY: `package.json` range updates, missing `@stagepass/loader` and `@stagepass/modules` devDependencies (an existing spec is not removed), `stagepass.d.ts` when the file is missing or already has the `// @stagepass-types` marker, and a missing `.htaccess` when `"php": true`. Those do not replace a hand-edited source file. A custom `scripts/build.mjs`, a `stagepass.d.ts` without the marker, and an existing `.htaccess` stay as they are. `upgrade --json` matches CLI 2.4.0 and later: the flag is unknown, stdout is empty, and nothing is written. There is no JSON object on that command.
212
+ - `.htaccess`: since 2.4.1, when `stagepass.json` has `"php": true` and the project root has no `.htaccess`, upgrade writes the shipped template (same bytes as `stagepass new --php`). An existing file is not modified. If it has no `RewriteRule "(^|/)\." - [F]` line, a hint points at https://stagepass.one/docs/php/ and `api/README.md` and the command still exits 0. A symlink or directory at that name is left in place. Projects without `"php": true` are unchanged. `--dry-run` writes nothing. CLI 2.4.0 and older do not write this file.
213
+
214
+ ### Types in existing projects
215
+
216
+ Since 2.5.0, when the editor reports `Cannot find name 'sp'` and the page still runs, run `stagepass upgrade`. CLI 2.4.1 and older only update a plain `compilerOptions.types` array. Upgrade writes `package.json` only. It does not run `npm install`.
217
+
218
+ 1. `stagepass upgrade` (`--dry-run` prints the plan and writes nothing). `@stagepass/loader` is added to `devDependencies` when it is missing. `@stagepass/modules` is added only when the declared module list is not empty. A plain `tsconfig.json` or `jsconfig.json` that already has a `types` array is updated. Otherwise upgrade writes `stagepass.d.ts` (first line `// @stagepass-types`) with `/// <reference types="..." />` lines, at the project root when that path is included, or under a directory `include` already covers. A config with comments or invalid JSON is not edited. If `include` or `files` would not cover the reference file, upgrade reports that and leaves the config unchanged. A `stagepass.d.ts` without the marker is left unchanged. With no `tsconfig.json` or `jsconfig.json`, the reference file is still written at the project root. Upgrade does not create a config. Editors load `stagepass.d.ts` only as part of a project, so the command prints a note (also on `--dry-run`): add a `jsconfig.json` or `tsconfig.json` that includes your sources, for example `{"include": ["src", "stagepass.d.ts"]}`, then run `stagepass upgrade` again. A missing `stagepass.json` does not skip this step.
219
+ 2. `npm install`
220
+ 3. In the editor command palette: `TypeScript: Restart TS Server`.
221
+
222
+ Every change is printed as `file: action` (unchanged files are not listed; skipped files appear as hints). `npm install` is printed, not run. CLI 2.6.0 (not yet published) prints snippets on the Stagepass CDN with an exact pin, plus a jsDelivr alternative line. With `"cdn": "jsdelivr"` the snippets use the major pin `@2` and an optional exact pin note.
207
223
 
208
224
  ### Domain argument (`link` / `unlink`)
209
225
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stagepass/cli",
3
- "version": "2.4.1",
3
+ "version": "2.6.0",
4
4
  "description": "Local Development Orchestrator for Webflow",
5
5
  "type": "module",
6
6
  "main": "bin/index.js",
package/src/cli.js CHANGED
@@ -326,10 +326,11 @@ export function createProgram(deps = {}) {
326
326
  'Bump @stagepass/*, sync project files, replace an unmodified scripts/build.mjs, add a missing PHP .htaccess, print Webflow snippets'
327
327
  )
328
328
  .option('--dry-run', 'Show changes without writing any file')
329
+ .option('--cursor-rule', 'Write .cursor/rules/stagepass.mdc even when .cursor/ is absent')
329
330
  .option('--site <host>', 'Live Webflow site to detect loaded modules from (https)')
330
331
  .option('--site-modules <list>', 'Modules the site loads: none, all, or inject,cookies,maintenance')
331
332
  .option('--skip-site', 'Do not fetch the live site')
332
- .option('-y, --yes', 'Non-interactive; accept detected or existing modules and an unmodified scripts/build.mjs')
333
+ .option('-y, --yes', 'Non-interactive; accept detected or existing modules and replace an unmodified scripts/build.mjs')
333
334
  .option(
334
335
  '--target <version>',
335
336
  'Target version, range or dist-tag; must be published on npm (default: ^<latest published 2.x>, ^2 offline)'
@@ -397,8 +398,10 @@ export function createProgram(deps = {}) {
397
398
  .option('--git', 'Initialize a git repository')
398
399
  .option('--no-git', 'Do not initialize git')
399
400
  .option('--remote <url>', 'Git remote URL (requires git)')
401
+ .option('--cursor-rule', 'Write .cursor/rules/stagepass.mdc even when .cursor/ is absent')
400
402
  .option('--install', 'Run npm install after scaffolding')
401
403
  .option('--no-install', 'Do not run npm install (default)')
404
+ .option('--cdn <host>', 'CDN for Webflow snippets: stagepass (default) or jsdelivr')
402
405
  .option('-y, --yes', 'Non-interactive; accept defaults for omitted flags')
403
406
  .option('--dry-run', 'Print the file plan without writing')
404
407
  .option('-v, --verbose', 'Show detailed output')
@@ -15,8 +15,8 @@ import {
15
15
  clearStaleDevPorts,
16
16
  } from '../lib/projects.js';
17
17
  import { applySiteBlock } from '../lib/apply-site-block.js';
18
- import { createLiveServer, resolveOutputDir } from '../lib/live-server.js';
19
- import { readStagepassJson } from '../lib/project-sync.js';
18
+ import { createLiveServer, resolveOutputDir, PHP_WATCH_DIRS } from '../lib/live-server.js';
19
+ import { phpFromStagepassConfig, readStagepassJson } from '../lib/project-sync.js';
20
20
  import { getCaddyfilePath, getProjectsPath, validateRoot } from '../lib/paths.js';
21
21
  import { isPidAlive, isValidDevPort } from '../lib/dev-port.js';
22
22
  import { ensureStagepassReady } from '../lib/ensure-running.js';
@@ -159,6 +159,7 @@ export async function dev(options = {}, deps = {}) {
159
159
  /** @type {NodeJS.Signals | null} */
160
160
  let stopSignal = null;
161
161
  let setupDone = false;
162
+ let phpLive = false;
162
163
 
163
164
  try {
164
165
  let project = await getProject(domain, projectsPath);
@@ -205,6 +206,9 @@ export async function dev(options = {}, deps = {}) {
205
206
  return 1;
206
207
  }
207
208
 
209
+ const stagepass = await readStagepassJson(cwd, fse);
210
+ phpLive = phpFromStagepassConfig(stagepass.data) === true;
211
+
208
212
  if (options.verbose) {
209
213
  log(chalk.dim(`Live reload watching ${outDir.rel}/ → https://${domain}/__stagepass/live`));
210
214
  }
@@ -213,6 +217,7 @@ export async function dev(options = {}, deps = {}) {
213
217
  const server = createServer({
214
218
  projectRoot: rootCheck.path,
215
219
  outDir: outDir.rel,
220
+ php: phpLive,
216
221
  log: options.verbose ? (m) => log(chalk.dim(m)) : () => {},
217
222
  });
218
223
  live = await server.listen(0);
@@ -343,6 +348,10 @@ export async function dev(options = {}, deps = {}) {
343
348
  });
344
349
 
345
350
  log(chalk.green(`Live reload on https://${domain}/__stagepass/live (127.0.0.1:${live.port})`));
351
+ if (phpLive) {
352
+ const names = PHP_WATCH_DIRS.map((dir) => `${dir}/`).join(' and ');
353
+ log(chalk.dim(`Live reload also watching ${names}`));
354
+ }
346
355
  if (options.verbose) {
347
356
  log(chalk.dim('Running: npm run watch'));
348
357
  }
@@ -20,8 +20,9 @@ import {
20
20
  printWebflowSnippets,
21
21
  } from '../lib/snippets.js';
22
22
 
23
- import { STAGEPASS_PACKAGES_VERSION } from '../lib/versions.js';
23
+ import { SNIPPET_LOADER_VERSION, normalizeCdnChoice } from '../lib/cdn-base.js';
24
24
  import { formatModules, normalizeModulesList } from '../lib/project-modules.js';
25
+ import { cursorDirPresent } from '../lib/project-sync.js';
25
26
  import { describeDetection, detectSite, normalizeSiteUrl } from '../lib/site-detect.js';
26
27
  import {
27
28
  PACKAGES_MAJOR_RANGE,
@@ -180,6 +181,19 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
180
181
  siteModules = parsed.modules;
181
182
  }
182
183
 
184
+ /** @type {string} */
185
+ let cdn = '';
186
+ if (options.cdn != null) {
187
+ const parsed = normalizeCdnChoice(options.cdn);
188
+ if (!parsed) {
189
+ return {
190
+ ok: false,
191
+ error: 'Invalid --cdn: use stagepass (default) or jsdelivr.',
192
+ };
193
+ }
194
+ cdn = parsed;
195
+ }
196
+
183
197
  /** @type {string} */
184
198
  let origin = '';
185
199
  /** @type {string} */
@@ -327,6 +341,32 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
327
341
  else log(chalk.yellow(` ${parsed.error}`));
328
342
  }
329
343
  }
344
+ if (!cdn) {
345
+ // Bound retries: an invalid answer (for example "n" after y/N prompts)
346
+ // must not spin forever and grow memory.
347
+ const maxAttempts = 5;
348
+ let attempts = 0;
349
+ while (!cdn) {
350
+ const raw = await ask(
351
+ rl,
352
+ 'CDN for Webflow snippets (stagepass | jsdelivr)',
353
+ 'stagepass'
354
+ );
355
+ const parsed = normalizeCdnChoice(raw);
356
+ if (parsed) {
357
+ cdn = parsed;
358
+ break;
359
+ }
360
+ attempts += 1;
361
+ log(chalk.yellow(' Use stagepass (cdn.stagepass.one) or jsdelivr.'));
362
+ if (attempts >= maxAttempts) {
363
+ return {
364
+ ok: false,
365
+ error: 'Invalid --cdn: use stagepass (default) or jsdelivr.',
366
+ };
367
+ }
368
+ }
369
+ }
330
370
  if (php === undefined) {
331
371
  php = await askYesNo(rl, 'Enable PHP for this project?', false);
332
372
  }
@@ -366,6 +406,8 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
366
406
  // The npm package (types) follows the declared list; keep the legacy default (included).
367
407
  if (siteModules.length > 0) modules = true;
368
408
 
409
+ if (!cdn) cdn = 'stagepass';
410
+
369
411
  // Non-interactive / --yes defaults
370
412
  if (!name) {
371
413
  return { ok: false, error: 'Project name is required (pass [name] or use a TTY).' };
@@ -438,8 +480,9 @@ export async function resolveNewOptions(nameArg, options = {}, deps = {}) {
438
480
  remote: remoteCheck.remote,
439
481
  install,
440
482
  dryRun: options.dryRun === true,
441
- loaderVersion:
442
- deps.packagesVersion || deps.cliVersion || STAGEPASS_PACKAGES_VERSION,
483
+ cursorRule: options.cursorRule === true,
484
+ loaderVersion: deps.packagesVersion || SNIPPET_LOADER_VERSION,
485
+ cdn,
443
486
  },
444
487
  };
445
488
  }
@@ -653,6 +696,9 @@ export async function createNew(nameArg, options = {}, deps = {}) {
653
696
  const targetDir = path.isAbsolute(config.dir)
654
697
  ? config.dir
655
698
  : path.resolve(cwd, config.dir);
699
+ if (config.cursorRule !== true) {
700
+ config.cursorRule = await cursorDirPresent(targetDir, fse);
701
+ }
656
702
 
657
703
  const templatesRootResolved = path.resolve(templatesRoot);
658
704
  const readTemplate = async (rel) => {
@@ -847,6 +893,10 @@ export async function createNew(nameArg, options = {}, deps = {}) {
847
893
  const snippets = buildWebflowSnippets({
848
894
  version: config.loaderVersion,
849
895
  moduleList: config.siteModules,
896
+ gitRemote: config.git ? config.remote || '' : '',
897
+ gitBranch: config.git ? 'main' : '',
898
+ projectName: config.name,
899
+ cdn: config.cdn,
850
900
  });
851
901
  printWebflowSnippets(snippets, log);
852
902
 
@@ -26,8 +26,24 @@ import {
26
26
  LAUNCH_AGENT_LABEL,
27
27
  } from '../lib/autostart.js';
28
28
  import { ensurePhpFpm } from '../lib/php-fpm.js';
29
+ import { buildOfficialHeadSnippets, printWebflowHeadSnippets } from '../lib/snippets.js';
30
+ import { declaredModules, readStagepassJson } from '../lib/project-sync.js';
29
31
  import { certsTrust, certsRenew } from './certs.js';
30
32
 
33
+ /**
34
+ * Loader plus the modules declared in this project's stagepass.json.
35
+ * @param {string} cwd
36
+ */
37
+ async function printStartHeadSnippets(cwd) {
38
+ const sp = await readStagepassJson(cwd);
39
+ const declared = declaredModules(sp.data);
40
+ const moduleList = Array.isArray(declared) ? declared : [];
41
+ printWebflowHeadSnippets(buildOfficialHeadSnippets({ moduleList }));
42
+ if (moduleList.length === 0) {
43
+ console.log('No modules are declared in stagepass.json.');
44
+ }
45
+ }
46
+
31
47
  const PORT_IGNORE = ['Google Chrome', 'Chrome Helper', 'OneDrive', 'Music', 'Safari', 'caddy'];
32
48
 
33
49
  /**
@@ -412,6 +428,7 @@ export async function start(options = {}) {
412
428
  return 1;
413
429
  }
414
430
  }
431
+ let kickstarted = false;
415
432
  try {
416
433
  await exec('launchctl', buildLaunchctlKickstartArgs(uid));
417
434
  if (!options.verbose) {
@@ -426,7 +443,7 @@ export async function start(options = {}) {
426
443
  chalk.green(`✔ kickstart gui/${uid}/${LAUNCH_AGENT_LABEL}`)
427
444
  );
428
445
  }
429
- return 0;
446
+ kickstarted = true;
430
447
  } catch (error) {
431
448
  if (!options.verbose) spinner.fail('launchctl kickstart failed.');
432
449
  console.log(
@@ -435,6 +452,10 @@ export async function start(options = {}) {
435
452
  console.log(chalk.dim('Falling back to direct caddy start...'));
436
453
  if (!options.verbose) spinner.start('Booting background services...');
437
454
  }
455
+ if (kickstarted) {
456
+ await printStartHeadSnippets(options.cwd || process.cwd());
457
+ return 0;
458
+ }
438
459
  }
439
460
 
440
461
  // Direct caddy start (no LaunchAgent)
@@ -454,6 +475,7 @@ export async function start(options = {}) {
454
475
  } else {
455
476
  console.log(chalk.green('✔ Stagepass is active.'));
456
477
  }
478
+ await printStartHeadSnippets(options.cwd || process.cwd());
457
479
  return 0;
458
480
  } catch (error) {
459
481
  if (!options.verbose) spinner.fail('Failed to start.');