diff --git a/.dockerignore b/.dockerignore index 68f69e40a..8d4915043 100644 --- a/.dockerignore +++ b/.dockerignore @@ -15,6 +15,14 @@ *.swp **/.DS_Store +# Instructions and settings for AI coding agents, read in a checkout and never +# at runtime. Only the top-level files are excluded here; qdb/ and docker/ are +# dropped from the web root by the Dockerfile, and profiles/generic/AGENTS.md +# must stay, because doctor setup copies it into every new site. +AGENTS.md +CLAUDE.md +.gemini + # Composer output — regenerated by `composer install` inside the image. vendor vendor/* diff --git a/.gemini/settings.json b/.gemini/settings.json new file mode 100644 index 000000000..5e535b215 --- /dev/null +++ b/.gemini/settings.json @@ -0,0 +1,5 @@ +{ + "context": { + "fileName": ["AGENTS.md", "GEMINI.md"] + } +} diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index d0cce1922..47c5a5a97 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -39,9 +39,10 @@ name: Build and push Docker image # extension and without it? # (noext + fallback + daemon modes) # -# The second is the one that guards the shim: every call site wired to the node -# database keeps a legacy path, and the suite pins both branches to the same -# observable behaviour. See qdb/tests/quanta/_bootstrap.php. +# The second is the one that guards the shim: every node-database method has a +# filesystem implementation (FilesDb) behind the extension-backed one +# (FilesDbExt), and the suite pins both to the same observable behaviour. See +# qdb/tests/quanta/_bootstrap.php. # # Running both suites on arm64 as well is not incidental: qdb mirrors PHP's # string hash, whose byte accumulation depends on the target's `char` diff --git a/.gitignore b/.gitignore index b37a4d789..85c131495 100755 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,7 @@ secrets.php *.key !**/*.pub.key .htpasswd + +# Personal agent instructions for one checkout. The shared ones are AGENTS.md +# (every tool) and CLAUDE.md, which imports it. +CLAUDE.local.md diff --git a/.htaccess b/.htaccess index 62c44473e..496a95ab2 100755 --- a/.htaccess +++ b/.htaccess @@ -19,9 +19,12 @@ RewriteRule ^(tmp)/(.*) static/tmp/%{HTTP_HOST}/files/$2 [NC] RewriteRule ^(thumbs)/(.*) static/tmp/%{HTTP_HOST}/thumbs/$2 [NC] RewriteRule ^(modules)/(.*) src/modules/$2 +# Real files of these types are never served. md covers the README and the +# AGENTS.md agent instructions that sit in the document root and in each site's +# folder; nginx denies them too (docker/nginx/snippets/deny-dev-files.conf). RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_URI} !boot\.(php) -RewriteCond %{REQUEST_URI} .*\.(php|inc|json|conf|lock|gitignore|doctor|htaccess) +RewriteCond %{REQUEST_URI} .*\.(php|inc|json|conf|lock|gitignore|doctor|htaccess|md) RewriteRule ^(.*)$ '/403' [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f diff --git a/AGENTS.md b/AGENTS.md new file mode 100644 index 000000000..ec44f8641 --- /dev/null +++ b/AGENTS.md @@ -0,0 +1,173 @@ +# AGENTS.md — Quanta CMS + +Instructions for AI coding agents (Codex, Claude Code, Copilot, Cursor, Gemini CLI, …) and for +anyone new to the codebase. This file is loaded into every agent session, so it stays short: the +details live in the documents under [Read more](#read-more). Open them when a task touches that area. + +## What Quanta is + +A PHP 8.5 CMS and framework with no SQL database. Every piece of content is a **node**: a +directory that holds a `data.json` (plus `data_.json` translations, attached files and +templates). Pages are written in **Qtags** (`[TAG|attr=value:target]`), a bracket markup that PHP +classes render. Behaviour is extended by **modules** that implement **hooks**. **qdb** is an +optional Rust PHP extension that indexes the node tree in shared memory; Quanta behaves the same +without it. + +## Repository map + +| Path | What it is | +|---|---| +| `src/boot.php` | Front controller: every non-static request and every `doctor` run goes through it | +| `src/autoload.php` | Class-map autoloader for `Quanta\Common\*` / `Quanta\Qtags\*`, then Composer | +| `src/modules//` | Core modules: `hooks/.hook.inc`, `classes/Common/`, `classes/Qtags/`, `tpl/`, `assets/` | +| `profiles/generic/` | Install profile, copied into a new site by `doctor setup` | +| `qdb/` | Rust extension `quanta_db.so`, daemon `qdbd`, monitor `qdbstat` — see `qdb/AGENTS.md` | +| `Dockerfile`, `docker/` | Base image (nginx + php-fpm + qdb) — see `docker/AGENTS.md` | +| `.htaccess` | Apache rules for native installs (`docker/nginx/quanta.conf` is the nginx equivalent; `quanta-nginx.conf` is an old sample) | +| `docs/site/` | Source of the static docs site; the files listed in `docs/.build-manifest` are generated from it | +| `docs/reference/` | Hand-written engine reference (not part of the docs site build) | +| `tests/` | `logger_test.php` only; the real suites live in `qdb/tests/` and `docker/tests/` | +| `doctor` | CLI entry point: `php doctor ` | + +Not in git: `sites/` (each site is its own repository), `vendor/`, `static/tmp/` (generated per +site), `.env`, `node_modules/`. + +## Commands + +Run from the repository root. `` is a directory name under `sites/`. + +```sh +composer install # PHP dependencies; also points git at .githooks/ +php doctor setup # create a site from a profile (interactive; --profile=generic) +php doctor check # rebuild class map, reindex + repair node links, rebuild CSS/JS bundles +php doctor class_map # rebuild the class map only +php doctor clear_cache # drop cached node paths and thumbnails +php -l # syntax check +vendor/bin/phpcs # lint (.phpcs.xml); see "Code style" before acting on it +php tests/logger_test.php # logger unit test +sh qdb/tests/run-in-docker.sh # qdb contract + Quanta parity suites, in Docker +sh docker/tests/run-tests.sh # container script tests +npm install && npm run docs:check # docs site: check links (docs:build regenerates docs/) +``` + +## How the engine works (one-minute version) + +- **Request:** `src/boot.php` builds an `Environment` (the host selects `sites//`), loads + modules, fires hooks `boot` → `load_includes` → JSON actions → `init`, closes the session, + renders `sites//index.html` through `Page` (Qtags expand here), then fires `complete`. +- **Hook:** a function `\Quanta\Common\_(Environment $env, array $vars)` in + `/hooks/.hook.inc`. Every module defining it runs: `environment` first, then core + modules alphabetically, then site modules. +- **Classes:** `Quanta\Common\X` lives in `classes/Common/X.class.php`, Qtag `Quanta\Qtags\X` in + `classes/Qtags/X.qtag.php`. The autoloader resolves them through a class map keyed by file + basename, so the basename must equal the class name. +- **Nodes:** the URL `/a/b/foo/` renders node `foo`. Only the last segment counts, so node names + are unique across a site. +- **Templates:** a node renders through the nearest `tpl.html` / `tpl-.html` … / `tpl^.html` in + its folder lineage, otherwise its body. +- **Qtags:** `[TAG|attr=value|flag:target]`; `{TAG…}` nests inside attributes. Innermost tags + render first, and passes repeat until nothing changes. + +## Rules that bite + +1. **New or renamed class → `php doctor class_map`.** The map is only rebuilt when it is + missing, so a new class is "not found" until then. Rebuild it; don't delete it on a shared volume. +2. **Changed module CSS/JS → `php doctor check`.** Pages use the aggregated + `css.min.css` / `js.min.js` bundles, not the module files. +3. **Qtag names are `UPPER_SNAKE`:** `[BODY_CLASSES]` → class `BodyClasses`. CamelCase in markup + maps to `Bodyclasses` and does not autoload. +4. **No `:` inside a Qtag attribute value** (the first `:` starts the target) and no `[ ] { }` + inside one tag except a nested `{…}` tag. +5. **Rendered HTML has all newlines stripped** before Qtags run: `//` comments in inline JS swallow + the rest of the script, and `
` loses its line breaks.
+6. **Any `[Xx…]` / `{Xx…}` text in output is parsed as a Qtag**, and unknown tags render as empty.
+   Escape user content with `Api::string_normalize()` or the `no_qtags` attribute.
+7. **Hook functions share one flat namespace.** Any function named `_` in a hook
+   file *is* a hook implementation, and two modules can't define the same function.
+8. **Hooks receive `$vars` by value** unless the function declares `array &$vars`. Change caller
+   state through the objects in `$vars` or through a `&$vars` signature.
+9. **Node storage goes through `$env->db()`** (`FilesDb`, or `FilesDbExt` when qdb is loaded).
+   Never call `\QuantaDb::` directly. Catch `FilesDbException`, never `QuantaDbException` (undefined
+   without the extension). Pass `'at' => $path` when you already hold the folder.
+10. **`FilesDb` and `FilesDbExt` must answer identically.** A db method change needs both classes
+    and the parity tests (see `docs/reference/recipes.md`).
+11. **`.htaccess` and `docker/nginx/quanta.conf` implement the same routes:** change both.
+12. **Every top-level file ships into the Docker image's web root** unless `.dockerignore`
+    excludes it.
+13. **Don't hand-edit generated files:** anything in `static/tmp/`, or the `docs/` files listed in
+    `docs/.build-manifest`.
+14. **Secrets live in the site's `.env`** (read with `$env->getData('KEY')`), never in code or
+    content. The pre-commit hook blocks credential-shaped strings.
+15. **The session is closed before the page renders:** session writes from a Qtag or template are
+    lost.
+16. **Rendering can write:** `[TEXT|tag=…]` creates a translation node on first render, and the
+    mail queue is sent during `init`. Don't assume a GET is read-only.
+
+## Code style (as practised)
+
+- Match the file you edit. Most PHP is Drupal-like: 2-space indent, `array()`, `TRUE`/`FALSE`/
+  `NULL`, docblocks such as `Implements hook_init().` with `@param Environment $env`. `.phpcs.xml`
+  asks for PSR-12, but the code predates it. Lint what you add; don't reformat untouched code.
+- `$env` is passed explicitly everywhere; there are no globals.
+- `t('Hello !name', array('!name' => $name))` only substitutes placeholders. Translated text is
+  `[TEXT|tag=key:Default]` markup.
+- Screen and log messages: `new Message($env, $text, Message::MESSAGE_WARNING)`. Structured logs:
+  `Logger::get('channel')->error('Charge failed {id}', array('id' => $id))`.
+- Comments explain *why*: config files and scripts carry a paragraph for each non-obvious line.
+  When you change such a line, update its comment.
+- Write the mechanism, not the instance: no hostnames, customer names, ticket ids or one
+  deployment's numbers in shared code, comments or docs. Use ``-style placeholders.
+
+## Security notes
+
+- `/qtag/` and `/q//…` render Qtags taken from the URL. A Qtag must enforce its own
+  access and must not change state just because it rendered.
+- The API router (`/api/…`) has no auth layer. Each `_api__` handler checks
+  `UserFactory::current($env)` and `NodeAccess::check()` itself.
+- Filter user input before it reaches HTML (`Api::filter_xss()`) or Qtag markup
+  (`Api::string_normalize()`).
+- Site folders sit under the web root. Both `.htaccess` and nginx refuse real `.php`, `.json`,
+  `.inc` and `.md` files, and nginx also denies dotfiles and other dev-file extensions. Under
+  Apache, any other file in a site folder can be fetched directly, so keep secrets out of node
+  folders.
+
+## Definition of done
+
+- **PHP in `src/`:** run `php -l` and `vendor/bin/phpcs` on the changed files, rebuild the class
+  map, and exercise the change on a scratch site (`php doctor  setup`). If you touched
+  `FilesDb*`, `Node*`, `NodeFactory`, `Environment` path code, jobs or the class map, also run
+  `sh qdb/tests/run-in-docker.sh parity`.
+- **qdb:** see `qdb/AGENTS.md`. **Docker / nginx / php-fpm:** see `docker/AGENTS.md`.
+- **Docs site:** run `npm run docs:build && npm run docs:check`, and commit the regenerated `docs/`
+  output with its source.
+- **Docs stay true:** update the document that describes what you changed (this file,
+  `docs/reference/`, `qdb/docs/`) in the same change.
+
+## Commits and pull requests
+
+Imperative, sentence-case subject with no prefix and no trailing period ("Rebuild the class map in
+place instead of deleting it"). The body explains why the change is needed and what was wrong
+before. Branches are kebab-case, and PRs target `master`.
+
+## Working inside a site
+
+A site (`sites//`) is a separate repository with its own `AGENTS.md`. New sites get it from
+`profiles/generic/`. For an existing site, copy it with
+`cp profiles/generic/AGENTS.md profiles/generic/CLAUDE.md sites//`. Site-specific conventions
+belong in the site's file, not here.
+
+## Read more
+
+- [docs/reference/architecture.md](docs/reference/architecture.md): boot sequence, `Environment`,
+  module loading, class map, hook mechanism and catalog, caches and generated state
+- [docs/reference/content-model.md](docs/reference/content-model.md): nodes on disk, names and
+  lookup, lineage, categories, status, permissions, users, site layout
+- [docs/reference/templates-and-qtags.md](docs/reference/templates-and-qtags.md): `index.html`,
+  template resolution, Qtag syntax and parser rules, writing a Qtag, tag catalog
+- [docs/reference/modules.md](docs/reference/modules.md): module anatomy and catalog, overrides,
+  assets, forms, actions, Shadow, API, jobs, mail, localization, doctor
+- [docs/reference/recipes.md](docs/reference/recipes.md): step-by-step checklists for common changes
+- [qdb/AGENTS.md](qdb/AGENTS.md), [qdb/docs/usage.md](qdb/docs/usage.md),
+  [qdb/docs/how-it-works.md](qdb/docs/how-it-works.md), [qdb/docs/api-contract.md](qdb/docs/api-contract.md)
+- [docker/AGENTS.md](docker/AGENTS.md), and [README.md](README.md) for Docker environment
+  variables and logging
diff --git a/CLAUDE.md b/CLAUDE.md
new file mode 100644
index 000000000..fa961de52
--- /dev/null
+++ b/CLAUDE.md
@@ -0,0 +1,4 @@
+@AGENTS.md
+
+
diff --git a/docker/AGENTS.md b/docker/AGENTS.md
new file mode 100644
index 000000000..f5a0b3456
--- /dev/null
+++ b/docker/AGENTS.md
@@ -0,0 +1,67 @@
+# AGENTS.md — Docker image and runtime
+
+Applies to `docker/`, the root `Dockerfile`, `.dockerignore` and the CI workflow. The
+repository-wide rules are in `../AGENTS.md`. User-facing behaviour (environment variables,
+`/docker-entrypoint.d/`, logging) is documented in `../README.md`. Keep it current when behaviour
+changes.
+
+## What the image is
+
+A base image: nginx + php-fpm + `qdbd`, supervised by supervisord. Application images `FROM` it
+and add only their site code. The root `Dockerfile` stages, in order:
+
+| Stage | Purpose |
+|---|---|
+| `qdb-builder` | Compiles `qdb/` (`cargo build --release --locked`). The target-dir cache is keyed by `PHP_VERSION`, so a stale Zend module API can't end up in the `.so` |
+| `php-builder` | Adds PHP extensions (gd, zip, calendar, intl) and records their runtime libraries |
+| `vendor` | `composer install --no-dev --no-scripts`, prunes Google API services, authoritative class map |
+| `squeeze` | Compresses `rclone` |
+| `base` | `debian:-slim` plus the PHP tree, nginx, supervisor and the qdb artifacts. No compiler. |
+
+## Rules
+
+- **The PHP version is an exact pin** (`ARG PHP_VERSION` in `Dockerfile`), and a PHP update is a
+  deliberate bump. `qdb/Dockerfile` builds the same minor; move it in step. `ext-php-rs` caps the
+  minor (see `qdb/README.md`). `DEBIAN_SUITE` must match the suite of the PHP image.
+- **Stay multi-arch clean** (amd64 + arm64, built natively in CI): no architecture-specific
+  downloads or binaries.
+- **PHP extensions go in `php-builder` only.** The runtime stage has no compiler, so `pecl` and
+  `phpize` don't work there.
+- **Any build-time `RUN` that starts PHP with the extension must end with `rm -rf /tmp/quanta_db`**,
+  otherwise a stale metrics arena is baked into the layer.
+- **`.dockerignore` is also the web-root exclusion list.** `COPY . /var/www/quanta/` puts
+  everything that survives it under the document root. Exclude new non-runtime files there.
+- **`.htaccess` ↔ `docker/nginx/quanta.conf`:** the vhost reproduces the Apache rewrite map one for
+  one (the table at the top of `quanta.conf`). Change both, and update that table.
+- **Every `location ^~` block re-includes the deny snippets** (`nginx/snippets/deny-dotfiles.conf`,
+  `deny-php.conf`, `deny-dev-files.conf`). Prefix matches skip regex locations, so without them the
+  denies don't apply there. The `/.well-known/` blocks are the deliberate exceptions: they can't
+  deny dotfiles.
+- **php-fpm:** `clear_env = no` in `php/zz-quanta.conf` is required so PHP sees `QUANTA_DB_ROOT`.
+  The pool files load in order `zz-quanta` < `zzy-autotune` (written at start by
+  `php-fpm-autotune.sh`) < a deployment's own `zzz-*`.
+- **`/healthz/fpm`:** `nginx -t` can't catch a wrong `fastcgi_param` there. A change is only
+  verified by a request that answers `pong`.
+- **supervisord:** `qdbd` starts first, then php-fpm, then nginx. Optional programs (the exporter,
+  the dashboard) exit 0 when not configured and use `autorestart=unexpected` + `exitcodes=0`, so
+  an opt-out doesn't crash-loop. Follow that pattern for new programs.
+- **Entrypoint (`docker-entrypoint.sh`):** does the per-site setup, then sources
+  `/docker-entrypoint.d/*.sh`, then `exec`s the CMD. Downstream images must not override
+  `ENTRYPOINT`. A new ini key whose value depends on the site directory needs its own `sed` next to
+  the existing `quanta-db.ini` rewrite. Run doctor there (and in `build-assets.sh`) with
+  `QUANTA_DOCTOR_AS_ROOT=1`: those scripts own the directories they just created and fix ownership
+  at the end. Replace files with a temp file + rename, never in place:
+  `static/` is a volume shared by every container of a site.
+- **Comments:** every file here explains why each non-obvious line exists and what broke without
+  it. Write new lines the same way, and update the comment when the line changes.
+
+## Test
+
+```sh
+sh docker/tests/run-tests.sh            # autotune + dashboard wrapper tests; any host, not run in CI
+sh qdb/tests/run-in-docker.sh parity    # builds the full image; also runs nginx -t, php-fpm -t, php -l
+DOCKER_BUILDKIT=1 docker build -t quanta-local:php8.5 .   # full build, from the repo root
+```
+
+For routing, header or php-fpm changes, also start the image and request the affected URLs
+(including `/healthz` and `/healthz/fpm`).
diff --git a/docker/CLAUDE.md b/docker/CLAUDE.md
new file mode 100644
index 000000000..fa961de52
--- /dev/null
+++ b/docker/CLAUDE.md
@@ -0,0 +1,4 @@
+@AGENTS.md
+
+
diff --git a/docs/qdb/api-contract.html b/docs/qdb/api-contract.html
index 3db93b2b7..0c9ab85ed 100644
--- a/docs/qdb/api-contract.html
+++ b/docs/qdb/api-contract.html
@@ -506,7 +506,7 @@ 

6. Configuration3. The data segment
   0  magic          AtomicU64   "QDBDAT1\0"
-   8  layout_version u32         = 2  (bumped when images were added)
+   8  layout_version u32         = 3  (2: images added; 3: image strings moved to a segment-wide table)
   12  _pad0          u32
   16  epoch          u64         must match the filename
   24  seg_size       u64         must match the real file size
diff --git a/docs/qdb/index.html b/docs/qdb/index.html
index aa97b14ce..b6b3b85cb 100644
--- a/docs/qdb/index.html
+++ b/docs/qdb/index.html
@@ -136,7 +136,7 @@ 

Configuration (php.ini, en quanta_db.root (required) -Data root (the site's db/ directory) +Data root: the site directory (sites/<host>) quanta_db.shm_dir @@ -349,11 +349,11 @@

Build & test (Docker)

Quanta call-site parity tests#

The conformance suite proves the extension obeys the contract. -tests/run-quanta-tests.sh proves Quanta obeys itself: every call site wired -to the node database keeps its original code as a fallback, and the two -branches must be indistinguishable from the outside. It boots a real -Environment against a throwaway site and runs the same assertions in three -modes — noext (the .so is not loaded at all), fallback, and daemon:

+tests/run-quanta-tests.sh proves Quanta obeys itself: every node-database +method has a filesystem implementation (FilesDb) behind the extension-backed +one (FilesDbExt), and the two must be indistinguishable from the outside. It +boots a real Environment against a throwaway site and runs the same assertions +in three modes — noext (the .so is not loaded at all), fallback, and daemon:

docker run --rm --entrypoint sh -v "$PWD/qdb/tests:/tests:ro" \
     <quanta-image> -c 'sh /tests/run-quanta-tests.sh'
 # QDB_MODES="noext fallback"  to restrict
diff --git a/docs/qdb/usage.html b/docs/qdb/usage.html index 2d35bdecd..78656e837 100644 --- a/docs/qdb/usage.html +++ b/docs/qdb/usage.html @@ -127,7 +127,7 @@

Configuration keysThe one configuration trap
// tests/php/04_concurrency.php — this ordering is load-bearing
 ini_set('quanta_db.lock_timeout_ms', '800');
 fresh_env();   // in daemon mode this awaits coherence, which resolves config
+

Running PHP as root#

+

php-fpm runs as the site's user, and everything the extension writes (lock dir +and lock files, metrics arena, node dirs and documents, trashbin dirs) has to +stay usable by it. A PHP process running as root, a CLI started with kubectl exec for example, therefore creates each of these as the owner of the +directory it goes in, using the Linux per-thread filesystem uid, not a chown +afterwards. Opening, renaming and removing existing entries keep root's own +rights. A lock file the site's user cannot open for writing, such as a root-owned +one left by an older build, is opened read-only: flock locks it all the same.

Container-level switches (not extension settings)#

Several environment variables in the Docker image look like extension config but are not. The extension has no enabled key and never reads any of these:

@@ -402,9 +410,9 @@

getRaw()
QuantaDb::getRaw(string $name, ?string $lang = null): ?string

The stored bytes, verbatim. One asymmetry worth knowing: on a document that does not parse, get()/getObject() throw CORRUPT_JSON but getRaw() does not — -it is the escape hatch for inspecting one. In daemon mode it returns '' (the -daemon does not retain the bytes of a document it could not parse); in fallback -mode it returns the actual bytes off disk.

+it is the escape hatch for inspecting one. It always reads the file, in daemon +mode too (segment layout 3 keeps either a document's image or its bytes, never +both), so it returns the actual bytes, those of a corrupt document included.

path(), exists(), meta()#

QuantaDb::path(string $name): ?string     // absolute directory path, or null
 QuantaDb::exists(string $name): bool
@@ -1054,6 +1062,7 @@ 

12. Limits3. Setup
  • Configuration keys
  • The one configuration trap
  • +
  • Running PHP as root
  • Container-level switches (not extension settings)
  • 4. The data model
  • 5. Reading
  • diff --git a/docs/reference/architecture.md b/docs/reference/architecture.md new file mode 100644 index 000000000..b3c098f4f --- /dev/null +++ b/docs/reference/architecture.md @@ -0,0 +1,190 @@ +# Architecture + +How a Quanta request runs: from the front controller through module loading, the class map and +hooks, to rendering. Paths are relative to the repository root. Code references name the file and +the function or method, not line numbers. + +## Request lifecycle + +The web server sends every non-static request to `src/boot.php` (`.htaccess`, +`docker/nginx/quanta.conf`). The `doctor` CLI includes the same file with `$doctor_cmd` set. +`boot.php` does this, in order: + +1. `require_once` of `DataContainer`, `Environment`, `Logger` (PHP errors go to the JSON logger + from here on) and `UserFactory`. These load outside the class map on purpose, because on a fresh + site the map doesn't exist yet. +2. `new Environment($host, $request_uri, $docroot)` parses the request (see below). +3. `src/autoload.php` registers the class-map autoloader, then Composer's `vendor/autoload.php`. +4. `$env->load()` discovers and loads the modules. If `CLASS_MAP_FILE` doesn't exist, it calls + `$env->mapClasses()`. +5. `$env->startSession()`. +6. `FileFactory::checkFile()` / `FileFactory::downloadPdf()` serve a node attachment and exit + when the request is for one. +7. Hook **`boot`**. Most routing happens here: `api_boot` handles `/api/…`, `form_boot` validates + and submits Qtag forms, `shadow_boot` switches to the overlay UI, `environment_boot` reads the + site's `.env`. +8. Hook **`load_includes`** registers CSS/JS (skipped when `$_REQUEST['ajax']` is set). +9. If run by `doctor`: `new Doctor(...)->cure()` runs the command and exits. +10. `$env->checkActions()`: if the POST field `json` carries `action.value`, it fires + **`action_`** and exits (see `modules.md#json-actions`). +11. Hook **`init`**. `page_init` creates the `Page` and `mail_init` sends the mail queue. + `feeds_init` (`/feeds/`) and `shadow_init` (overlay requests) render their own output + and exit. +12. `$env->closeSession()` releases the session lock **before** rendering, so concurrent requests + from one user don't serialise. Session writes after this point are lost. +13. `print $env->getData('page')->render()`. `Page::buildHTML()` loads `sites//index.html` + (or only the current node for `?ajax=1`) and fires `page_preload`, `page_init`, + `body_classes`, `page_after_build`, `page_complete` (where `qtags_page_complete` expands all + Qtags) and `page_render`. +14. Hook **`complete`**, then `exit()`. + +`boot.php` also defines the global `t()` helper (`Localization::t()`). + +## Environment + +`Quanta\Common\Environment` (`src/modules/environment/classes/Common/Environment.class.php`) is +the per-request context. It is a `DataContainer`: `setData($key, $value)`, +`getData($key, $default)` (a stored `NULL` reads back as the default) and `addData()` (merges +arrays, adds numbers, concatenates strings). Everything receives it explicitly as `$env`; there is +no global. + +**Request fields:** `$env->host` (`HTTP_HOST` without the port), `$env->request_uri` (no query +string; `/` becomes `/home/`), `$env->request` (the URI split on `/`), `$env->request_path` (the +last segment, which selects the node), `$env->query_params`, `$env->request_json` +(`json_decode($_REQUEST['json'])`). + +**Directories** (`$env->dir[...]`, set in the constructor): + +| Key | Path | +|---|---| +| `quanta` | repository root | +| `docroot` | `sites/` | +| `db` | `sites//db` | +| `users` | `sites//db/_users` | +| `statuses` | `sites//db/_statuses` | +| `tpl` | `sites//_tpl` | +| `modules_core` | `src/modules` | +| `modules_custom` | `sites//_modules` | +| `profiles` | `profiles` | +| `tmp` | `static/tmp/` | +| `tmp_files` | `static/tmp//files` (CSS/JS bundles) | +| `trashbin` | `static/tmp//trashbin` (deleted nodes) | +| `log` | `static/tmp//log` | + +Modules add more at boot with `$env->sysdir($name, $folder)` (under the docroot) and +`$env->tmpdir($name, $folder)` (under `tmp`): `cache`, `pages`, `system`, `languages`, +`translations`, `roles`, `mailqueue`, … + +**Site configuration:** `environment_boot` reads `sites//.env` (`KEY=VALUE` lines, `#` +comments) into environment data. Read values with `$env->getData('KEY')`. API keys, SMTP +credentials and JWT secrets come from here. + +**Storage accessor:** `$env->db()` returns the node-storage implementation: `FilesDbExt` when the +qdb extension class `QuantaDb` exists, otherwise `FilesDb`. Both are `require_once`d directly. See +`content-model.md#lookup` and `qdb/docs/usage.md`. + +Other notable methods: `nodePath($name)` (name → folder), `getContext()` / `setContext()` (the +current UI context, e.g. `node_edit`, `qtag`), `addInclude($path)` (register CSS/JS for the +bundle), `hook()`, `checkActions()`, `scanDirectory()`. + +## Modules + +A module is any directory in `src/modules/` (core) or `sites//_modules/` (site). There is no +manifest and no enable switch. + +- `Environment::load()` loads core first, then site modules. `scanDirectory()` returns them sorted, + and skips `.git`, `assets`, `files` and anything starting with `_`. **Rename a module to `_name` + to disable it.** +- Modules are keyed by name. A site module with the same name as a core module **replaces it + entirely**: the core hook file and classes are no longer loaded. +- Loading a module only `require_once`s `/hooks/.hook.inc`. Classes load lazily + through the class map. +- There is no dependency declaration (`dependsFrom()` exists but nothing calls it). Modules use + each other's classes freely. Some core code relies on other modules being present (e.g. `stats` + defines constants used during rendering), so don't disable core modules casually. + +Module anatomy and the full catalog are in `modules.md`. + +## Class map and autoloading + +- `CLASS_MAP_FILE` is `static/tmp//class_map.dat` (defined in `src/autoload.php`). +- `Environment::mapClasses()` lists `/classes/Common/` and `/classes/Qtags/` of + every loaded module, without recursing. It stores `[Common|Qtags][] = ` and writes the map to a temporary file that is renamed into place, so readers + never see a truncated map. +- The autoloader handles only three-part names, `Quanta\Common\X` or `Quanta\Qtags\X`. It loads + the map once per process and looks `X` up **case-sensitively**. +- So the class file's basename must equal the class name. The suffix (`.class.php`, `.qtag.php`, + `.interface.php`) is a convention, not a rule. Modules load in order (core, then site), so a + later file with the same basename wins: a site module can shadow a core class. +- **The map is rebuilt only when it is missing** (`boot.php`). After adding or renaming a class, + run `php doctor class_map` (or `check`). The Docker entrypoint runs `class_map` on every + start. + +## Hooks + +`Environment::hook($name, array &$vars = array())` calls every loaded module's function +`\Quanta\Common\_($env, $vars)` that exists: + +- **Order:** `environment` first, then the remaining modules in load order (core alphabetically, + then site modules). The list of implementers is cached per hook name for the request. +- **Return value:** `TRUE` if at least one module implemented the hook (`doctor` uses this to + report an unknown command). +- **Naming:** the hook file must declare `namespace Quanta\Common;`. The module name is a prefix, + not a separator, so `node_page_init` is module `node` implementing `page_init`, and `page_init` + is module `page` implementing `init`. Every function in a hook file whose name starts with + `_` is a candidate hook. All hook functions share one namespace, so names must be unique + across modules. +- **`$vars` and references:** `hook()` takes `$vars` by reference, but an implementer declared + as `function x_y(Environment $env, array $vars)` receives a copy. Changes reach the caller only + through objects inside `$vars` (`'node' => &$node`, `'form_state' => &$this`), through slots the + caller bound by reference, or when the implementer declares `array &$vars`. Hooks that collect + values (`api_routes`, for example) need `&$vars`. + +### Hooks fired by core + +| Area | Hooks | +|---|---| +| Boot | `boot`, `load_includes`, `init`, `complete` | +| Actions | `action_` (from `checkActions()`), `_complete` (e.g. `node_edit_complete`) | +| Page | `page_preload`, `page_init`, `body_classes`, `page_after_build`, `page_complete`, `page_render`, `metadata` | +| Nodes | `node_open` (after load; access sets `forbidden`), `node_build` (after JSON is read), `node_presave`, `node_save`, `node_after_save`, `node_delete`, `link_alter`, `list_item` | +| Users | `user_open`, `user_load`, `user_presave`, `user_save`, `user_after_save`, `user_login`, `user_wrong_login`, `user_logout`; `User::save()` also fires a hook named after the current context | +| Qtags | `qtag_preload` (before render: change attributes, deny access), `qtag` (after render) | +| Forms | `form_pre_validate`, `_form_pre_validate`, `form_validate`, `form_type__validate`, `_form_validate`, `form_submit`, `form_type__submit`, `_form_submit`, `form_type__after_submit`, `_form_after_submit`, `form_validation_errors`, `form_item_validate`, `_form_item_validate` | +| Shadow | `shadow_` (build overlay tabs), `shadow_
    _pre_validate` | +| API | `api_routes`, `api_get_`, `api_post_`, `api_put_`, `api_patch_`, `api_delete_` | +| Doctor | `doctor` (the `check` command), `doctor_` (`-` becomes `_`), `doctor_pre_setup`, `doctor_setup` | +| Other | `fallback_language`, `job_run_`, `mailform__send`, `feed_`, `feed__item`, `file_imported`, `google_doc_before_generate`, `google_doc_generated`, `google_doc_readed` | + +To list the implementers of a hook: `grep -rn "function [a-z_]*_(" src/modules sites//_modules`. + +## Caching and generated state + +- **Per-request cache:** `Cache::get($env, $bin, $key)` / `Cache::set(...)` keep values in + environment data for the current request only. Bins include `node`, `qtag`, `qtag_markup` + (identical Qtag markup renders once per request) and `access`. +- **Persistent, generated, never hand-edited** (all under `static/tmp//`): + - `class_map.dat` + - `cache/`: sharded symlinks from node name to folder, plus `__MISSING__` negative markers + - `files/css.min.css`, `files/js.min.js`: the bundles built by `doctor check` + - `thumbs/`: image thumbnails + - `trashbin/`: deleted nodes + - `doctor_recipe.txt`: its modification time is the cache-buster for `[JS|refresh]` +- `php doctor clear_cache` removes `cache/` and the thumbnails. A stale `__MISSING__` + marker can hide a node created behind Quanta's back until then. +- qdb's shared-memory index (when present) lives outside the tree; see + `qdb/docs/how-it-works.md`. + +## Logging and errors + +- `\Quanta\Common\Logger::get($channel)->info|warning|error(...)` writes one JSON object per line, + with PSR-3 levels and `{key}` placeholders from the context. PHP warnings and fatals go to the + same log on channel `php`. `QUANTA_LOG_LEVEL` and `QUANTA_LOG_OUTPUT` configure it (see + `README.md`). +- `new Message($env, $text, $severity, $type)` queues a message for the screen (`[MESSAGES]`) or + the log. Severities are `Message::MESSAGE_ERROR|WARNING|NOTICE|CONFIRM|GENERIC`; types are + `MESSAGE_TYPE_SCREEN|LOG|VALIDATION`. +- Storage errors throw `FilesDbException`. "Not found" is never an exception: you get `NULL`, + `FALSE` or an empty array. +- Action, API and form-async handlers answer by printing JSON and calling `exit`. diff --git a/docs/reference/content-model.md b/docs/reference/content-model.md new file mode 100644 index 000000000..8518b58b6 --- /dev/null +++ b/docs/reference/content-model.md @@ -0,0 +1,162 @@ +# Content model + +Quanta has no SQL database: the filesystem under `sites//` *is* the database. This document +covers what a node is on disk, how names map to folders, and how status, permissions, users and +languages are stored. + +## A site on disk + +``` +sites// site docroot (often its own git repository) +├── index.html page shell: every page renders inside it +├── .env KEY=VALUE configuration and secrets (never committed) +├── _modules// site modules (same layout as core modules) +├── _tpl/ template overrides by node name (_tpl.html, …) +├── files/ assets/ static files, served at /files/… and /assets/… +├── pages/ the profile's page tree (home, blog, …) +├── _components/ layout nodes (_header, _footer, _logo, …) rendered via Qtags +├── _system/ system nodes such as 403 and 404 +├── jobs/ job queue nodes (_jobs_todo, _jobs_done, _jobs_unknown) +└── db/ + ├── _users// one node per user + ├── _roles/ role nodes (anonymous, logged, admin) + ├── _languages/ language nodes (en, …) + ├── _translations/ i18n- nodes created by [TEXT] + └── _statuses/ workflow status nodes +``` + +`doctor setup` creates this tree from `profiles//` (it copies the profile's files) and +adds the system nodes, the `en` language, the roles and an `administrator` user. Generated state +for the site lives outside it, in `static/tmp//` (see `architecture.md`). + +## Nodes + +A **node** is a directory anywhere under the site docroot: + +| File | Meaning | +|---|---| +| `data.json` | the language-neutral document | +| `data_.json` | one translation per language (`data_en.json`, …) | +| `tpl.html`, `tpl-.html`, `tpl^.html`, … | templates for this node or its descendants (`templates-and-qtags.md`) | +| other files (`cat.jpg`, `report.pdf`) | attachments, listed by `[FILES]` and served at `//` | +| subdirectories | child nodes | +| symlinks to other node folders | categories / tags | + +Folders named `files` or `assets` are payload directories, not nodes, and are never listed as +children. + +**Standard JSON fields:** `Node::updateJSON()` writes `name`, `title`, `teaser`, `body`, `author`, +`thumbnail`, `timestamp`, `weight`, `status`. Optional `permissions` (below). Any other key is +custom data: read it with `$node->getAttributeJSON('key')` (escapes Qtag characters by default) and +write it with `$node->setAttributeJSON('key', $value)`, or show it with `[ATTRIBUTE|name=key]`. + +Example (`profiles/generic/pages/data.json`): + +```json +{"permissions":{"node_add":"admin","node_edit":"admin","node_delete":"admin","node_view":"anonymous"}, + "teaser":"Welcome in my blog","author":"administrator","body":"","title":"Blog", + "thumbnail":null,"timestamp":1541094900,"status":"node-status-published","breadcrumb_exclude":1} +``` + +## Names, URLs and lookup + +- **A node's name is its folder's basename, and it must be unique across the whole site.** Two + folders with the same name produce a "more than one folder" warning and an unpredictable result. + `Environment::getCandidatePath()` adds a suffix when creating a node whose name is taken. +- `NodeFactory::buildNode()` normalises new names with `Api::normalizePath()`: accents removed, + lowercase, spaces and `_` become `-`, anything outside `[a-z0-9-]` is dropped (unless + `skip_normalize` is passed). +- **URL → node:** only the **last** path segment matters. `/en/animals/cat/` and `/cat/` both + render node `cat`. A leading language segment (`/en/…`) sets the language. The web server forces + a trailing slash on extensionless URLs. +- Names starting with `_` are system/hidden nodes: excluded from listings by default, and never + "published" for anonymous visitors. A name starting with `-` never resolves (it always comes from + a caller concatenating onto an empty string). + +### Lookup + +Name → folder resolution (`$env->nodePath($name)` → `FilesDb::path()`) tries, in order: + +1. a per-request memo (hits and misses), +2. the shard symlink cache in `static/tmp//cache/` (with on-disk `__MISSING__` markers), +3. the qdb shared-memory index, when the extension is loaded and coherent (`FilesDbExt`), +4. `find` over the docroot, with a time budget. + +Consequences: + +- When you already know a node's folder, pass `'at' => $path` to the `$env->db()` methods so no + lookup runs. +- After moving or renaming a folder outside Quanta's API, clear the cached path + (`$env->nodePath($name, FALSE, TRUE)`) or run `php doctor clear_cache`. +- All node reads and writes go through `$env->db()`. Writes are locked and atomic (temp file + + rename). See `qdb/docs/usage.md` for the method list and semantics. + +## Working with nodes in PHP + +| Call | What it does | +|---|---| +| `NodeFactory::load($env, $name, $lang = NULL)` | Load by name, falling back to the fallback language when the translation is missing; fires `node_open` (access sets `$node->forbidden`) | +| `NodeFactory::loadOrCurrent($env, $name)` | Like `load`, but an empty name means the current node (what most Qtags use for their target) | +| `NodeFactory::current($env)` | The node selected by the URL (empty in the `node_add` / `qtag` contexts) | +| `NodeFactory::buildNode($env, $name, $father, $vars)` | Create and save a node under `$father` | +| `NodeFactory::fastLoadFromRealPath(...)` | Load from a known folder, skipping hooks and access checks (use with care) | +| `$node->save()` / `$node->delete()` | Persist (`node_presave` → `node_save` → `node_after_save`) / move to the trash bin (`node_delete`) | +| `$node->getFather()`, `getLineage()`, `hasParent($name)` | Parent, all ancestors from the docroot down, ancestry test | +| `$node->hasChildren()`, `hasChild($name)`; `$env->db()->children(...)` to list | Children (subfolders) | +| `$node->getCategories()` | Nodes linked into this one by symlink | +| `$node->exists`, `isNew()`, `isForbidden()`, `isPublished()`, `hasTranslation($lang)` | State checks | +| `NodeFactory::linkNodes()` / `unlinkNodes()` | Add / remove a category symlink | +| `$env->db()->move(...)` | Move a node folder (there is no `NodeFactory` wrapper) | + +The **father** is the parent folder; when the parent is the site docroot, the father is `home`. The +**lineage** is every ancestor folder, keyed by name, excluding the node itself. Lineage drives +template inheritance and permission inheritance. + +## Status and workflow + +`status` is one of `node-status-published`, `node-status-unpublished`, `node-status-draft` +(`Node::NODE_STATUS_*`). An empty status counts as published. The `workflow` module maps the +edit form's status field onto the node in `node_presave`. Status nodes live in `db/_statuses`. + +## Permissions + +`data.json` may contain `permissions` with the actions `node_view`, `node_add`, `node_edit`, +`node_delete`. Each value is a role name, an array of roles, `author` (the node's author), `self` +(the user *is* the node, or one of its ancestors), or `inherit`. + +- A missing or `inherit` value is taken from the nearest ancestor that sets it. With no value + anywhere, the default is `anonymous` for `node_view` and `admin` for everything else. +- `anonymous` grants everyone. Otherwise the user needs one of the listed roles exactly. Roles are + not hierarchical: `admin` doesn't satisfy a permission set to another role. +- Check in code with `NodeAccess::check($env, Node::NODE_ACTION_EDIT, array('node' => $node))` + (optionally `'user' => $user`). `duplicate` maps to `add` and `change_author` to `edit`. Results + are cached per request. +- View access is enforced on load (`access_node_open` sets `forbidden`). `node_page_init` then + redirects to `/403` or `/404`. +- `UserAccess::check()` covers user actions (`user_edit`, `user_edit_own`, `user_register`, …). +- Qtags can be shown or hidden per request with the `filter` attribute + (`templates-and-qtags.md#access-filters`). + +## Users and sessions + +- A user is a node in `db/_users//` (`class User extends Node`). Its JSON holds `roles`, + `password` (hashed by `UserFactory::passwordEncrypt()`), `email`, names and custom fields. +- The built-in roles are `anonymous`, `logged` and `admin` (`User::ROLE_*`). Logging in adds + `logged`. +- `UserFactory::current($env)` resolves the current user from the session, then from an + `Authorization: Bearer` JWT (HS256, secret `JWT_SECRET_KEY` from `.env`), and falls back to + anonymous. +- `$user->hasRole($role)`, `UserFactory::load($env, $name)`, `UserFactory::buildUser(...)`, + `UserFactory::getUserFromField(...)`. +- The session is started at boot and closed after the `init` hook, before render. Session writes + belong in `boot`/`init` hooks, actions or form handlers, not in Qtags or templates. + +## Languages and translations + +- Languages are nodes in `db/_languages/`. The current language comes from environment data, then + the session, then the fallback language (`Localization::getLanguage($env)`). +- A node's translations are its `data_.json` files. `NodeFactory::load()` falls back to the + fallback language when one is missing. +- Interface strings: `[TEXT|tag=key:Default text]` looks up node `i18n-` in + `db/_translations/` and **creates it on first render** if it is missing. `t()` only substitutes + `!x` / `%x` placeholders; it doesn't translate. diff --git a/docs/reference/modules.md b/docs/reference/modules.md new file mode 100644 index 000000000..ad08d8181 --- /dev/null +++ b/docs/reference/modules.md @@ -0,0 +1,218 @@ +# Modules + +How modules are put together, what each core module does, and the subsystems they provide: assets, +forms, actions, the Shadow overlay, the API router, jobs, mail and the `doctor` CLI. + +## Module anatomy + +``` +/ src/modules// (core) or sites//_modules// (site) +├── hooks/.hook.inc hook implementations, namespace Quanta\Common (the only file loaded eagerly) +├── classes/Common/.class.php \Quanta\Common\ (autoloaded via the class map) +├── classes/Qtags/.qtag.php \Quanta\Qtags\ (one Qtag per file) +├── tpl/*.tpl.php | *.inc | *.html Qtag-markup templates (not PHP) +└── assets/{css,js,img}/ served at /modules//assets/… +``` + +- There is no manifest: a directory is a module. A leading `_` disables it. +- Hook file header: `_(Environment $env, array $vars)`, each with an `Implements hook_().` + docblock. +- Class files: one class per file. The basename must equal the class name, and only the + `classes/Common` and `classes/Qtags` directories are mapped (not recursively). +- Templates are read with `file_get_contents` and rendered as Qtags, so PHP code in them is not + executed. +- Vendored front-end libraries live in the module's `assets/` (or `addons/`, as in + `form/addons/autocomplete`). + +## Site modules and overrides + +- Put site-specific code in `sites//_modules//`, never in `src/modules/`. +- A site module with a **new name** adds hooks, classes and Qtags. It loads after every core + module, so its hooks run last. +- A site module with the **same name as a core module replaces the core module completely**: + none of the core module's hooks or classes load. Copy everything you still need, or prefer a new + module that hooks in. +- A site class whose file basename equals a core class's overrides it in the class map. Use this + sparingly, because it silently shadows core code. + +## Core module catalog + +| Module | Purpose | +|---|---| +| `access` | Node and user permission checks (`NodeAccess`, `UserAccess`); the Qtag `filter=` attribute | +| `amp` | Google AMP rendering and AMP Qtags | +| `api` | `Api` utility class (`normalizePath`, `string_normalize`, `filter_xss`, validators, `minify`, `redirect`) and the `/api/` router; generic Qtags (`LINK`, `URL`, `VARIABLE`, `DATE`, …) | +| `block` | `BLOCK` (embed a node), `WRAPPER` | +| `blog` | `BLOG` list | +| `cache` | Per-request cache, node-path shard cache, `doctor clear_cache` | +| `captcha` | `CAPTCHA` Qtag and validation (secret from `.env`) | +| `carousel` | Image carousels | +| `doctor` | The `Doctor` CLI class, symlink repair, `doctor check` | +| `environment` | `Environment`, `DataContainer`, `JSONDataContainer`, `FilesDb` / `FilesDbExt`, `Logger`, `.env` loading, class map | +| `feeds` | RSS feeds at `/feeds/` | +| `file` | Uploads, attachments, file Qtags, serving node files | +| `fontawesome` | Icon Qtags | +| `form` | Qtag forms: `FormState`, `FormFactory`, field classes | +| `gallery` | Image gallery of a node | +| `googleclient`, `googledrive`, `googledocs` | Google OAuth client, Drive permissions, Docs generation/reading | +| `grid` | CSS grid framework and the `grid=` attribute | +| `image` | Images and thumbnails (`static/tmp//thumbs`) | +| `import` | CSV import of an attached file on save (`file_imported` hook) | +| `integrity` | Repair of translated sub-nodes (`doctor integrity_check`) | +| `jobs` | File-based job queue | +| `jquery` | jQuery, jQuery UI, and `engine.js` (the client side of JSON actions) | +| `jumper` | Quick-navigation dropdown | +| `list` | Node, tree and file lists (`DirList`, `FastDirList`, `FileList`); drag-sorting | +| `localization` | Languages, `[TEXT]` translations, language switcher | +| `mail` | `Mail` (PHPMailer over SMTP), the `_mailqueue`, `MAIL_FORM` | +| `map` | Google Maps | +| `media` | Audio/video players and playlists | +| `menu` | `MENU` | +| `message` | Flash messages (`Message`, `[MESSAGES]`) | +| `meta` | `` meta tags (`[META_DATA]`, `metadata` hook) | +| `node` | `Node`, `NodeFactory`, `NodeTemplate`, node CRUD actions and edit forms | +| `page` | `Page` (the `index.html` shell), layout Qtags, CSS/JS bundle build, profile install | +| `qtags` | `QtagFactory`, base `Qtag` / `HtmlTag`, the `/q/` and `/qtag/` endpoints | +| `shadow` | The overlay editing UI ("Shadow") | +| `sitemap` | XML sitemap | +| `social` | Share buttons, YouTube embeds | +| `stats` | Page timing (`STATS`, admin only); defines constants used elsewhere, so keep it enabled | +| `sync` | `doctor rsync`: copies a site's `db/` between environments with a deployment-specific script | +| `user` | `User`, `UserFactory`, login/registration/profile forms and actions, JWT bearer auth | +| `workflow` | Node status (draft / unpublished / published) | +| `wysiwyg` | CKEditor 5, loaded only when the Shadow editor is open | + +## CSS and JavaScript + +- Register a file for the bundle with `$env->addInclude($path)` in `_load_includes` (the + type comes from the extension). `load_includes` doesn't run on `?ajax` requests. +- `php doctor check` concatenates and minifies every include into + `static/tmp//files/css.min.css` and `js.min.js`. **Edits to module assets are not live + until it runs** (Docker images build the bundles at image build time with + `quanta-build-assets`). +- `[CSS|runlast]` inlines the CSS bundle into a `