@plitzi/sdk-mcp 0.38.24 → 0.39.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +156 -1
  2. package/dist/createServer.js +1 -0
  3. package/dist/modules/mcp/catalogs/index.d.ts +1 -1
  4. package/dist/modules/mcp/catalogs/index.js +2 -2
  5. package/dist/modules/mcp/catalogs/pluginCatalog.js +5 -1
  6. package/dist/modules/mcp/handler.d.ts +3 -1
  7. package/dist/modules/mcp/handler.js +32 -2
  8. package/dist/modules/mcp/helpers/guide/index.d.ts +3 -0
  9. package/dist/modules/mcp/helpers/guide/index.js +19 -0
  10. package/dist/modules/mcp/helpers/{guide.d.ts → guide/instructions.d.ts} +0 -1
  11. package/dist/modules/mcp/helpers/guide/instructions.js +106 -0
  12. package/dist/modules/mcp/helpers/guide/logic.d.ts +2 -0
  13. package/dist/modules/mcp/helpers/guide/logic.js +166 -0
  14. package/dist/modules/mcp/helpers/guide/practice.d.ts +2 -0
  15. package/dist/modules/mcp/helpers/guide/practice.js +123 -0
  16. package/dist/modules/mcp/helpers/guide/reference.d.ts +2 -0
  17. package/dist/modules/mcp/helpers/guide/reference.js +249 -0
  18. package/dist/modules/mcp/helpers/guide/server.d.ts +2 -0
  19. package/dist/modules/mcp/helpers/guide/server.js +252 -0
  20. package/dist/modules/mcp/helpers/guide/structure.d.ts +2 -0
  21. package/dist/modules/mcp/helpers/guide/structure.js +187 -0
  22. package/dist/modules/mcp/helpers/guide/styling.d.ts +2 -0
  23. package/dist/modules/mcp/helpers/guide/styling.js +118 -0
  24. package/dist/modules/mcp/helpers/guide/values.d.ts +2 -0
  25. package/dist/modules/mcp/helpers/guide/values.js +6 -0
  26. package/dist/modules/mcp/helpers/space.d.ts +5 -2
  27. package/dist/modules/mcp/helpers/space.js +5 -4
  28. package/dist/modules/mcp/resources/core.js +1 -1
  29. package/dist/modules/mcp/resources/index.d.ts +1 -1
  30. package/dist/modules/mcp/resources/primer.d.ts +0 -11
  31. package/dist/modules/mcp/resources/primer.js +46 -1
  32. package/dist/modules/mcp/resources/register.js +1 -1
  33. package/dist/modules/mcp/server.js +17 -8
  34. package/dist/modules/mcp/tools/apply/index.d.ts +19 -0
  35. package/dist/modules/mcp/tools/index.js +2 -0
  36. package/dist/modules/mcp/tools/operations/actions/document.d.ts +3 -0
  37. package/dist/modules/mcp/tools/operations/actions/document.js +5 -2
  38. package/dist/modules/mcp/tools/operations/actions/index.d.ts +6 -0
  39. package/dist/modules/mcp/tools/operations/actions/patchAction.d.ts +3 -0
  40. package/dist/modules/mcp/tools/operations/actions/upsertAction.d.ts +3 -0
  41. package/dist/modules/mcp/tools/operations/index.d.ts +64 -0
  42. package/dist/modules/mcp/tools/operations/schema/operations.d.ts +13 -0
  43. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +13 -0
  44. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +25 -1
  45. package/dist/modules/mcp/tools/render.d.ts +13 -0
  46. package/dist/modules/mcp/tools/renderWidget.d.ts +13 -0
  47. package/dist/modules/mcp/tools/shared/lintDraft.js +5 -0
  48. package/dist/modules/mcp/tools/shared/tool.d.ts +6 -0
  49. package/dist/modules/mcp/tools/shared/validator/connectors.js +0 -1
  50. package/dist/modules/mcp/tools/shared/validator/css.js +6 -1
  51. package/dist/modules/mcp/tools/test.d.ts +23 -0
  52. package/dist/modules/mcp/tools/test.js +85 -0
  53. package/dist/modules/mcp/types/aiSchema.d.ts +2 -0
  54. package/dist/modules/mcp/types/previewTypes.d.ts +3 -2
  55. package/dist/modules/mcp/types/toolTypes.d.ts +5 -0
  56. package/dist/preview/createPreview.js +4 -2
  57. package/package.json +8 -8
  58. package/dist/modules/mcp/helpers/guide.js +0 -1139
@@ -0,0 +1,123 @@
1
+ import { MOTION_ENTERS, MOTION_LOOPS } from "@plitzi/sdk-authoring";
2
+ //#region src/modules/mcp/helpers/guide/practice.ts
3
+ /** Good practice: motion, accessibility and semantics. */
4
+ var practiceGuide = `## Motion — good practices
5
+ A preset first: an element's \`motion\` field (\`upsertElement\`/\`patchElement\`) —
6
+ \`{ "enter": "fade-up", "on": "view" }\`, \`"stagger": 60\` for its children one by one, \`"easing"\`/\`"distance"\` (px) for a reference's own curve and travel, \`"loop": "float"\` — is
7
+ played by the SDK, cheap and stilled for reduced motion. \`on\`: \`load\` (default), \`view\` (once, the first time it
8
+ comes into view, then it stays) or \`scroll\` (follows the scroll both ways — it fades back out as the reader scrolls
9
+ up past it; only for an effect that is about the scroll itself). Enters: ${MOTION_ENTERS.join(", ")}; loops:
10
+ ${MOTION_LOOPS.join(", ")}. Beyond them, keyframes go in \`customCss\` (\`patchSettings\`), a
11
+ definition names them (\`animation\`). Only \`opacity\` and
12
+ \`transform\` (\`translate\`, \`scale\`, \`rotate\`) animate off the main thread: they stay smooth while the page
13
+ hydrates and on a slow phone. Anything else repaints or lays the page out again on every frame, and freezes while the
14
+ page's scripts run.
15
+ - Slide, grow, fade with \`transform\` and \`opacity\` — never \`left\`, \`top\`, \`width\`, \`height\` or
16
+ \`margin\`. Something travelling across a box is \`transform: translate(%)\` on an element as large as the box.
17
+ - No animated blur: no \`filter: blur()\` in an entrance or a loop, no \`backdrop-filter\` over moving content. A soft
18
+ shape is a \`radial-gradient\` fading to transparent.
19
+ - Fake the expensive ones: a growing shadow is a second shadow on a pseudo-element whose \`opacity\` changes; a
20
+ pulsing glow is a static gradient whose \`opacity\` or \`scale\` changes.
21
+ - Decoration that must animate something else (a custom property, \`background-position\`) starts paused and runs
22
+ once the page is hydrated: \`.glow { animation: glow 8s linear infinite paused; } [data-hydrated] .glow {
23
+ animation-play-state: running; }\` in \`customCss\`. That is for loops: an entrance of its own that plays once
24
+ (\`transform\`/\`opacity\` only) plays from the first paint with \`backwards\`, never gated on \`[data-hydrated]\`.
25
+ - Entrances: \`opacity\` + a small \`translateY\`, under ~600ms, staggered by tens of ms.
26
+ - One slow ambient loop per screen at most — not one per card: \`infinite\` runs on every visitor's battery.
27
+ - Name what transitions (\`transition: transform 200ms, opacity 200ms\`), never \`all\`; \`will-change\` only on the
28
+ few elements about to move.
29
+ - Reduced motion is the SDK's: it cuts every animation to an instant for whoever asks — never write that reset.
30
+
31
+ ## Accessibility — pages people, screen readers and browser agents can all use
32
+ A page is read three ways: seen, heard through a screen reader, and worked by a **browser agent** (Claude in Chrome)
33
+ — which finds the controls it can press in the same **accessibility tree** a screen reader walks. A control that
34
+ tree names nothing is invisible to both, however it looks. So build every page to be operable without sight:
35
+ - **Every control has words.** A \`button\` is named by its \`content\` and the words inside it; an icon-only one needs a
36
+ \`title\` (also its tooltip), and one whose words do not say what it does (a key hint, a count) a \`label\`. A \`link\` is named by what it holds, or \`label\` (set it on a link wrapping a whole card).
37
+ A \`formControl\` is named by its \`label\` — keep it and set \`hideLabel: true\` when the design shows what the field
38
+ is (a swatch, a search box); a \`placeholder\` names only a field typed into, and only until something is typed.
39
+ - **Every picture says what it shows** (\`alt\`), or is marked \`decorative: true\` when the words beside it already say
40
+ it. A \`fontAwesome\` icon is decoration (hidden) unless its \`label\` gives it a meaning of its own.
41
+ - **Only controls are clicked.** A click flow belongs on a \`button\` (it holds children — a whole card can be one) or
42
+ a \`link\` when it goes somewhere — never on a \`container\`, \`text\` or \`image\`: a keyboard cannot reach those and
43
+ no agent finds them. An empty backdrop that closes a panel is the exception (the panel's close button and Escape
44
+ are the ways everyone has).
45
+ - **State is said, not only styled.** A toggle sets \`ariaPressed\`, a button that opens a panel \`ariaExpanded\`
46
+ (bind them like any attribute) — an "active" class alone is invisible to both readers. A button that shows and
47
+ hides a panel names it in \`controls\` (\`aria-controls\`, the panel's anchor), and words that change while a
48
+ visitor reads them — a count, a total, a status — sit in a \`container\` with \`live: "polite"\` (\`aria-live\`).
49
+ - **A dropdown opens from a \`button\`** among its children, outside the popup (an avatar, a "⋯": the button holds it and
50
+ has a \`title\`). The dropdown marks it and moves the focus in and out; a box or an icon alone opens nothing from a
51
+ keyboard.
52
+ - **An illustration** built from elements (a mock of a page, art) is a \`container\` with \`decorative: true\`: both
53
+ readers skip it. Keep controls out of it.
54
+ - **The page has an outline.** Headings go down one level at a time (h1 → h2 → h3; size them with their class, not
55
+ their level). Landmarks are containers with a tag — \`header\`, \`nav\`, \`main\`, \`aside\`, \`footer\` — and a
56
+ \`label\` when a page has two of one kind; a \`section\` with a \`label\` is a region an assistant can jump to.
57
+ - **What comes built in:** modals and dialogs are \`dialog\`s named by their title, take the focus, keep Tab inside
58
+ and close on Escape; tabs are a tab list worked with the arrow keys; a field that breaks a rule is marked invalid and
59
+ described by its message; the pager marks the current page. Nothing to add for those.
60
+ - **A canvas is a picture** to both readers. A plugin that draws (a chart, a board, a map) also renders what it shows
61
+ as real elements — a list, a table — with a button for every action; one hidden until focused cannot be clicked by an
62
+ agent that clicks by position, so offer a visible "list view".
63
+ The linter warns about these (\`control-without-name\`, \`image-without-alt\`, \`click-on-static-element\`,
64
+ \`dropdown-without-control\`, \`heading-level-skipped\`, \`label-ignored\`, \`control-in-decorative\`) on every element
65
+ you touch; fix them in the same batch. Then look:
66
+ \`plitzi_look\` shows the page as those readers get it, and lists what has no name.
67
+
68
+ ## Semantics
69
+ - **props are fully replaced** on \`upsertElement\`: send every prop you want to keep. To change only some props,
70
+ use **\`patchElement\`** — it merges \`props\`/\`style\` onto the existing element (listed keys change, \`null\` unsets
71
+ a key, everything else is preserved) and never creates. Combined with \`plitzi_search\` (which returns the ref +
72
+ stateVersion), a targeted edit is two calls with no read.
73
+ - **definition CSS is fully replaced** on \`upsertDefinition\`: send every property you want to keep. To change only
74
+ some declarations, use **\`patchDefinition\`** — it merges CSS per breakpoint/state/variant/slot onto the existing
75
+ definition (listed keys change, \`null\` removes a property, everything else is preserved) and never creates.
76
+ Example — recolor one definition without resending it: \`{ "type": "patchDefinition", "ref": "btn-x",
77
+ "desktop": { "background-color": "#111" } }\`.
78
+ - **Atomic batches**: if any operation fails, \`plitzi_apply\` persists nothing.
79
+ - **Every element you touch must be malformation-free — pre-existing errors block the save.** When your batch edits
80
+ an element, the result is read by the same linter every writer of a space is held to, and the element's **current
81
+ stored content** with it — a broken transformer action, a malformed step, an attribute it never reads — even in
82
+ parts your edit does not touch. Such a finding is reported as a \`Pre-existing malformation in element …\` **error**, and
83
+ \`plitzi_apply\` rejects the batch until it is fixed. These are **not caused by your change** (the message says so)
84
+ — do not be confused; fix them **in the same batch** and re-apply. Because the check runs on the resulting state,
85
+ including the fix in your batch is exactly what unblocks the save. (Advisory issues — an unobserved source/action
86
+ name that may still be a valid plugin, a binding target a plugin manifest does not list — come back as
87
+ \`Pre-existing issue …\` **warnings** and do not block.) Elements you do not touch are not held against you — except
88
+ that a broken tree your batch leaves anywhere (an element orphaned by a delete) is refused.
89
+ - **Optimistic concurrency — read before you write, and prove your read is current.** Editing a resource means you
90
+ read it first, so you hold its \`stateVersion\`. **Always pass \`expectedResourceVersions\`** (URI → the stateVersion
91
+ you read) for every resource your batch changes. If another agent edited it in the meantime, the live version no
92
+ longer matches and apply is **rejected with a conflict** — nothing persists. Then re-read the reported resources
93
+ (their new content + version) and retry on top of the fresh state. This is exactly how a file editor forces a
94
+ re-read after a stale write: it is what keeps concurrent agents from silently overwriting each other's changes, so
95
+ never omit it "to save a call".
96
+
97
+ ## The space's own tests — \`plitzi_test\`
98
+ A space keeps its tests in its document, and **a snapshot and a publish wait for them**: what you change must leave them
99
+ passing. Two kinds — the builder calls them **element checks** (unit) and **journeys** (e2e: what a visitor does, from
100
+ start to end — not an interaction's flow). \`plitzi_test { action: 'list' }\` says them and how the element checks
101
+ stand; \`run\` plays the journeys on the draft, where the deployment has a browser — one play at a time per space, each
102
+ journey counted against the plan's month (a refusal says why, and when it comes back). Write them whole with \`set\`:
103
+ - \`unit\`: \`{ id, title, element, given: { state, sources }, expect: [{ kind: 'visible' | 'attribute' | 'style' |
104
+ 'variant' | 'state', … }] }\` — one element resolved for a state, no browser.
105
+ - \`e2e\`: \`{ id, title, page, width, steps: [{ kind: 'click', element }, { kind: 'expectText', element, text }, …] }\`
106
+ — a visitor's steps on a page, elements by id (a list's copy \`row:3\`), what must hold between them; \`type\` names
107
+ a form control and writes in its field; \`click\`/\`hover\` take \`point: { x, y }\`, percent of the element's box —
108
+ what a canvas draws (a map's marker); \`page\` may be a wrong address the space's own not-found page answers.
109
+ \`{ kind: 'expectCheck', check: '<unit id>' }\` holds an element check for the state the journey reached;
110
+ \`given: { state: { … } }\` starts it with a state; \`as: '<account>'\` plays it signed in as a test account;
111
+ \`tags: ['sign-in']\` sorts many (lower case words) — \`run\` with \`tags\` plays only those carrying one.
112
+ - \`accounts\`: \`{ id, email?, roles? }\` — who a journey plays as, declared here alone: no real account and no
113
+ password, so what the page asks the API it asks as a guest — a page for signed-in visitors, a role's view. Its roles
114
+ are the space's visitor roles (\`settings.visitorRoles\`), what it may is what they give; one removed since is warned.
115
+ The primer names both kinds' ids and titles.
116
+ A batch that leaves a test unreadable — an element it presses removed, the page it starts on renamed — says so in its
117
+ warnings ("This change leaves a test of the space unreadable…"): fix the test in the same batch, or say why.
118
+ When a test fails over a change the user asked for, say so and fix the test with them — never delete it to pass.
119
+ The plan keeps a number of journeys per space (Free one): a \`set\` that adds past it is refused, naming the plan that
120
+ keeps more — tell the user; never remove a journey of theirs to make room.
121
+ `;
122
+ //#endregion
123
+ export { practiceGuide };
@@ -0,0 +1,2 @@
1
+ /** The guide's start: what to read, the tools, and how an element is addressed, made, moved and deleted. */
2
+ export declare const referenceGuide = "# Plitzi AI MCP \u2014 usage guide\n\nA Plitzi space is **two separate schemas** you edit together:\n- **Element schema** \u2014 the tree of pages and elements (their type, label, props, and which style classes they use).\n- **Style schema** \u2014 reusable **definitions** (CSS classes), design tokens (variables), theme.\n\nThey are stored and persisted independently, but a single `plitzi_apply` batch may touch **both atomically**.\nTo style a specific element you do two things in one batch: write a **definition** (style schema) and **attach**\nit via the element's `style.base` (element schema). Example \u2014 \"rename button X to PEPE and make it red\":\n```json\n{ \"operations\": [\n { \"type\": \"upsertDefinition\", \"ref\": \"btn-x\", \"desktop\": { \"color\": \"red\" } },\n { \"type\": \"upsertElement\", \"pageRef\": \"home\",\n \"element\": { \"ref\": \"X\", \"type\": \"button\", \"label\": \"PEPE\", \"style\": { \"base\": [\"btn-x\"] } } }\n] }\n```\n\nReads are cheap by design \u2014 treat them like a filesystem: **list** to navigate, **read one item** for detail.\nNever download a whole tree you do not need.\n\n## Resources (read)\n- `plitzi://primer/{env}` \u2014 **cold-start bundle**: guide + types + css-properties + page/definition/variable\n **summaries** in one read. Fetch this first instead of the individual resources below. Summaries only \u2014 open a\n page skeleton or element for its tree/detail.\n- `plitzi://guide` \u2014 this guide.\n- `plitzi://types` \u2014 element types **observed in this space** (ground truth): props, slots, subTypes, plus each\n type's `label`, `description` (what it is FOR) and `category`, and a `source` (`builtin` | `plugin` | `unknown`).\n Read the descriptions to pick the right type \u2014 e.g. `apiContainer` fetches backend data into the frontend,\n `link` navigates between pages, `list` repeats a template over a data array. `plugin` types are the elements\n of the plugins the space installed: added by their type, like a built-in.\n- `plitzi://css-properties` \u2014 valid kebab-case CSS property keys.\n- `plitzi://explain/{name}` \u2014 what a name means: an element type's attributes, triggers, callbacks and what it writes\n on its node; a step's params and what it publishes; what a trigger hands its flow; a style state; a problem code's\n fix. `plitzi://explain/steps` (or elements, triggers, codes, transformers, states) lists every one of a kind.\n- `plitzi://schema/{env}/pages` \u2014 page **summaries** (ref, label, elementCount, folder). No element trees.\n- `plitzi://schema/{env}/layouts` \u2014 the shared **layout shells** (header/sidebar/footer) and the pages rendered\n inside each. Read one like a page. See *Shared layouts* below.\n- `plitzi://schema/{env}/components` \u2014 the space's **components** (reusable subtrees): their props, slots, root and\n how many places render each. Read one like a page. See *Components* below.\n- `plitzi://folders/{env}` \u2014 page **folders** (the sidebar tree): ref, name, slug, parentId. `/{ref}` for one.\n- `plitzi://schema/{env}/pages/{ref}` \u2014 one page as a **skeleton tree**: each node is `ref/type/label` **plus the\n style classes it attaches** (`base`, and `slots` for non-base slots) \u2014 names only, no CSS. So you can map every\n element to its class in a single page read, without opening each element just to learn which class it uses.\n- `plitzi://schema/{env}/pages/{ref}/styles` \u2014 **every style the page uses in one read**: the class definitions its\n elements attach (deduplicated, **with full CSS**) plus the global styles affecting any element type on the page.\n Reach for this to recolor/restyle a whole page \u2014 it needs no shared class-name prefix and no per-element reads.\n- `plitzi://schema/{env}/elements/{ref}` \u2014 one element in **full detail** (props, style, parentRef, childRefs).\n Its `resolvedStyle` inlines the **CSS of every definition** the element attaches (keyed by class ref), so you\n can see and edit its style without a separate definition read. Its `globalStyles` lists the **global element\n selectors** that also affect it (the CSS equivalent of `button { \u2026 }`, keyed by the type they target) \u2014 every\n element of that type inherits them. Edit a global only through the global-style tools (never per element). If the\n element carries a DOM `id` that an id rule matches, its `idStyle` (`#id`) is inlined too.\n- `plitzi://definitions/{env}` \u2014 the **names** of every style definition.\n- `plitzi://definitions/{env}/{ref}` \u2014 one definition's CSS.\n- `plitzi://global-styles/{env}` \u2014 element **types** that have a site-wide global style. `/{componentType}` for one.\n- `plitzi://id-styles/{env}` \u2014 DOM **ids** that have an id rule (`#id`) targeting a single element. `/{targetId}` for one.\n- `plitzi://style-variables/{env}` \u2014 design tokens by category. `/{category}` for one.\n- `plitzi://fonts/{env}` \u2014 the font **families the space loads**, with their source and fallback. `/{family}` for one.\n- `plitzi://schema-variables/{env}` \u2014 space-level values referenced in props as `{{name}}`.\n- `plitzi://flags/{env}` \u2014 the space's **feature flags**, each a default and its rules (see **Feature flags**).\n- `plitzi://settings/{env}` \u2014 space-level settings: the global `customCss` and the state/auth (user-provider) config.\n- `plitzi://interactions/{env}` \u2014 interaction **actions** observed in this space (grouped by node type): the\n vocabulary for interaction flows.\n- `plitzi://data-sources/{env}` \u2014 data-source **paths** and binding targets observed in this space: the\n vocabulary for data bindings.\n- `plitzi://connector-presets` \u2014 working starting **manifests** (Strapi, WordPress, Directus, Contentful, plain\n REST) with the credential keys each provider needs, plus every **template token** the connector engine binds.\n Space-independent. Read it before writing a connector by hand.\n- `plitzi://connectors/{env}` \u2014 the **connectors this space has**: for each, its read/write endpoint names, its\n filter operators and its published fields. `/{ref}` opens one manifest in full. See *Connectors* below.\n- `plitzi://actions/{env}` \u2014 the **server actions this space has**: what starts each one, who may run it, and the\n input/output contract a caller is held to. `/{ref}` opens one flow in full. See *Server actions* below.\n- `plitzi://actions/{env}/tasks` \u2014 the **server tasks this deployment can run**, each with its params: the steps an\n action may be built from.\n- `plitzi://functions/{env}` \u2014 the space's **functions**, its own server code: which files, and the tasks, routes and\n hosts they declare. `plitzi://functions/{env}/{+path}` reads one file whole. See *Functions* below.\n- `plitzi://data/{env}` \u2014 the space's **data**: JSON files its server providers read, never served.\n `plitzi://data/{env}/{+path}` reads one, parsed. See *Data* below.\n- `plitzi://changes/{env}` \u2014 the space's **change history**, read-only and newest first: who made each change (a\n person in the builder, an agent, the autofix), when, and every element, class, token or font it touched, whole, before\n and after. `/{id}` for the history of one of them \u2014 how you find what changed an element you are asked about, or\n review what you or another agent just did.\n- `plitzi://render/guide`, `plitzi://render/types` \u2014 the manual and the type table for `plitzi_render` (offline\n widgets, not this space).\n\nThe style resources also answer under the `plitzi://schema/{env}/\u2026` root as aliases \u2014 `plitzi://schema/{env}/definitions/{ref}`, `plitzi://schema/{env}/style-variables/{category}`, `plitzi://schema/{env}/schema-variables` \u2014 but prefer the ready-made `uri` from search / a write response over hand-building either form.\n\nData resources return `{ stateVersion, data }`. Keep `stateVersion` for optimistic concurrency.\n\n**Reuse what you already know \u2014 don't re-scan an unchanged page.** A page read (`plitzi://schema/{env}/pages/{ref}`)\nreturns a `stateVersion` that is an **aggregate of the whole page**: it changes if and only if some element on the\npage changed. Its skeleton `tree` also carries a `stateVersion` **per node**, identical to the one a direct element\nread or search hit returns for that element. So when you come back to a page you already inspected:\n1. Re-read just the page skeleton and compare its top-level `stateVersion` to the one you held. **Same \u2192 nothing\n changed since your read; skip re-reading and re-searching the tree** and act on what you already know.\n2. If it differs, diff the per-node `stateVersion`s against the ones you cached and `plitzi_read` **only the nodes\n that changed** \u2014 never re-search or re-read the whole tree.\n\nThis is a **read-time** shortcut, not a safety guarantee. **Other agents/sub-agents may edit the same space\nconcurrently**, so a version you cached can go stale between your read and your write. Never skip the write-time\ncheck below on the strength of a cached hash \u2014 the guarantee that no concurrent edit is lost comes only from\n`expectedResourceVersions` on `plitzi_apply`, which re-validates against the live data at write time.\n\n## Navigating (files analogy)\nPages and containers are folders; elements are files. **Prefer `plitzi_search` (especially with `include: \"detail\"`)\nover reading elements one by one** \u2014 it jumps straight to elements by label/type/attribute and each hit already\ncarries the element's `uri`, `stateVersion`, `pageUri`, `parentRef` and tree `path`, so you can edit it (with\noptimistic concurrency) **without a follow-up read**. `include: \"detail\"` additionally inlines each hit's props/style\n**and** its `resolvedStyle` (the CSS behind its classes) \u2014 so a search-then-edit is the efficient path and a manual\nelement read is the exception. Search also matches **pages** by name/slug (returned under `pages`, each with its uri +\nstateVersion) and returns any **style definitions** whose name matches the query, with full CSS, under `definitions`.\nWhen you do hold several refs to open (e.g. from a skeleton), read them together with `plitzi_read` rather than one at a time.\n\n## Tools\n- `plitzi_apply` \u2014 validate \u2192 apply \u2192 persist atomically. Rejects the whole batch on any error or conflict, and\n reports **pre-existing malformations** in any resource the batch touches (see below) and `suggestions` (see\n *Suggestions*). Pass `dryRun: true` to check and apply in memory only \u2014 the same answer, nothing persisted \u2014 and\n `look` (`\"html\"`, `\"image\"`, `\"accessibility\"` or `\"both\"`, with `pageRef` and `viewport`) to see the page\n as the batch leaves it in the same call. Check and look with `dryRun`, then send the same operations without it.\n `effects` is what the batch did, read off the space before and after it \u2014 every element, attribute, class and\n setting it changed, one line each: read it, not your batch, for what is now so. `Nothing changed` and `NOT saved`\n lead the warnings when they are so.\n- **By intention**, a few parameters and the element named by its ref alone \u2014 the page is found, the operations\n written, the batch checked and saved as `plitzi_apply` saves it, and the answer its `effects`, whether it was\n `saved`, and what was already so:\n `plitzi_set_attributes { ref, set, unset }`, `plitzi_set_classes { ref, add, remove }` (the classes it wears and\n you do not name stay), `plitzi_bind_attribute { ref, to, source }`, `plitzi_place_component { component, ref, into,\n props }`, `plitzi_add_page { ref, slug, layout }`. One of them when it says the whole change; anything else is one\n batch of `plitzi_apply`.\n- `plitzi_describe_operation` \u2014 one operation's schema by its `type` (every field, which are required); without a\n type, every operation type there is. Ask for the one you are writing instead of guessing a field: a field an\n operation does not have is refused naming the one meant (`\"prop\" (did you mean \"props\"?)`), and a type spelt with\n other capitals is read as the catalog spells it and said in `warnings`. The same batch refused twice is not run a\n third time (`REPEATED_BATCH`) \u2014 change what the errors name, or ask the person.\n- `plitzi_search` \u2014 find elements (and pages/definitions) across the space.\n- `plitzi_read` \u2014 read many resource **uris in one batch** (pages, elements, definitions, variables). Pass the\n ready-made uris from search / a write response; each result is `{ uri, stateVersion, data }` or a teachable error,\n so one bad uri never fails the batch. Use it instead of N single reads whenever you already hold several refs.\n- `plitzi_look { pageRef, view, viewport }` \u2014 see a saved page. `view`: `\"accessibility\"` (default) reads it as a\n screen reader and a browser agent (Claude in Chrome) do \u2014 an outline of roles and names, every control and picture\n with no name listed in `unnamed`, as text and far cheaper than an image; `\"html\"` its markup; `\"image\"` a PNG,\n the way to SEE overflow and misalignment (desktop, mobile or `both`); `\"both\"` image and outline. A change not\n saved yet is seen with `plitzi_apply`'s `dryRun` and `look`, the same views. It needs the SSR render service\n (`PREVIEW_UNAVAILABLE` without it); without a browser, an image or an outline falls back to the HTML, said.\n- `plitzi_activity { after, wait }` \u2014 what happened on the space since you last looked: the draft changed (a person\n in the builder, another agent, the autofix \u2014 `seq` is its place in `plitzi://changes/{env}`), a version went\n out, a server action failed or was refused. The first call, without `after`, answers the latest and a `cursor`;\n pass it back as `after` and the call waits up to `wait` seconds (45, at most 50) until something happens. Your own\n writes are left out and counted (`skippedMine`; `mine: true` keeps them). On a space people edit too, call it\n before a write that rests on what you read earlier.\n- `plitzi_render` \u2014 a different job: show the user a self-contained widget built offline. It never touches the space.\n\n## Suggestions \u2014 the same page with fewer elements\n`plitzi_apply` (with or without `dryRun`) answers with `suggestions`: lines like `[content-attribute] \u2026 (saves 4\nelements)`, each naming a shorter way to what the batch just wrote. Only what THIS batch opened up is said \u2014 what the\nspace already had is not repeated on every batch \u2014 and none of them blocks anything: the page renders as written.\n- `repeated-on-pages` \u2014 the same block at the edge of several pages: put it in a **layout** once (a block only some\n pages of a layout carry is a **component** instead). Copies differing only in one link's class are the nav item of the\n page being shown: the `current` state marks it (see *Pages & folders*).\n- `repeated-shape` \u2014 one structure written again with other words: a **component** with props\n (`upsertComponent { fromRef }` turns one copy into it), or, for sibling rows of data, one `repeatElement`/`list`.\n A few cards a person rewords by hand can stay cards; siblings that bind different data, keep different state, fill\n from a template of their own or render on the server are controls written alike, and are not offered.\n- `content-attribute` \u2014 a `button` or `link` whose children are only a `text` and/or a `fontAwesome`: its words\n are its own `content` and the icon its `icon`. What the text's class adds (`white-space: nowrap`) moves to the\n box's class \u2014 never the class itself; the icon's class goes in the `icon` slot.\n- `custom-css-class`, `custom-css-sdk-default`, `custom-css-notifications` \u2014 `customCss` that a class's\n `states`/`ancestors`, the SDK (reduced motion, the theme toggle's icons) or the space's notification look says.\n- `heavy-animation` \u2014 keyframes that animate a size, a position, a blur, a shadow, or a colour in a loop: they stutter\n while the page loads. Lighter, not shorter \u2014 see **Motion \u2014 good practices**.\n- `unused-class`, `unused-token`, `unused-component` \u2014 declared and read by nothing: remove it\n (`deleteDefinition`, `deleteStyleVariable`, `deleteComponent`), or use it where it was meant to go. Said\n when a batch leaves one behind.\n- `element-color-inherited` \u2014 the space's `elements` giving a type `color: inherit` or the page's own colour,\n which every element \u2014 a link's words included \u2014 takes by itself: remove it, and name the colour once on the page.\n- `literal-colour` \u2014 a class painted from the palette typing out a token's light value: `var(--token)` when it\n should follow the scheme; a token of one value when it must stay the same in both.\n`plitzi://explain/<code>` explains each. Take one unless the copies are about to diverge; one left on purpose is\nquieted on an element it names \u2014 `quiet: [\"repeated-shape\"]` on `upsertElement`/`patchElement` (`null` removes it)\n\u2014 and is not offered again, here, in the builder or in authoring. Suggestions' codes only.\n\n## Readers: resources vs plitzi_search vs plitzi_read (do not confuse them)\nThree ways to read, each for a different moment \u2014 pick by what you have in hand:\n- **MCP resources** (the `plitzi://\u2026` catalog above) \u2014 the **browsable index**. List them to discover what exists, or\n open one by URI when you are exploring. This is the passive catalog, not a tool.\n- **`plitzi_search`** \u2014 you know *what* you want but not its **ref/uri** (\"the hero button\"). Search finds it by\n label/type/attribute and hands back the uri + stateVersion (and, with `include:\"detail\"`, the full element).\n- **`plitzi_read`** \u2014 you **already hold one or more uris** (from search or a write response) and want their\n content in one batch. It is the tool form of opening resources, for when you have the addresses.\nRule of thumb: **discover \u2192 resources**, **find a name \u2192 plitzi_search**, **fetch known uris \u2192 plitzi_read**. Never\nhand-build a URI to guess your way to an element \u2014 search for it instead.\n\nWrite tools return what **changed** (`{ uri, stateVersion }`) plus counts, and the **full detail of every element\nthey created or updated** \u2014 each with its own `uri` and `stateVersion` (`elements: [...]`) so a follow-up edit of\nthe same element needs **no intermediate read**. Other resources (pages, definitions, variables) still report only\nuri+stateVersion \u2014 re-read them if you need their new content. The operation shapes are in each tool's input\nschema (discriminated by `type`).\n\n## Addressing\nEvery element and page has **one name, and that name is its id**. You choose it, you address it by it, and the\nruntime wires by it \u2014 there is no second key and nothing to translate. Creating an element with\n`\"ref\": \"products-api\"` stores it under exactly that.\n\nThat name is the **wiring key**: a provider registers its data source as `<type>_<name>`, so a `source` you write\nagainst a name resolves to that element at runtime. Rules for a **new** name (both enforced; a violation fails the\nbatch):\n- Charset `[A-Za-z0-9_-]`, **starting with a letter** and not ending in `-` (e.g. `\"products-api\"`, `\"food_item\"`). A `.` would split\n the `<type>_<name>.<field>` source path and the interaction target lookup, so **no dots**. An **underscore is\n allowed**: the FIRST `_` separates `<type>` from the name and element types are camelCase with none, so\n underscores inside a name are unambiguous (`list_food_item` \u2192 type `list`, name `food_item`).\n- **Unique across the space**; a name that is taken is rejected (address the existing element instead).\n\n**Never invent a name for something that already exists** \u2014 read it. Every read hands you the name back\n(`plitzi_search`, a page skeleton, a write response), and that is the string every op takes.\n\n**Where an element renders** is its `runtime`, settable on `upsertElement`/`patchElement`: `\"shared\"` (the\ndefault, both sides), `\"client\"` (browser only) or `\"server\"` (SSR only). It matters for one thing above all \u2014 an\n`apiContainer` reads through a **connector** only when it is `\"server\"` (see *Connectors*). An element read\nreports it only when it is set. The page server resolves `\"server\"` elements of a page and its layouts only, never\ninside a component \u2014 one there is refused; put the provider on the page and hand the component its rows as a prop.\n\n**Renaming** (`patchElement` with `rename`) moves the one key: the parent's child list, every binding source and\nevery interaction target across the space that named the old one is repointed with it, so nothing comes unwired.\nYou do not have to rewrite them.\n\n## Elements \u2014 create, move, delete\n- `upsertElement` creates an element (or replaces one by name) under `parentRef` \u2014 the page root when omitted \u2014 and\n builds a whole subtree in one op through nested `children`. `patchElement` changes an existing one in place.\n- `moveElement { pageRef, ref, toParentRef, position }` moves or reorders one: `position` `\"inside\"` (the default)\n nests it in `toParentRef`; `\"before\"`/`\"after\"` make it that element's sibling. Its subtree moves with it.\n- `deleteElement { pageRef, ref }` removes an element **and everything under it**. A binding or an interaction\n elsewhere that named one of them is left pointing at nothing, and the save reports it \u2014 delete them in the same\n batch. Destructive: confirm first.\n- `flag` on `upsertElement` / `patchElement` gates an element on a feature flag (`\"newCheckout\"` or\n `\"!newCheckout\"`) \u2014 not a visibility: gated off it is not rendered at all. See **Feature flags**.\n- **A compound element is written with its parts**, as `children` of the same `upsertElement`: a `carousel` holds a\n `carouselTrack` (the slides go in it), a `tabContainer` a `tabContainerHeader` and a `tabContainerBody`, a\n `dropdown` a `dropdownPopup`. Without its part it shows nothing (`part-missing`); a part anywhere else breaks the\n page (`outside-ancestor`).\n- **A dropdown places its popup**: the popup's class is its look, never its place (`popup-position-set`) \u2014\n `popupPlacement`, the offsets and `popupWidth: \"trigger\"` are the dropdown's; the `openDropdown`,\n `closeDropdown` and `toggleDropdown` steps open and close it. The open tab is a class's `current` state\n (`aria-selected`), never `active` (the press): `plitzi://explain/<type>` says what each element writes on its node.\n\n";
@@ -0,0 +1,249 @@
1
+ //#region src/modules/mcp/helpers/guide/reference.ts
2
+ /** The guide's start: what to read, the tools, and how an element is addressed, made, moved and deleted. */
3
+ var referenceGuide = `# Plitzi AI MCP — usage guide
4
+
5
+ A Plitzi space is **two separate schemas** you edit together:
6
+ - **Element schema** — the tree of pages and elements (their type, label, props, and which style classes they use).
7
+ - **Style schema** — reusable **definitions** (CSS classes), design tokens (variables), theme.
8
+
9
+ They are stored and persisted independently, but a single \`plitzi_apply\` batch may touch **both atomically**.
10
+ To style a specific element you do two things in one batch: write a **definition** (style schema) and **attach**
11
+ it via the element's \`style.base\` (element schema). Example — "rename button X to PEPE and make it red":
12
+ \`\`\`json
13
+ { "operations": [
14
+ { "type": "upsertDefinition", "ref": "btn-x", "desktop": { "color": "red" } },
15
+ { "type": "upsertElement", "pageRef": "home",
16
+ "element": { "ref": "X", "type": "button", "label": "PEPE", "style": { "base": ["btn-x"] } } }
17
+ ] }
18
+ \`\`\`
19
+
20
+ Reads are cheap by design — treat them like a filesystem: **list** to navigate, **read one item** for detail.
21
+ Never download a whole tree you do not need.
22
+
23
+ ## Resources (read)
24
+ - \`plitzi://primer/{env}\` — **cold-start bundle**: guide + types + css-properties + page/definition/variable
25
+ **summaries** in one read. Fetch this first instead of the individual resources below. Summaries only — open a
26
+ page skeleton or element for its tree/detail.
27
+ - \`plitzi://guide\` — this guide.
28
+ - \`plitzi://types\` — element types **observed in this space** (ground truth): props, slots, subTypes, plus each
29
+ type's \`label\`, \`description\` (what it is FOR) and \`category\`, and a \`source\` (\`builtin\` | \`plugin\` | \`unknown\`).
30
+ Read the descriptions to pick the right type — e.g. \`apiContainer\` fetches backend data into the frontend,
31
+ \`link\` navigates between pages, \`list\` repeats a template over a data array. \`plugin\` types are the elements
32
+ of the plugins the space installed: added by their type, like a built-in.
33
+ - \`plitzi://css-properties\` — valid kebab-case CSS property keys.
34
+ - \`plitzi://explain/{name}\` — what a name means: an element type's attributes, triggers, callbacks and what it writes
35
+ on its node; a step's params and what it publishes; what a trigger hands its flow; a style state; a problem code's
36
+ fix. \`plitzi://explain/steps\` (or elements, triggers, codes, transformers, states) lists every one of a kind.
37
+ - \`plitzi://schema/{env}/pages\` — page **summaries** (ref, label, elementCount, folder). No element trees.
38
+ - \`plitzi://schema/{env}/layouts\` — the shared **layout shells** (header/sidebar/footer) and the pages rendered
39
+ inside each. Read one like a page. See *Shared layouts* below.
40
+ - \`plitzi://schema/{env}/components\` — the space's **components** (reusable subtrees): their props, slots, root and
41
+ how many places render each. Read one like a page. See *Components* below.
42
+ - \`plitzi://folders/{env}\` — page **folders** (the sidebar tree): ref, name, slug, parentId. \`/{ref}\` for one.
43
+ - \`plitzi://schema/{env}/pages/{ref}\` — one page as a **skeleton tree**: each node is \`ref/type/label\` **plus the
44
+ style classes it attaches** (\`base\`, and \`slots\` for non-base slots) — names only, no CSS. So you can map every
45
+ element to its class in a single page read, without opening each element just to learn which class it uses.
46
+ - \`plitzi://schema/{env}/pages/{ref}/styles\` — **every style the page uses in one read**: the class definitions its
47
+ elements attach (deduplicated, **with full CSS**) plus the global styles affecting any element type on the page.
48
+ Reach for this to recolor/restyle a whole page — it needs no shared class-name prefix and no per-element reads.
49
+ - \`plitzi://schema/{env}/elements/{ref}\` — one element in **full detail** (props, style, parentRef, childRefs).
50
+ Its \`resolvedStyle\` inlines the **CSS of every definition** the element attaches (keyed by class ref), so you
51
+ can see and edit its style without a separate definition read. Its \`globalStyles\` lists the **global element
52
+ selectors** that also affect it (the CSS equivalent of \`button { … }\`, keyed by the type they target) — every
53
+ element of that type inherits them. Edit a global only through the global-style tools (never per element). If the
54
+ element carries a DOM \`id\` that an id rule matches, its \`idStyle\` (\`#id\`) is inlined too.
55
+ - \`plitzi://definitions/{env}\` — the **names** of every style definition.
56
+ - \`plitzi://definitions/{env}/{ref}\` — one definition's CSS.
57
+ - \`plitzi://global-styles/{env}\` — element **types** that have a site-wide global style. \`/{componentType}\` for one.
58
+ - \`plitzi://id-styles/{env}\` — DOM **ids** that have an id rule (\`#id\`) targeting a single element. \`/{targetId}\` for one.
59
+ - \`plitzi://style-variables/{env}\` — design tokens by category. \`/{category}\` for one.
60
+ - \`plitzi://fonts/{env}\` — the font **families the space loads**, with their source and fallback. \`/{family}\` for one.
61
+ - \`plitzi://schema-variables/{env}\` — space-level values referenced in props as \`{{name}}\`.
62
+ - \`plitzi://flags/{env}\` — the space's **feature flags**, each a default and its rules (see **Feature flags**).
63
+ - \`plitzi://settings/{env}\` — space-level settings: the global \`customCss\` and the state/auth (user-provider) config.
64
+ - \`plitzi://interactions/{env}\` — interaction **actions** observed in this space (grouped by node type): the
65
+ vocabulary for interaction flows.
66
+ - \`plitzi://data-sources/{env}\` — data-source **paths** and binding targets observed in this space: the
67
+ vocabulary for data bindings.
68
+ - \`plitzi://connector-presets\` — working starting **manifests** (Strapi, WordPress, Directus, Contentful, plain
69
+ REST) with the credential keys each provider needs, plus every **template token** the connector engine binds.
70
+ Space-independent. Read it before writing a connector by hand.
71
+ - \`plitzi://connectors/{env}\` — the **connectors this space has**: for each, its read/write endpoint names, its
72
+ filter operators and its published fields. \`/{ref}\` opens one manifest in full. See *Connectors* below.
73
+ - \`plitzi://actions/{env}\` — the **server actions this space has**: what starts each one, who may run it, and the
74
+ input/output contract a caller is held to. \`/{ref}\` opens one flow in full. See *Server actions* below.
75
+ - \`plitzi://actions/{env}/tasks\` — the **server tasks this deployment can run**, each with its params: the steps an
76
+ action may be built from.
77
+ - \`plitzi://functions/{env}\` — the space's **functions**, its own server code: which files, and the tasks, routes and
78
+ hosts they declare. \`plitzi://functions/{env}/{+path}\` reads one file whole. See *Functions* below.
79
+ - \`plitzi://data/{env}\` — the space's **data**: JSON files its server providers read, never served.
80
+ \`plitzi://data/{env}/{+path}\` reads one, parsed. See *Data* below.
81
+ - \`plitzi://changes/{env}\` — the space's **change history**, read-only and newest first: who made each change (a
82
+ person in the builder, an agent, the autofix), when, and every element, class, token or font it touched, whole, before
83
+ and after. \`/{id}\` for the history of one of them — how you find what changed an element you are asked about, or
84
+ review what you or another agent just did.
85
+ - \`plitzi://render/guide\`, \`plitzi://render/types\` — the manual and the type table for \`plitzi_render\` (offline
86
+ widgets, not this space).
87
+
88
+ The style resources also answer under the \`plitzi://schema/{env}/…\` root as aliases — \`plitzi://schema/{env}/definitions/{ref}\`, \`plitzi://schema/{env}/style-variables/{category}\`, \`plitzi://schema/{env}/schema-variables\` — but prefer the ready-made \`uri\` from search / a write response over hand-building either form.
89
+
90
+ Data resources return \`{ stateVersion, data }\`. Keep \`stateVersion\` for optimistic concurrency.
91
+
92
+ **Reuse what you already know — don't re-scan an unchanged page.** A page read (\`plitzi://schema/{env}/pages/{ref}\`)
93
+ returns a \`stateVersion\` that is an **aggregate of the whole page**: it changes if and only if some element on the
94
+ page changed. Its skeleton \`tree\` also carries a \`stateVersion\` **per node**, identical to the one a direct element
95
+ read or search hit returns for that element. So when you come back to a page you already inspected:
96
+ 1. Re-read just the page skeleton and compare its top-level \`stateVersion\` to the one you held. **Same → nothing
97
+ changed since your read; skip re-reading and re-searching the tree** and act on what you already know.
98
+ 2. If it differs, diff the per-node \`stateVersion\`s against the ones you cached and \`plitzi_read\` **only the nodes
99
+ that changed** — never re-search or re-read the whole tree.
100
+
101
+ This is a **read-time** shortcut, not a safety guarantee. **Other agents/sub-agents may edit the same space
102
+ concurrently**, so a version you cached can go stale between your read and your write. Never skip the write-time
103
+ check below on the strength of a cached hash — the guarantee that no concurrent edit is lost comes only from
104
+ \`expectedResourceVersions\` on \`plitzi_apply\`, which re-validates against the live data at write time.
105
+
106
+ ## Navigating (files analogy)
107
+ Pages and containers are folders; elements are files. **Prefer \`plitzi_search\` (especially with \`include: "detail"\`)
108
+ over reading elements one by one** — it jumps straight to elements by label/type/attribute and each hit already
109
+ carries the element's \`uri\`, \`stateVersion\`, \`pageUri\`, \`parentRef\` and tree \`path\`, so you can edit it (with
110
+ optimistic concurrency) **without a follow-up read**. \`include: "detail"\` additionally inlines each hit's props/style
111
+ **and** its \`resolvedStyle\` (the CSS behind its classes) — so a search-then-edit is the efficient path and a manual
112
+ element read is the exception. Search also matches **pages** by name/slug (returned under \`pages\`, each with its uri +
113
+ stateVersion) and returns any **style definitions** whose name matches the query, with full CSS, under \`definitions\`.
114
+ When you do hold several refs to open (e.g. from a skeleton), read them together with \`plitzi_read\` rather than one at a time.
115
+
116
+ ## Tools
117
+ - \`plitzi_apply\` — validate → apply → persist atomically. Rejects the whole batch on any error or conflict, and
118
+ reports **pre-existing malformations** in any resource the batch touches (see below) and \`suggestions\` (see
119
+ *Suggestions*). Pass \`dryRun: true\` to check and apply in memory only — the same answer, nothing persisted — and
120
+ \`look\` (\`"html"\`, \`"image"\`, \`"accessibility"\` or \`"both"\`, with \`pageRef\` and \`viewport\`) to see the page
121
+ as the batch leaves it in the same call. Check and look with \`dryRun\`, then send the same operations without it.
122
+ \`effects\` is what the batch did, read off the space before and after it — every element, attribute, class and
123
+ setting it changed, one line each: read it, not your batch, for what is now so. \`Nothing changed\` and \`NOT saved\`
124
+ lead the warnings when they are so.
125
+ - **By intention**, a few parameters and the element named by its ref alone — the page is found, the operations
126
+ written, the batch checked and saved as \`plitzi_apply\` saves it, and the answer its \`effects\`, whether it was
127
+ \`saved\`, and what was already so:
128
+ \`plitzi_set_attributes { ref, set, unset }\`, \`plitzi_set_classes { ref, add, remove }\` (the classes it wears and
129
+ you do not name stay), \`plitzi_bind_attribute { ref, to, source }\`, \`plitzi_place_component { component, ref, into,
130
+ props }\`, \`plitzi_add_page { ref, slug, layout }\`. One of them when it says the whole change; anything else is one
131
+ batch of \`plitzi_apply\`.
132
+ - \`plitzi_describe_operation\` — one operation's schema by its \`type\` (every field, which are required); without a
133
+ type, every operation type there is. Ask for the one you are writing instead of guessing a field: a field an
134
+ operation does not have is refused naming the one meant (\`"prop" (did you mean "props"?)\`), and a type spelt with
135
+ other capitals is read as the catalog spells it and said in \`warnings\`. The same batch refused twice is not run a
136
+ third time (\`REPEATED_BATCH\`) — change what the errors name, or ask the person.
137
+ - \`plitzi_search\` — find elements (and pages/definitions) across the space.
138
+ - \`plitzi_read\` — read many resource **uris in one batch** (pages, elements, definitions, variables). Pass the
139
+ ready-made uris from search / a write response; each result is \`{ uri, stateVersion, data }\` or a teachable error,
140
+ so one bad uri never fails the batch. Use it instead of N single reads whenever you already hold several refs.
141
+ - \`plitzi_look { pageRef, view, viewport }\` — see a saved page. \`view\`: \`"accessibility"\` (default) reads it as a
142
+ screen reader and a browser agent (Claude in Chrome) do — an outline of roles and names, every control and picture
143
+ with no name listed in \`unnamed\`, as text and far cheaper than an image; \`"html"\` its markup; \`"image"\` a PNG,
144
+ the way to SEE overflow and misalignment (desktop, mobile or \`both\`); \`"both"\` image and outline. A change not
145
+ saved yet is seen with \`plitzi_apply\`'s \`dryRun\` and \`look\`, the same views. It needs the SSR render service
146
+ (\`PREVIEW_UNAVAILABLE\` without it); without a browser, an image or an outline falls back to the HTML, said.
147
+ - \`plitzi_activity { after, wait }\` — what happened on the space since you last looked: the draft changed (a person
148
+ in the builder, another agent, the autofix — \`seq\` is its place in \`plitzi://changes/{env}\`), a version went
149
+ out, a server action failed or was refused. The first call, without \`after\`, answers the latest and a \`cursor\`;
150
+ pass it back as \`after\` and the call waits up to \`wait\` seconds (45, at most 50) until something happens. Your own
151
+ writes are left out and counted (\`skippedMine\`; \`mine: true\` keeps them). On a space people edit too, call it
152
+ before a write that rests on what you read earlier.
153
+ - \`plitzi_render\` — a different job: show the user a self-contained widget built offline. It never touches the space.
154
+
155
+ ## Suggestions — the same page with fewer elements
156
+ \`plitzi_apply\` (with or without \`dryRun\`) answers with \`suggestions\`: lines like \`[content-attribute] … (saves 4
157
+ elements)\`, each naming a shorter way to what the batch just wrote. Only what THIS batch opened up is said — what the
158
+ space already had is not repeated on every batch — and none of them blocks anything: the page renders as written.
159
+ - \`repeated-on-pages\` — the same block at the edge of several pages: put it in a **layout** once (a block only some
160
+ pages of a layout carry is a **component** instead). Copies differing only in one link's class are the nav item of the
161
+ page being shown: the \`current\` state marks it (see *Pages & folders*).
162
+ - \`repeated-shape\` — one structure written again with other words: a **component** with props
163
+ (\`upsertComponent { fromRef }\` turns one copy into it), or, for sibling rows of data, one \`repeatElement\`/\`list\`.
164
+ A few cards a person rewords by hand can stay cards; siblings that bind different data, keep different state, fill
165
+ from a template of their own or render on the server are controls written alike, and are not offered.
166
+ - \`content-attribute\` — a \`button\` or \`link\` whose children are only a \`text\` and/or a \`fontAwesome\`: its words
167
+ are its own \`content\` and the icon its \`icon\`. What the text's class adds (\`white-space: nowrap\`) moves to the
168
+ box's class — never the class itself; the icon's class goes in the \`icon\` slot.
169
+ - \`custom-css-class\`, \`custom-css-sdk-default\`, \`custom-css-notifications\` — \`customCss\` that a class's
170
+ \`states\`/\`ancestors\`, the SDK (reduced motion, the theme toggle's icons) or the space's notification look says.
171
+ - \`heavy-animation\` — keyframes that animate a size, a position, a blur, a shadow, or a colour in a loop: they stutter
172
+ while the page loads. Lighter, not shorter — see **Motion — good practices**.
173
+ - \`unused-class\`, \`unused-token\`, \`unused-component\` — declared and read by nothing: remove it
174
+ (\`deleteDefinition\`, \`deleteStyleVariable\`, \`deleteComponent\`), or use it where it was meant to go. Said
175
+ when a batch leaves one behind.
176
+ - \`element-color-inherited\` — the space's \`elements\` giving a type \`color: inherit\` or the page's own colour,
177
+ which every element — a link's words included — takes by itself: remove it, and name the colour once on the page.
178
+ - \`literal-colour\` — a class painted from the palette typing out a token's light value: \`var(--token)\` when it
179
+ should follow the scheme; a token of one value when it must stay the same in both.
180
+ \`plitzi://explain/<code>\` explains each. Take one unless the copies are about to diverge; one left on purpose is
181
+ quieted on an element it names — \`quiet: ["repeated-shape"]\` on \`upsertElement\`/\`patchElement\` (\`null\` removes it)
182
+ — and is not offered again, here, in the builder or in authoring. Suggestions' codes only.
183
+
184
+ ## Readers: resources vs plitzi_search vs plitzi_read (do not confuse them)
185
+ Three ways to read, each for a different moment — pick by what you have in hand:
186
+ - **MCP resources** (the \`plitzi://…\` catalog above) — the **browsable index**. List them to discover what exists, or
187
+ open one by URI when you are exploring. This is the passive catalog, not a tool.
188
+ - **\`plitzi_search\`** — you know *what* you want but not its **ref/uri** ("the hero button"). Search finds it by
189
+ label/type/attribute and hands back the uri + stateVersion (and, with \`include:"detail"\`, the full element).
190
+ - **\`plitzi_read\`** — you **already hold one or more uris** (from search or a write response) and want their
191
+ content in one batch. It is the tool form of opening resources, for when you have the addresses.
192
+ Rule of thumb: **discover → resources**, **find a name → plitzi_search**, **fetch known uris → plitzi_read**. Never
193
+ hand-build a URI to guess your way to an element — search for it instead.
194
+
195
+ Write tools return what **changed** (\`{ uri, stateVersion }\`) plus counts, and the **full detail of every element
196
+ they created or updated** — each with its own \`uri\` and \`stateVersion\` (\`elements: [...]\`) so a follow-up edit of
197
+ the same element needs **no intermediate read**. Other resources (pages, definitions, variables) still report only
198
+ uri+stateVersion — re-read them if you need their new content. The operation shapes are in each tool's input
199
+ schema (discriminated by \`type\`).
200
+
201
+ ## Addressing
202
+ Every element and page has **one name, and that name is its id**. You choose it, you address it by it, and the
203
+ runtime wires by it — there is no second key and nothing to translate. Creating an element with
204
+ \`"ref": "products-api"\` stores it under exactly that.
205
+
206
+ That name is the **wiring key**: a provider registers its data source as \`<type>_<name>\`, so a \`source\` you write
207
+ against a name resolves to that element at runtime. Rules for a **new** name (both enforced; a violation fails the
208
+ batch):
209
+ - Charset \`[A-Za-z0-9_-]\`, **starting with a letter** and not ending in \`-\` (e.g. \`"products-api"\`, \`"food_item"\`). A \`.\` would split
210
+ the \`<type>_<name>.<field>\` source path and the interaction target lookup, so **no dots**. An **underscore is
211
+ allowed**: the FIRST \`_\` separates \`<type>\` from the name and element types are camelCase with none, so
212
+ underscores inside a name are unambiguous (\`list_food_item\` → type \`list\`, name \`food_item\`).
213
+ - **Unique across the space**; a name that is taken is rejected (address the existing element instead).
214
+
215
+ **Never invent a name for something that already exists** — read it. Every read hands you the name back
216
+ (\`plitzi_search\`, a page skeleton, a write response), and that is the string every op takes.
217
+
218
+ **Where an element renders** is its \`runtime\`, settable on \`upsertElement\`/\`patchElement\`: \`"shared"\` (the
219
+ default, both sides), \`"client"\` (browser only) or \`"server"\` (SSR only). It matters for one thing above all — an
220
+ \`apiContainer\` reads through a **connector** only when it is \`"server"\` (see *Connectors*). An element read
221
+ reports it only when it is set. The page server resolves \`"server"\` elements of a page and its layouts only, never
222
+ inside a component — one there is refused; put the provider on the page and hand the component its rows as a prop.
223
+
224
+ **Renaming** (\`patchElement\` with \`rename\`) moves the one key: the parent's child list, every binding source and
225
+ every interaction target across the space that named the old one is repointed with it, so nothing comes unwired.
226
+ You do not have to rewrite them.
227
+
228
+ ## Elements — create, move, delete
229
+ - \`upsertElement\` creates an element (or replaces one by name) under \`parentRef\` — the page root when omitted — and
230
+ builds a whole subtree in one op through nested \`children\`. \`patchElement\` changes an existing one in place.
231
+ - \`moveElement { pageRef, ref, toParentRef, position }\` moves or reorders one: \`position\` \`"inside"\` (the default)
232
+ nests it in \`toParentRef\`; \`"before"\`/\`"after"\` make it that element's sibling. Its subtree moves with it.
233
+ - \`deleteElement { pageRef, ref }\` removes an element **and everything under it**. A binding or an interaction
234
+ elsewhere that named one of them is left pointing at nothing, and the save reports it — delete them in the same
235
+ batch. Destructive: confirm first.
236
+ - \`flag\` on \`upsertElement\` / \`patchElement\` gates an element on a feature flag (\`"newCheckout"\` or
237
+ \`"!newCheckout"\`) — not a visibility: gated off it is not rendered at all. See **Feature flags**.
238
+ - **A compound element is written with its parts**, as \`children\` of the same \`upsertElement\`: a \`carousel\` holds a
239
+ \`carouselTrack\` (the slides go in it), a \`tabContainer\` a \`tabContainerHeader\` and a \`tabContainerBody\`, a
240
+ \`dropdown\` a \`dropdownPopup\`. Without its part it shows nothing (\`part-missing\`); a part anywhere else breaks the
241
+ page (\`outside-ancestor\`).
242
+ - **A dropdown places its popup**: the popup's class is its look, never its place (\`popup-position-set\`) —
243
+ \`popupPlacement\`, the offsets and \`popupWidth: "trigger"\` are the dropdown's; the \`openDropdown\`,
244
+ \`closeDropdown\` and \`toggleDropdown\` steps open and close it. The open tab is a class's \`current\` state
245
+ (\`aria-selected\`), never \`active\` (the press): \`plitzi://explain/<type>\` says what each element writes on its node.
246
+
247
+ `;
248
+ //#endregion
249
+ export { referenceGuide };
@@ -0,0 +1,2 @@
1
+ /** The space's server side: connectors, server actions, functions, data, realtime channels and feature flags. */
2
+ export declare const serverGuide = "## Connectors \u2014 CMS and API integrations\nA **connector** is how a space reads real content from Strapi, WordPress, Contentful, Directus or any REST service.\nIt is **a manifest, not code**: you declare the base URL, the endpoints, the auth template and the filter operators,\nand the **server** executes it during the render. Integrating a new CMS never means shipping an adapter \u2014 it means\nwriting one document, which you can do here with `upsertConnector`.\n\nWhy the server and not the browser: the request (and the token behind it) never reaches the visitor, and the content\nis in the HTML search engines see. That is also the one hard rule below \u2014 a provider element that is not\nserver-rendered ignores its connector entirely.\n\n**Read these two first:**\n- `plitzi://connector-presets` \u2014 **working manifests** for Strapi v5, WordPress, Directus, Contentful and a plain\n REST API, each with the `credentialKeys` that provider needs, **plus every template token** the engine binds.\n Start from the preset for the user's provider and edit it; do not invent a shape from memory.\n- `plitzi://connectors/{env}` \u2014 the connectors **this space already has**, each with its read/write endpoint names,\n its filter operators and its published fields. `plitzi://connectors/{env}/{ref}` opens one manifest in full.\n\n### Credentials are NOT yours to write\nYou never create, see or transmit a secret. Author the manifest with the token in place\n(`\"value\": \"Bearer {{credential.token}}\"`) and **leave `connection.credential` unset** unless the user hands you an\nidentifier. The connector **saves fine that way** \u2014 validation reports it as a *warning*, not an error \u2014 and its\nrequests go unauthenticated until the space owner creates the credential in the builder and attaches it. Say that to\nthe user as the last step of any integration you build, naming the keys the preset lists (e.g. Strapi needs `token`).\n\n### The manifest\nEvery string is a template the server renders per request. `{{resource}}` is the collection the element asked for;\n`{{limit}}`/`{{offset}}`/`{{page}}`/`{{cursor}}` the window; `{{routeParams.x}}`/`{{queryParams.x}}` the\nvisitor's URL; `{{credential.x}}` the secret; `{{field}}`/`{{value}}` inside an operator; `{{id}}`/`{{values}}`\ninside a write. The op splits it in two, exactly as the engine does:\n- **`connection`** \u2014 what applies to every call: `credential`, `auth`, `headers`, `pagination`, `operators`,\n `mediaBaseUrl`, `fields`, `projection`.\n- **`endpoints`** \u2014 the individual calls: `read` (named; **`list` is the one an element addresses when it names\n none**) and `write` (named; **omit for read-only** \u2014 an undeclared write can never be executed).\n\nA read endpoint says where things live in *that* provider's response: `itemsPath` (the array), `totalPath` (the\ncount), `idPath` (the record's id), `valuesPath` (its fields). Strapi's `data` + `meta.pagination.total` and\nContentful's `items` + `fields` are the same manifest with different paths.\n\nTwo traps the validator will catch for you, both silent at runtime otherwise:\n- An **operator template must render a whole `key=value` entry** (`\"eq\": \"filters[{{field}}][$eq]={{value}}\"`). A\n filter naming an operator the manifest does not declare is **dropped** \u2014 the query then returns *unfiltered*\n records, not none.\n- **Paging must appear in the request.** Declaring `pagination: \"page\"` without `{{page}}` in the query makes every\n page resolve to the first one.\n\nExample \u2014 Strapi, from the preset:\n```json\n{ \"type\": \"upsertConnector\", \"ref\": \"strapi-blog\", \"name\": \"Blog CMS\",\n \"baseUrl\": \"https://cms.example.com\",\n \"connection\": {\n \"auth\": { \"in\": \"header\", \"name\": \"Authorization\", \"value\": \"Bearer {{credential.token}}\" },\n \"pagination\": \"offset\",\n \"operators\": { \"eq\": \"filters[{{field}}][$eq]={{value}}\", \"contains\": \"filters[{{field}}][$containsi]={{value}}\" },\n \"mediaBaseUrl\": \"https://cms.example.com\" },\n \"endpoints\": { \"read\": { \"list\": {\n \"path\": \"/api/{{resource}}\",\n \"query\": { \"pagination[start]\": \"{{offset}}\", \"pagination[limit]\": \"{{limit}}\", \"populate\": \"*\" },\n \"itemsPath\": \"data\", \"totalPath\": \"meta.pagination.total\", \"idPath\": \"documentId\" } } } }\n```\n`patchConnector` changes part of one (endpoints merge **by name**; `null` removes one) \u2014 that is how you add a\n`detail` read to a large manifest without resending it. `deleteConnector` is destructive: every element pointing\nat it stops resolving, so confirm first.\n\n### Using a connector on a page\nThe provider element is `apiContainer`, and it needs **both halves**:\n1. `runtime: \"server\"` \u2014 set it on `upsertElement`/`patchElement`. **Without it the connector is ignored** and the\n element falls back to fetching its own `query` URL from the browser. This is the single most common mistake; the\n validator warns when it sees one half without the other.\n2. props: `connector` (the ref), `resource` (the collection \u2192 `{{resource}}`), and optionally `endpoint` (a read\n other than `list`), `filters`, `limit`, `singleRecord`, `pagination`, `pageParam`.\n\nIt then publishes one source **to its descendants only** (like any provider \u2014 bind *inside* its subtree):\n`apiContainer_<name>.records` (an array of `{ id, values }` \u2014 a record's fields are under `values`, so a row\nreads `list_<name>.item.values.<field>`), `.pageInfo` (`page`, `pageCount`, `total`, `hasNextPage`\u2026),\n`.isEmpty`, `.hasError`, `.errorMessage`, `.isLoading`. With `singleRecord: true` it publishes `.record`\ninstead of `.records` \u2014 that is what a **detail page** uses. Bind an empty-state block's visibility to `.isEmpty`\nand an error block's to `.hasError`; they are ordinary bindings, no special mechanism.\n\n**A list page** \u2014 provider, then a `list` inside it bound to the records, then the row template reading the item\n(a `list` is a `<ul>`, or `<ol>` by `subType`; its row a `listItem`, an `<li>` \u2014 any other row is warned\n`list-row-not-li`):\n```json\n{ \"operations\": [\n { \"type\": \"upsertElement\", \"pageRef\": \"blog\", \"element\": {\n \"ref\": \"posts-api\", \"type\": \"apiContainer\", \"runtime\": \"server\",\n \"props\": { \"connector\": \"strapi-blog\", \"resource\": \"articles\", \"limit\": \"9\", \"pagination\": \"url\" },\n \"children\": [ { \"ref\": \"posts\", \"type\": \"list\", \"children\": [\n { \"ref\": \"post-row\", \"type\": \"listItem\", \"children\": [\n { \"ref\": \"post-title\", \"type\": \"text\" } ] } ] } ] } },\n { \"type\": \"upsertBinding\", \"pageRef\": \"blog\", \"ref\": \"posts\", \"category\": \"attributes\",\n \"binding\": { \"to\": \"items\", \"source\": \"apiContainer_posts-api.records\" } },\n { \"type\": \"upsertBinding\", \"pageRef\": \"blog\", \"ref\": \"post-title\", \"category\": \"attributes\",\n \"binding\": { \"to\": \"content\", \"source\": \"list_posts.item.values.title\" } } ] }\n```\n\n**A detail page** is the same provider with `singleRecord` and a filter resolved from the URL. Create the page with a\nroute param (`\"slug\": \"blog/:postSlug\"`), then filter on it \u2014 the filter `value` is a template the server resolves:\n```json\n{ \"type\": \"upsertElement\", \"pageRef\": \"post-detail\", \"element\": {\n \"ref\": \"post-api\", \"type\": \"apiContainer\", \"runtime\": \"server\",\n \"props\": { \"connector\": \"strapi-blog\", \"resource\": \"articles\", \"singleRecord\": true,\n \"filters\": [ { \"field\": \"slug\", \"operator\": \"eq\", \"value\": \"{{routeParams.postSlug}}\" } ] } } }\n```\nIts children then bind to `apiContainer_post-api.record.values.<field>`. A filter whose template resolves to nothing\nreturns **no records** rather than the whole collection \u2014 a URL that addressed one post never renders a different one.\n\n**Paging** is the `pagination` prop: `\"none\"`, `\"url\"` (the page number rides the query string, so pages are\nshareable and indexable \u2014 prefer it) or `\"append\"` (a \"load more\" list). Give each list on a page its own\n`pageParam` so two lists page independently. The provider also offers the `loadMore` and `goToPage` callbacks to\ninteraction flows, `performQuery` to refetch, and `cancelQuery` to drop a request in flight (a STOP).\n\n**Writing back** (a form, a \"delete\" button): declare the endpoint under `endpoints.write`, then call the provider's\n**`writeRecord`** callback from an interaction flow \u2014 nodeType `callback`, `elementId` the apiContainer's ref,\nparams `action` (the write endpoint's name) and `recordId`. The write goes through the server, which owns the\ncredential and refuses any action the manifest does not declare. Writes exist **only** on a server-rendered provider.\n\n**Connectors need a server.** A space published without server rendering has nowhere to resolve one: it works in the\nbuilder and renders empty when published. If the user has no SSR deployment, say so rather than leaving them to\ndiscover it \u2014 the alternative is a browser-side `query`, which cannot keep a secret.\n\n## Server actions\nWork a page cannot do in the browser \u2014 charge a card, send mail, read a system only the server reaches. An action\nis a stored flow the SERVER runs; a page names it and never learns what it does. Write one with\n`upsertAction` / `patchAction`, then call it from a page flow with the `runServerAction` step (mode\n`await` to use the result, `detached` to fire and carry on).\n\nFour rules worth knowing before you write:\n\n- **Steps are server tasks.** `plitzi://actions/{env}/tasks` lists what this deployment can run \u2014 a browser step\n (`setState`, `navigate`) has nothing to act on here, and the reverse is true too: a task cannot run in a page\n flow.\n- **The contracts.** `input` is coerced and anything undeclared is DROPPED. The OUTPUT is whatever the final\n `flow.output` step names \u2014 there is no separate list to keep in step with it \u2014 and that step must be LAST,\n since only the last one that runs is answered. Everything else a step produced stays on the server.\n- **Whether it runs lives on its TRIGGERS.** Each trigger step carries `enabled`, and the action is on when any\n way into it is \u2014 there is no switch beside the flow. So \"pause this action\" means disabling its trigger step(s),\n never deleting them.\n- **A step names the credential it uses**, and sees no other. `credentials` on the document says which ones the\n action may ask for at all; the secret itself is never yours to see, exactly as with a connector.\n\n`deleteAction { ref }` removes one; every `runServerAction` step that names it stops resolving, so confirm first.\n\n## Functions\nWhen no server task does what a flow needs \u2014 parse a feed, call an API with its own shape, compute something \u2014 the\nspace can have its own: **functions**, TypeScript the platform builds and runs in a sandbox. Their tasks are steps like\nany other (`<namespace>.<action>`), listed in `plitzi://actions/{env}/tasks` once saved.\n\n- **Write** files with `upsertFunctionFile { path, content }` (whole files; `deleteFunctionFile { path }` removes\n one). `index.ts` default-exports the definition:\n `export default defineFunctions({ allow: { hosts: [\"api.example.com\"] }, tasks: [{ namespace, action, title, params, run: async (params, ctx) => \u2026 }] })`,\n `defineFunctions` from `@plitzi/sdk-server/functions`. Files import each other by relative path \u2014 no package,\n no Node built-in.\n- **`ctx` is all a function reaches:** `ctx.kv` (the space's store), `ctx.fetch(url, init)` to the hosts\n `allow.hosts` names (`*.example.com` for subdomains), `ctx.publish/grant/revoke` (channels),\n `ctx.data(\"products.json\")` (one file of the space's data, parsed \u2014 never imported), `ctx.log`, `ctx.user` (who\n asked, never their session). A secret is NAMED, never read: `ctx.fetch(url, { credential: \"stripe\",\n headers: { authorization: \"Bearer {{ credential.apiKey }}\" } })`. `signal` in the init cuts a slow request short\n (`AbortSignal.timeout(12000)`).\n- **Refuse with `ActionRefusal`** (from `@plitzi/sdk-server/functions`): its message is written for whoever asked and\n reaches them (`{{ step.error }}`, a route's `400 { error }`); anything else thrown stays in the run's record.\n `new ActionRefusal(message, { code })` names it for code that catches it \u2014 compare `error.code`, never the message.\n- **An API on behalf of a visitor** (their calendar, their music) is an OAuth connection declared as data:\n `defineFunctions({ oauth: { calendar: { issuer, credential, scopes } } })` \u2014 `issuer` for OpenID, or\n `authorizeUrl`/`tokenUrl`; the credential holds the app's `clientId`/`clientSecret`. A route redirects to\n `(await ctx.oauth.connect(\"calendar\", { returnTo: \"/settings\" })).url` (`authorizeParams` adds to that one consent:\n `{ prompt: \"select_account\" }`), and `ctx.oauth.fetch(\"calendar\", url)` calls the API with the token written in;\n `status`, `disconnect` beside them. The platform keeps the token sealed and renews it \u2014 never put one in `kv`. The\n user registers `/fn/oauth/callback` on the space's host with the provider (`ctx.oauth.callbackUrl()` says the\n exact address, for a page that shows it). Not connected yet is a refusal with\n `code: \"oauth-not-connected\"`. `token` hands the access token only to a connection declaring `exposeToken: true`.\n- **Stateless:** nothing a function keeps in memory outlives the call \u2014 a module-level cache or counter starts empty\n every time, on whichever instance runs it. What must last goes in `ctx.kv`. A call gets 100 ms of CPU and 10 s;\n a task that needs more says so \u2014 `limits: { cpuMs: 1000, wallMs: 20000 }`, or `defineFunctions({ limits })` for\n all \u2014 up to the plan's ceiling. Asking above it is refused at save, never quietly cut.\n- **Routes** answer HTTP on the space's own host under `/fn/`: `routes: { \"GET /boards/:board\": (request, ctx) =>\n Response.json(\u2026) }` answers `/fn/boards/kanban` (`ctx.params.board`). No page may live under `/fn`.\n- **Saving builds and checks** the files: the batch is refused with each problem where it is (file and line). A\n namespace the platform uses (`kv`, `http`, `flow`\u2026) is refused.\n- **Try it** with `plitzi_try_function { task, params }` before a page relies on it: the value, the logs, the error.\n The live site runs what the space was last published with, never the draft. Running functions is part of the paid\n plans: on another plan they save, and a run answers why it did not start \u2014 tell the user rather than work around it.\n\n## Data\nJSON the space's pages read on the server and never serve \u2014 a catalog, prices, a menu: what a page needs whole and\nnobody edits element by element.\n\n- **Read** it as a provider does: `apiContainer` with `runtime: \"server\"` and `query: \"/data/products.json\"` reads\n `products.json` of `plitzi://data/{env}`, and the page arrives with it. A browser provider reading `/data/\u2026` is\n refused \u2014 the data is the server's.\n- **Write** it with `upsertDataFile { path, content }` (the whole file, as JSON text; `deleteDataFile { path }`\n removes one): a path of plain segments ending in `.json`. Saved whole, with the batch: a newer copy (somebody saved\n since you read it) refuses it \u2014 read it again.\n- **What a provider reads is in the page it renders**: data a page must not carry belongs in a server action, which\n answers only what is shown. The live site reads what the space was last published with, never the draft.\n\n## Realtime channels\nPages that see each other \u2014 cursors, presence, a shared board, a game. Three parts, all needed:\n\n1. **Declare** the topic pattern with `patchSettings { channels: { \"board:{id}\": { access: { mode: \"public\" }, publish: \"server\" } } }`.\n `publish: \"server\"` is for what must be validated and saved first; `\"clients\"` (the default) for what pages send\n directly \u2014 add `presence: true` for who-is-here.\n2. **Subscribe** with a `channel` element whose `topic` a pattern matches (`board:{{ id }}`, a route param).\n Its descendants bind `channel_<id>`: `connected`, `members`, `messages`, `last`, `retained`; flows use its `onMessage`,\n `onJoin`, `onLeave` triggers (`from`, `user` and the `state` the member announced \u2014 `onJoin` only for who\n came after this page) and its `publish` / `setPresence` callbacks.\n3. **Announce from the server**: an action whose last step is the `realtime.publish` task \u2014 validate, save, then say so.\n\nA topic no pattern matches is refused by the server and reported by the linter (`channel-topic`).\n\n**Private topics** (a room behind a password, a customer's order): declare the pattern `grant: true`. The action that\ndecides the visitor may be there ends with `realtime.grant { topic }` and answers its `grant`; the `channel`\nelement binds `grant` to it. Without one the topic is refused however well its name is known (`channel-grant`).\n`realtime.revoke { topic, grant }` takes one back \u2014 or all, naming none \u2014 and lets go whoever is on it with it.\n\n**State every screen shares** (a dashboard's lists, a board's settings): declare the pattern `retain: true` with\n`publish: \"server\"`. The server keeps the latest message of each type it says (`realtime.publish`) and hands them to\nevery page that joins \u2014 and to its `onMessage` flows, as if just said; the page binds `desk.retained.lists`, with no\nread of its own and no copy in `state`. `data: null` forgets a type; a topic keeps at most 64 types and 512 KB.\n\n**Two writers at once**: read-change-write with `kv.setIf` (written only if the value is still the one read \u2014 empty\n`expected` = only if nothing is there yet), ordered lists with `list.put` / `list.range`, and put\n`flow.rateLimit` first in any public action that writes.\n\n## Feature flags\nA flag turns a part of the space on or off without anyone editing it: a feature still being built, a version for\nbeta users, the old checkout kept until the new one ships. **Not a visibility** \u2014 visibility hides an element that is\nstill rendered; a flag decides whether it exists at all.\n\n- **Declare** with `upsertFlag { name, description?, value, rules? }`. `value` is its answer when no rule matches;\n `rules` are `[{ when, value }]` read top to bottom, the first match deciding. A rule's `when` is a rule group over\n `environment` (`main`, `development`, `staging`, `production`), `hostname`, `routeParams.<name>`,\n `queryParams.<name>` and the visitor: `user.authenticated`, `user.email`, `user.username`, `user.roles` (with\n `contains`). A group with no rules is skipped, never read as \"always\". `deleteFlag { name }` removes one.\n- **Gate** an element with `flag` on `upsertElement` / `patchElement`: `\"newCheckout\"` exists only while the flag is\n on, `\"!newCheckout\"` only while it is off \u2014 put both side by side for a rollout. On `upsertPage` a gated-off page\n answers 404. `null` on a patch removes the gate. Gated off, it is not rendered and its server data is not\n resolved \u2014 but the space's document, gated elements included, still reaches the browser: a flag is not a secret.\n- **Read** it anywhere a source is read: `{{ flags.newCheckout }}` in a binding, a `when` of a flow step, a computed\n value \u2014 and in a server action's steps, where it is resolved on the server.\n\nA gate or a read naming a flag the space does not declare is an error (`flag-undeclared`, `flag-unknown`): an\nundeclared flag is off. A declared flag nothing reads is a warning (`flag-unused`) \u2014 remove it once the feature\nships. The draft applies flags at once. Flags are not part of a snapshot: each environment has one set, shared by every\nsnapshot it serves \u2014 publishing a snapshot sends the draft's with it (and the snapshot keeps a copy, as a fallback), the\nbuilder's *Publish flags* sends only them, and a rollback keeps them. Above the space, the server rendering it, the SDK embedding it and a tester with the dev tools\nmay each override a flag; you only ever write the space's own.\n\n";