@plitzi/sdk-server 0.32.5 → 0.32.6

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 (168) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/core/services/mcp.js +1 -1
  3. package/dist/helpers/buildServerInfo.js +3 -9
  4. package/dist/index.js +2 -1
  5. package/dist/modules/mcp/catalogs/builtinCallbacks.js +204 -0
  6. package/dist/modules/mcp/catalogs/builtinComponents.js +170 -0
  7. package/dist/modules/mcp/catalogs/builtinElementCallbacks.js +50 -0
  8. package/dist/modules/mcp/catalogs/builtinTransformers.js +148 -0
  9. package/dist/modules/mcp/catalogs/builtinUtilities.js +90 -0
  10. package/dist/modules/mcp/{tools/operations/style → catalogs}/cssCatalog.js +75 -2
  11. package/dist/modules/mcp/catalogs/observed.js +90 -0
  12. package/dist/modules/mcp/catalogs/paramSpec.js +69 -0
  13. package/dist/modules/mcp/catalogs/registry.js +89 -0
  14. package/dist/modules/mcp/handler.js +12 -2
  15. package/dist/modules/mcp/helpers/agentPrompt.js +104 -0
  16. package/dist/modules/mcp/helpers/guide.js +334 -15
  17. package/dist/modules/mcp/helpers/interactions.js +123 -0
  18. package/dist/modules/mcp/helpers/log.js +54 -0
  19. package/dist/modules/mcp/helpers/space.js +158 -33
  20. package/dist/modules/mcp/helpers/uris.js +44 -0
  21. package/dist/modules/mcp/resources/canonical.js +6 -21
  22. package/dist/modules/mcp/resources/core.js +4 -3
  23. package/dist/modules/mcp/resources/primer.js +13 -8
  24. package/dist/modules/mcp/resources/register.js +37 -5
  25. package/dist/modules/mcp/resources/schema.js +30 -20
  26. package/dist/modules/mcp/resources/style.js +18 -11
  27. package/dist/modules/mcp/server.js +21 -7
  28. package/dist/modules/mcp/tools/apply/dispatch.js +38 -18
  29. package/dist/modules/mcp/tools/apply/index.js +19 -4
  30. package/dist/modules/mcp/tools/apply/writeResult.js +2 -1
  31. package/dist/modules/mcp/tools/index.js +1 -1
  32. package/dist/modules/mcp/tools/operations/index.js +13 -2
  33. package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +32 -0
  34. package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +36 -0
  35. package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.js +47 -0
  36. package/dist/modules/mcp/tools/operations/schema/{deleteElement.js → elements/deleteElement.js} +10 -6
  37. package/dist/modules/mcp/tools/operations/schema/{moveElement.js → elements/moveElement.js} +8 -6
  38. package/dist/modules/mcp/tools/operations/schema/{patchElement.js → elements/patchElement.js} +19 -7
  39. package/dist/modules/mcp/tools/operations/schema/{upsertElement.js → elements/upsertElement.js} +11 -5
  40. package/dist/modules/mcp/tools/operations/schema/{deleteFolder.js → folders/deleteFolder.js} +4 -4
  41. package/dist/modules/mcp/tools/operations/schema/{upsertFolder.js → folders/upsertFolder.js} +4 -4
  42. package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +52 -0
  43. package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +47 -0
  44. package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.js +43 -0
  45. package/dist/modules/mcp/tools/operations/schema/operations.js +25 -11
  46. package/dist/modules/mcp/tools/operations/schema/{deletePage.js → pages/deletePage.js} +8 -5
  47. package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +75 -0
  48. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +45 -0
  49. package/dist/modules/mcp/tools/operations/schema/shared.js +94 -2
  50. package/dist/modules/mcp/tools/operations/schema/translator.js +77 -10
  51. package/dist/modules/mcp/tools/operations/schema/{deleteVariable.js → variables/deleteVariable.js} +3 -3
  52. package/dist/modules/mcp/tools/operations/schema/{upsertVariable.js → variables/upsertVariable.js} +4 -4
  53. package/dist/modules/mcp/tools/operations/schema/write.js +78 -13
  54. package/dist/modules/mcp/tools/operations/style/{deleteDefinition.js → definitions/deleteDefinition.js} +4 -3
  55. package/dist/modules/mcp/tools/operations/style/{patchDefinition.js → definitions/patchDefinition.js} +6 -5
  56. package/dist/modules/mcp/tools/operations/style/{upsertDefinition.js → definitions/upsertDefinition.js} +5 -4
  57. package/dist/modules/mcp/tools/operations/style/{deleteGlobalStyle.js → globalStyles/deleteGlobalStyle.js} +4 -3
  58. package/dist/modules/mcp/tools/operations/style/{patchGlobalStyle.js → globalStyles/patchGlobalStyle.js} +6 -5
  59. package/dist/modules/mcp/tools/operations/style/{upsertGlobalStyle.js → globalStyles/upsertGlobalStyle.js} +5 -4
  60. package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.js +21 -0
  61. package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.js +28 -0
  62. package/dist/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.js +24 -0
  63. package/dist/modules/mcp/tools/operations/style/operations.js +14 -8
  64. package/dist/modules/mcp/tools/operations/style/translator.js +25 -1
  65. package/dist/modules/mcp/tools/operations/style/{deleteStyleVariable.js → variables/deleteStyleVariable.js} +4 -4
  66. package/dist/modules/mcp/tools/operations/style/{upsertStyleVariable.js → variables/upsertStyleVariable.js} +4 -4
  67. package/dist/modules/mcp/tools/operations/style/write.js +19 -11
  68. package/dist/modules/mcp/tools/read.js +1 -1
  69. package/dist/modules/mcp/tools/search.js +34 -27
  70. package/dist/modules/mcp/tools/shared/validator/audit.js +124 -0
  71. package/dist/modules/mcp/tools/shared/validator/batch.js +30 -0
  72. package/dist/modules/mcp/tools/shared/validator/bindings.js +70 -0
  73. package/dist/modules/mcp/tools/shared/validator/context.js +35 -0
  74. package/dist/modules/mcp/tools/shared/validator/css.js +47 -0
  75. package/dist/modules/mcp/tools/shared/validator/elements.js +55 -0
  76. package/dist/modules/mcp/tools/shared/validator/index.js +226 -0
  77. package/dist/modules/mcp/tools/shared/validator/interactions.js +106 -0
  78. package/dist/modules/mcp/tools/shared/validator/refs.js +28 -0
  79. package/dist/modules/mcp/tools/validate.js +23 -3
  80. package/dist/modules/ssr/preview.js +1 -1
  81. package/dist/modules/ssr/views/template.ejs +2 -0
  82. package/dist/src/index.d.ts +1 -1
  83. package/dist/src/modules/mcp/catalogs/builtinCallbacks.d.ts +23 -0
  84. package/dist/src/modules/mcp/catalogs/builtinComponents.d.ts +4 -0
  85. package/dist/src/modules/mcp/catalogs/builtinElementCallbacks.d.ts +20 -0
  86. package/dist/src/modules/mcp/catalogs/builtinTransformers.d.ts +28 -0
  87. package/dist/src/modules/mcp/catalogs/builtinTransformers.test.d.ts +1 -0
  88. package/dist/src/modules/mcp/catalogs/builtinUtilities.d.ts +18 -0
  89. package/dist/src/modules/mcp/{tools/operations/style → catalogs}/cssCatalog.d.ts +5 -1
  90. package/dist/src/modules/mcp/catalogs/index.d.ts +9 -0
  91. package/dist/src/modules/mcp/catalogs/observed.d.ts +48 -0
  92. package/dist/src/modules/mcp/catalogs/paramSpec.d.ts +42 -0
  93. package/dist/src/modules/mcp/catalogs/registry.d.ts +35 -0
  94. package/dist/src/modules/mcp/handler.d.ts +2 -2
  95. package/dist/src/modules/mcp/helpers/agentPrompt.d.ts +4 -0
  96. package/dist/src/modules/mcp/helpers/guide.d.ts +2 -1
  97. package/dist/src/modules/mcp/helpers/index.d.ts +4 -0
  98. package/dist/src/modules/mcp/helpers/interactions.d.ts +30 -0
  99. package/dist/src/modules/mcp/helpers/log.d.ts +8 -0
  100. package/dist/src/modules/mcp/helpers/log.test.d.ts +1 -0
  101. package/dist/src/modules/mcp/helpers/space.d.ts +67 -11
  102. package/dist/src/modules/mcp/helpers/uris.d.ts +28 -0
  103. package/dist/src/modules/mcp/index.d.ts +1 -1
  104. package/dist/src/modules/mcp/mcp.bench.d.ts +1 -0
  105. package/dist/src/modules/mcp/resources/canonical.d.ts +0 -1
  106. package/dist/src/modules/mcp/resources/index.d.ts +2 -3
  107. package/dist/src/modules/mcp/resources/primer.d.ts +2 -1
  108. package/dist/src/modules/mcp/resources/register.d.ts +2 -2
  109. package/dist/src/modules/mcp/server.d.ts +5 -2
  110. package/dist/src/modules/mcp/tools/apply/index.d.ts +191 -2
  111. package/dist/src/modules/mcp/tools/operations/index.d.ts +383 -4
  112. package/dist/src/modules/mcp/tools/operations/schema/bindings/deleteBinding.d.ts +17 -0
  113. package/dist/src/modules/mcp/tools/operations/schema/bindings/patchBinding.d.ts +25 -0
  114. package/dist/src/modules/mcp/tools/operations/schema/bindings/upsertBinding.d.ts +27 -0
  115. package/dist/src/modules/mcp/tools/operations/schema/{deleteElement.d.ts → elements/deleteElement.d.ts} +2 -2
  116. package/dist/src/modules/mcp/tools/operations/schema/{moveElement.d.ts → elements/moveElement.d.ts} +2 -2
  117. package/dist/src/modules/mcp/tools/operations/schema/{patchElement.d.ts → elements/patchElement.d.ts} +7 -2
  118. package/dist/src/modules/mcp/tools/operations/schema/{upsertElement.d.ts → elements/upsertElement.d.ts} +3 -3
  119. package/dist/src/modules/mcp/tools/operations/schema/{deleteFolder.d.ts → folders/deleteFolder.d.ts} +2 -2
  120. package/dist/src/modules/mcp/tools/operations/schema/{upsertFolder.d.ts → folders/upsertFolder.d.ts} +2 -2
  121. package/dist/src/modules/mcp/tools/operations/schema/index.d.ts +17 -11
  122. package/dist/src/modules/mcp/tools/operations/schema/interactions/deleteInteraction.d.ts +12 -0
  123. package/dist/src/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.d.ts +18 -0
  124. package/dist/src/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.d.ts +27 -0
  125. package/dist/src/modules/mcp/tools/operations/schema/operations.d.ts +131 -0
  126. package/dist/src/modules/mcp/tools/operations/schema/{deletePage.d.ts → pages/deletePage.d.ts} +2 -2
  127. package/dist/src/modules/mcp/tools/operations/schema/{upsertPage.d.ts → pages/upsertPage.d.ts} +3 -2
  128. package/dist/src/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +34 -0
  129. package/dist/src/modules/mcp/tools/operations/schema/shared.d.ts +53 -0
  130. package/dist/src/modules/mcp/tools/operations/schema/translator.d.ts +5 -2
  131. package/dist/src/modules/mcp/tools/operations/schema/{deleteVariable.d.ts → variables/deleteVariable.d.ts} +2 -2
  132. package/dist/src/modules/mcp/tools/operations/schema/{upsertVariable.d.ts → variables/upsertVariable.d.ts} +2 -2
  133. package/dist/src/modules/mcp/tools/operations/schema/write.d.ts +38 -8
  134. package/dist/src/modules/mcp/tools/operations/style/{deleteDefinition.d.ts → definitions/deleteDefinition.d.ts} +2 -2
  135. package/dist/src/modules/mcp/tools/operations/style/{patchDefinition.d.ts → definitions/patchDefinition.d.ts} +2 -2
  136. package/dist/src/modules/mcp/tools/operations/style/{upsertDefinition.d.ts → definitions/upsertDefinition.d.ts} +2 -2
  137. package/dist/src/modules/mcp/tools/operations/style/{deleteGlobalStyle.d.ts → globalStyles/deleteGlobalStyle.d.ts} +2 -2
  138. package/dist/src/modules/mcp/tools/operations/style/{patchGlobalStyle.d.ts → globalStyles/patchGlobalStyle.d.ts} +2 -2
  139. package/dist/src/modules/mcp/tools/operations/style/{upsertGlobalStyle.d.ts → globalStyles/upsertGlobalStyle.d.ts} +2 -2
  140. package/dist/src/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.d.ts +9 -0
  141. package/dist/src/modules/mcp/tools/operations/style/idStyles/patchIdStyle.d.ts +37 -0
  142. package/dist/src/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.d.ts +37 -0
  143. package/dist/src/modules/mcp/tools/operations/style/index.d.ts +11 -9
  144. package/dist/src/modules/mcp/tools/operations/style/operations.d.ts +70 -2
  145. package/dist/src/modules/mcp/tools/operations/style/shared.d.ts +1 -1
  146. package/dist/src/modules/mcp/tools/operations/style/translator.d.ts +4 -1
  147. package/dist/src/modules/mcp/tools/operations/style/{deleteStyleVariable.d.ts → variables/deleteStyleVariable.d.ts} +3 -3
  148. package/dist/src/modules/mcp/tools/operations/style/{upsertStyleVariable.d.ts → variables/upsertStyleVariable.d.ts} +3 -3
  149. package/dist/src/modules/mcp/tools/operations/style/write.d.ts +2 -7
  150. package/dist/src/modules/mcp/tools/preview.d.ts +191 -2
  151. package/dist/src/modules/mcp/tools/screenshot.d.ts +191 -2
  152. package/dist/src/modules/mcp/tools/shared/validator/audit.d.ts +4 -0
  153. package/dist/src/modules/mcp/tools/shared/validator/batch.d.ts +5 -0
  154. package/dist/src/modules/mcp/tools/shared/validator/bindings.d.ts +6 -0
  155. package/dist/src/modules/mcp/tools/shared/validator/context.d.ts +34 -0
  156. package/dist/src/modules/mcp/tools/shared/validator/css.d.ts +4 -0
  157. package/dist/src/modules/mcp/tools/shared/validator/elements.d.ts +6 -0
  158. package/dist/src/modules/mcp/tools/shared/validator/index.d.ts +8 -0
  159. package/dist/src/modules/mcp/tools/shared/validator/interactions.d.ts +3 -0
  160. package/dist/src/modules/mcp/tools/shared/validator/refs.d.ts +4 -0
  161. package/dist/src/modules/mcp/tools/validate.d.ts +191 -2
  162. package/dist/src/modules/mcp/types/aiSchema.d.ts +93 -1
  163. package/package.json +12 -10
  164. package/dist/modules/mcp/tools/operations/schema/registry.js +0 -55
  165. package/dist/modules/mcp/tools/operations/schema/upsertPage.js +0 -64
  166. package/dist/modules/mcp/tools/shared/validator.js +0 -262
  167. package/dist/src/modules/mcp/tools/operations/schema/registry.d.ts +0 -22
  168. package/dist/src/modules/mcp/tools/shared/validator.d.ts +0 -4
@@ -1,5 +1,56 @@
1
1
  //#region src/modules/mcp/helpers/guide.ts
2
- var serverInstructions = "Plitzi AI server: read-then-write editing of a Plitzi space. Reads follow a filesystem model — list cheap, read one item in detail on demand; never fetch a whole tree you do not need. Workflow: (1) read plitzi://primer/{env} once — it bundles the guide, types, css-properties and page/definition/variable summaries in a single call; (2) plitzi_search with include:\"detail\" to jump to elements — each hit then carries its uri, stateVersion AND full style/resolvedStyle, so an edit needs no per-element read; open a page skeleton or element only when you need its tree/detail (the skeleton already lists the style classes of each node, and plitzi_read fetches many uris at once); (3) plitzi_apply with dryRun to preview a batch; (4) plitzi_apply to persist, passing expectedResourceVersions to guard against concurrent edits — apply and search both hand back the versions you need for the next edit. Use patchElement / patchDefinition to change only some props / CSS (the upsert variants replace them all). An element read (and search include:\"detail\") inlines the CSS of the definitions it attaches under resolvedStyle, so you rarely need a separate definition read. Refs accept a semantic aiRef or the raw id. CSS is kebab-case (shorthands like border/padding are accepted); style vars are var(--name), schema vars are {{name}}.";
2
+ var serverInstructions = "Plitzi AI server: read-then-write editing of a Plitzi space. Reads follow a filesystem model — list cheap, read one item in detail on demand; never fetch a whole tree you do not need. Workflow: (1) read plitzi://primer/{env} once — it bundles the guide, types, css-properties and page/definition/variable summaries in a single call; (2) plitzi_search with include:\"detail\" to jump to elements — each hit then carries its uri, stateVersion AND full style/resolvedStyle, so an edit needs no per-element read; open a page skeleton or element only when you need its tree/detail (the skeleton already lists the style classes of each node, and plitzi_read fetches many uris at once); (3) plitzi_apply with dryRun to preview a batch; (4) plitzi_apply to persist, passing expectedResourceVersions to guard against concurrent edits — apply and search both hand back the versions you need for the next edit. Use patchElement / patchDefinition to change only some props / CSS (the upsert variants replace them all). An element read (and search include:\"detail\") inlines the CSS of the definitions it attaches under resolvedStyle, so you rarely need a separate definition read. Refs accept a semantic idRef ([A-Za-z0-9_-] starting with a letter, unique, chosen by you) or the raw id — the idRef is ALSO the runtime wiring key, so a provider source is `<type>_<idRef>.<field>`, visible to the provider’s DESCENDANTS only (bind inside its subtree). CSS is kebab-case and ATOMIC (shorthands like border/padding expanded; compound ones like flex/background/font rejected — use longhands); style vars are var(--name), schema vars are {{name}}. READERS — do not confuse them: MCP *resources* are the browsable catalog (list them, or open one by URI); plitzi_search FINDS refs by label/type/attribute; plitzi_read BATCH-fetches URIs you already hold. Reach for search/read to work; browse resources to discover. Elements also carry applied style variants + visibility (initialState), data bindings and interaction flows: edit them with patchElement (initialState), upsertBinding/patchBinding/deleteBinding, and upsertInteractionFlow/patchInteractionNode/deleteInteraction. An element read shows all three plus availableVariants (which variant each of its classes offers).";
3
+ var guideQuickstart = `# Plitzi AI MCP — quickstart
4
+ This is the condensed guide; read \`plitzi://guide\` for the full reference (every resource, op and example).
5
+
6
+ A space is **two schemas you edit together in one atomic \`plitzi_apply\` batch**: the **element schema** (tree of
7
+ pages/elements) and the **style schema** (definitions = CSS classes, tokens, theme). To style an element: write a
8
+ **definition** and attach it via the element's \`style.base\` in the same batch.
9
+
10
+ **Workflow:** (1) you already have this primer (guide + types + css + page/style summaries). (2) \`plitzi_search\`
11
+ with \`include:"detail"\` to find elements — each hit carries its \`uri\`, \`stateVersion\` and full style, so no
12
+ per-element read. (3) \`plitzi_apply\` with \`dryRun:true\` to preview. (4) \`plitzi_apply\` to persist, passing
13
+ \`expectedResourceVersions\` (uri → the stateVersion you read) for every resource you change — omitting it lets a
14
+ concurrent edit be lost. Use \`patchElement\`/\`patchDefinition\` to change only some props/CSS (upsert replaces all).
15
+
16
+ **Refs & wiring:** a ref is the semantic \`idRef\` (letters, numbers, hyphens and underscores, **starting with a
17
+ letter — no dots**) or the raw id. The idRef is the runtime wiring key: a provider's source is \`<type>_<idRef>\`, and
18
+ interactions target by it. A dot would split that path; an **underscore is fine** — the first \`_\` separates the type
19
+ from the idRef (element types have none), so \`list_food_item\` reads unambiguously as type \`list\`, idRef \`food_item\`.
20
+
21
+ **Styling:** CSS keys are **kebab-case** (\`background-color\`); \`var(--token)\` for style vars, \`{{name}}\` for schema
22
+ vars. Shorthands \`border\`/\`padding\`/\`margin\`/\`gap\` are expanded for you. Write **atomically — no compound
23
+ shorthands** (\`flex\`, \`background\`, \`font\`, \`transition\`, \`grid\` are rejected/warned): use their longhands, and
24
+ express flex layout as \`display: flex\` + \`flex-direction\`/\`align-items\`/… Mind a type's \`defaultStyle\` (\`text\`
25
+ is \`display: inline\`). Global styles (\`button {…}\`) and id styles (\`#id\`) have their own ops.
26
+
27
+ **Data bindings** (\`upsertBinding\`, category attributes|style|initialState): connect a \`source\` to a \`to\` field.
28
+ A source \`<type>_<idRef>\` is scoped to the provider's **DESCENDANTS only** — bind inside the provider's subtree
29
+ (module sources state/space/navigation/auth/collection are global). \`apiContainer.mockData\` is builder-only; set a
30
+ real \`query\` for production. \`transformers: [{action, params}]\` post-process the value — use exact action names
31
+ from \`plitzi://data-sources\`; \`twigTemplate\` formats it (the value is \`{{source}}\`, not \`{{value}}\`). \`when\` is
32
+ a QueryBuilder RuleGroup gating the binding.
33
+
34
+ **Interactions** (\`upsertInteractionFlow\`): a \`trigger\` node first, then callbacks/utilities **in order** (links
35
+ computed for you). Node types: \`callback\` (an element's own callback — \`elementId\` is that element), \`globalCallback\`
36
+ (a source module — omit \`elementId\`, the MCP sets it), \`utility\` (no element). Element \`setState\`
37
+ (category/key/value/revertOnFinish) ≠ global \`setState\` (source \`state\`, key/type/value). To turn a step off use
38
+ \`patchInteractionNode {enabled:false}\` — \`deleteInteraction\` removes it (destructive; confirm first). Any param
39
+ **value** can be a binding token \`{{ source }}\` (e.g. notification \`content: "{{ list_<idRef>.item.name }}"\`).
40
+
41
+ **Pages & navigation:** \`upsertPage\` — always set a **relative** \`slug\` (no leading \`/\`; the runtime and folder
42
+ slugs prepend the path). A \`:name\` segment (\`"posts/:postId"\`) is a route param, readable as \`{{name}}\` and as the
43
+ source \`navigation.routeParams.name\` → build dynamic pages this way. To move between pages **prefer the \`Link\`
44
+ element** (a container: \`mode\` "page"/"internal"/"external") over a \`navigate\` interaction.
45
+
46
+ **Touched resources must be malformation-free.** Editing an element/definition also checks its CURRENT stored content
47
+ and BLOCKS the save on any \`Pre-existing malformation in <resource>\` error (a broken transformer, malformed node,
48
+ invalid CSS) — even parts you did not touch. These are NOT from your change (the message says so); fix them in the
49
+ SAME batch and re-apply (the check runs on the result, so the fix unblocks it). \`Pre-existing issue\` warnings advise
50
+ but do not block.
51
+
52
+ Read \`plitzi://guide\` before anything above is unclear.
53
+ `;
3
54
  var guideText = `# Plitzi AI MCP — usage guide
4
55
 
5
56
  A Plitzi space is **two separate schemas** you edit together:
@@ -25,7 +76,10 @@ Never download a whole tree you do not need.
25
76
  **summaries** in one read. Fetch this first instead of the individual resources below. Summaries only — open a
26
77
  page skeleton or element for its tree/detail.
27
78
  - \`plitzi://guide\` — this guide.
28
- - \`plitzi://types\` — element types **observed in this space** (ground truth): props, slots, subTypes.
79
+ - \`plitzi://types\` — element types **observed in this space** (ground truth): props, slots, subTypes, plus each
80
+ type's \`label\`, \`description\` (what it is FOR) and \`category\`, and a \`source\` (\`builtin\` | \`plugin\` | \`unknown\`).
81
+ Read the descriptions to pick the right type — e.g. \`apiContainer\` fetches backend data into the frontend,
82
+ \`link\` navigates between pages, \`list\` repeats a template over a data array. \`plugin\` types are custom elements.
29
83
  - \`plitzi://css-properties\` — valid kebab-case CSS property keys.
30
84
  - \`plitzi://schema/{env}/pages\` — page **summaries** (ref, label, elementCount, folder). No element trees.
31
85
  - \`plitzi://folders/{env}\` — page **folders** (the sidebar tree): ref, name, slug, parentId. \`/{ref}\` for one.
@@ -39,17 +93,38 @@ Never download a whole tree you do not need.
39
93
  Its \`resolvedStyle\` inlines the **CSS of every definition** the element attaches (keyed by class ref), so you
40
94
  can see and edit its style without a separate definition read. Its \`globalStyles\` lists the **global element
41
95
  selectors** that also affect it (the CSS equivalent of \`button { … }\`, keyed by the type they target) — every
42
- element of that type inherits them. Edit a global only through the global-style tools (never per element).
96
+ element of that type inherits them. Edit a global only through the global-style tools (never per element). If the
97
+ element carries a DOM \`id\` that an id rule matches, its \`idStyle\` (\`#id\`) is inlined too.
43
98
  - \`plitzi://definitions/{env}\` — the **names** of every style definition.
44
99
  - \`plitzi://definitions/{env}/{ref}\` — one definition's CSS.
45
100
  - \`plitzi://global-styles/{env}\` — element **types** that have a site-wide global style. \`/{componentType}\` for one.
101
+ - \`plitzi://id-styles/{env}\` — DOM **ids** that have an id rule (\`#id\`) targeting a single element. \`/{targetId}\` for one.
46
102
  - \`plitzi://style-variables/{env}\` — design tokens by category. \`/{category}\` for one.
47
103
  - \`plitzi://schema-variables/{env}\` — space-level values referenced in props as \`{{name}}\`.
104
+ - \`plitzi://settings/{env}\` — space-level settings: the global \`customCss\` and the state/auth (user-provider) config.
105
+ - \`plitzi://interactions/{env}\` — interaction **actions** observed in this space (grouped by node type): the
106
+ vocabulary for interaction flows.
107
+ - \`plitzi://data-sources/{env}\` — data-source **paths** and binding targets observed in this space: the
108
+ vocabulary for data bindings.
48
109
 
49
110
  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.
50
111
 
51
112
  Data resources return \`{ stateVersion, data }\`. Keep \`stateVersion\` for optimistic concurrency.
52
113
 
114
+ **Reuse what you already know — don't re-scan an unchanged page.** A page read (\`plitzi://schema/{env}/pages/{ref}\`)
115
+ returns a \`stateVersion\` that is an **aggregate of the whole page**: it changes if and only if some element on the
116
+ page changed. Its skeleton \`tree\` also carries a \`stateVersion\` **per node**, identical to the one a direct element
117
+ read or search hit returns for that element. So when you come back to a page you already inspected:
118
+ 1. Re-read just the page skeleton and compare its top-level \`stateVersion\` to the one you held. **Same → nothing
119
+ changed since your read; skip re-reading and re-searching the tree** and act on what you already know.
120
+ 2. If it differs, diff the per-node \`stateVersion\`s against the ones you cached and \`plitzi_read\` **only the nodes
121
+ that changed** — never re-search or re-read the whole tree.
122
+
123
+ This is a **read-time** shortcut, not a safety guarantee. **Other agents/sub-agents may edit the same space
124
+ concurrently**, so a version you cached can go stale between your read and your write. Never skip the write-time
125
+ check below on the strength of a cached hash — the guarantee that no concurrent edit is lost comes only from
126
+ \`expectedResourceVersions\` on \`plitzi_apply\`, which re-validates against the live data at write time.
127
+
53
128
  ## Navigating (files analogy)
54
129
  Pages and containers are folders; elements are files. **Prefer \`plitzi_search\` (especially with \`include: "detail"\`)
55
130
  over reading elements one by one** — it jumps straight to elements by label/type/attribute and each hit already
@@ -61,7 +136,8 @@ stateVersion) and returns any **style definitions** whose name matches the query
61
136
  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.
62
137
 
63
138
  ## Tools (write)
64
- - \`plitzi_validate\` — check a batch, returns teachable errors/warnings. Writes nothing.
139
+ - \`plitzi_validate\` — check a batch, returns teachable errors/warnings. Writes nothing. Also reports **pre-existing
140
+ malformations** in any resource the batch touches (see below).
65
141
  - \`plitzi_apply\` — validate → apply → persist atomically. Rejects the whole batch on any error or conflict. Pass
66
142
  \`dryRun: true\` to apply in memory only and get the same result back (changed versions + full element detail)
67
143
  without persisting — inspect it, then re-run without \`dryRun\` to commit.
@@ -70,6 +146,17 @@ When you do hold several refs to open (e.g. from a skeleton), read them together
70
146
  ready-made uris from search / a write response; each result is \`{ uri, stateVersion, data }\` or a teachable error,
71
147
  so one bad uri never fails the batch. Use it instead of N single reads whenever you already hold several refs.
72
148
 
149
+ ## Readers: resources vs plitzi_search vs plitzi_read (do not confuse them)
150
+ Three ways to read, each for a different moment — pick by what you have in hand:
151
+ - **MCP resources** (the \`plitzi://…\` catalog above) — the **browsable index**. List them to discover what exists, or
152
+ open one by URI when you are exploring. This is the passive catalog, not a tool.
153
+ - **\`plitzi_search\`** — you know *what* you want but not its **ref/uri** ("the hero button"). Search finds it by
154
+ label/type/attribute and hands back the uri + stateVersion (and, with \`include:"detail"\`, the full element).
155
+ - **\`plitzi_read\`** — you **already hold one or more uris** (from search or a write response) and want their
156
+ content in one batch. It is the tool form of opening resources, for when you have the addresses.
157
+ Rule of thumb: **discover → resources**, **find a ref → plitzi_search**, **fetch known uris → plitzi_read**. Never
158
+ hand-build a URI to guess your way to an element — search for it instead.
159
+
73
160
  Write tools return what **changed** (\`{ uri, stateVersion }\`) plus counts, and the **full detail of every element
74
161
  they created or updated** — each with its own \`uri\` and \`stateVersion\` (\`elements: [...]\`) so a follow-up edit of
75
162
  the same element needs **no intermediate read**. Other resources (pages, definitions, variables) still report only
@@ -77,32 +164,235 @@ uri+stateVersion — re-read them if you need their new content. The operation s
77
164
  schema (discriminated by \`type\`).
78
165
 
79
166
  ## Addressing
80
- Refs are a semantic \`aiRef\` you choose (e.g. \`"hero.cta"\`) or the element's **raw id**. Both always resolve, so
81
- schemas predating aiRef keep working through ids. Creating an element stores its \`ref\` as the aiRef.
167
+ Refs are the semantic \`idRef\` (e.g. \`"hero-cta"\`) or the element's **raw id** both resolve. Creating an element
168
+ stores the \`ref\` you chose as its **idRef**.
169
+
170
+ The idRef is not just an alias — it is the **wiring key the runtime uses**. A provider registers its data source as
171
+ \`<type>_<idRef>\`, so a \`source\` you write against a ref resolves to that element at runtime with no id translation.
172
+ Rules for a **new** ref (both are enforced; a violation fails the batch):
173
+ - Charset \`[A-Za-z0-9_-]\`, **starting with a letter** (e.g. \`"products-api"\`, \`"food_item"\`). A \`.\` would split the
174
+ \`<type>_<idRef>.<field>\` source path and the interaction target lookup, so **no dots**. An **underscore is
175
+ allowed**: the FIRST \`_\` separates \`<type>\` from \`<idRef>\` and element types are camelCase with none, so
176
+ underscores inside the idRef are unambiguous (\`list_food_item\` → type \`list\`, idRef \`food_item\`).
177
+ - **Unique across the space**; creating a ref that is taken is rejected (address the existing element instead).
178
+
179
+ An idRef is **optional** on an element — one built in the builder may not have it. The consequence is specific: an
180
+ element without an idRef **publishes no data source** and **holds no interactions**, because the runtime keys
181
+ everything by idRef and the raw id is never a fallback. You do not have to fix this by hand: writing an
182
+ interaction **mints an idRef for you** — the element that hosts the flow, and any element a node targets, is given
183
+ a free \`<type>-<n>\` ref if it lacks one, and the flow is wired to it. A node target you write may be a raw id; it
184
+ is normalised to that element's idRef. (To make an element a data-source **provider** to bind against, give it an
185
+ idRef explicitly with \`patchElement\`, or create it with the \`ref\` you want — a created element stores its ref as
186
+ its idRef.)
187
+
188
+ **Renaming** an idRef moves the wiring key: every binding source and interaction target across the space that
189
+ pointed at the old name is repointed with it, so the element stays wired. You do not have to rewrite them.
82
190
 
83
191
  ## Styling (crosses both schemas)
192
+ - **Mind the type's intrinsic default style.** A type renders with a base CSS *before* any class is attached — read
193
+ it from \`defaultStyle\` on the type in \`plitzi://types\` (the primer includes it). Do not assume \`display: block\`:
194
+ \`text\`, for one, defaults to \`display: inline\`, so margins/width/vertical padding behave differently. If you need
195
+ block/flex layout on such an element, set \`display\` explicitly in your definition rather than relying on a default.
196
+ - **Images: preserve aspect ratio.** Setting only \`width\` and \`height\` (or forcing both) distorts an image. Change
197
+ one dimension and let the other be \`auto\`, or set \`aspect-ratio\` with \`object-fit: cover\`/\`contain\`, so the
198
+ image scales without stretching.
199
+ - **Font size and line height move together.** When you change \`font-size\`, set \`line-height\` in the same edit
200
+ (prefer a unitless ratio like \`1.5\`, which tracks the font size). Changing one without the other leaves cramped or
201
+ loosely-spaced text — they are a joint change, not two separate ones.
84
202
  - A definition lives in the **style schema**; an element's \`style.base\` (element schema) is the link that applies
85
203
  it. Styling an element = upsertDefinition + upsertElement with that ref in \`style.base\`, in one batch.
86
204
  - CSS keys are **kebab-case** (\`background-color\`). camelCase is rejected — read \`plitzi://css-properties\`.
87
205
  - Common **shorthands are accepted** and expanded for you: \`border\`, \`border-{side}\`, \`border-radius\`,
88
206
  \`padding\`, \`margin\`, \`inset\`, \`gap\` (they persist as their longhand keys).
207
+ - **Write CSS atomically — no multi-value compound shorthands.** Plitzi stores each property on its own so a
208
+ breakpoint/state/variant can override just that one, so \`flex\`, \`background\`, \`font\`, \`transition\`,
209
+ \`animation\`, \`grid\`, \`place-*\`, \`outline\`, \`columns\` are **rejected** (or warned) — use their longhands
210
+ instead: \`background\` → \`background-color\`/\`background-image\`/…, \`font\` → \`font-size\`/\`font-weight\`/
211
+ \`line-height\`, \`flex: 1\` → \`flex-grow\`/\`flex-shrink\`/\`flex-basis\`. **Flex layout is not a \`flex\` value**: set
212
+ \`display: flex\` **plus** \`flex-direction\`, \`align-items\`, \`justify-content\` as separate properties.
89
213
  - CSS is grouped by breakpoint: \`desktop\`, \`tablet\`, \`mobile\`.
90
214
  - Reference a style variable in CSS as \`var(--name)\`; a schema variable in a prop as \`{{name}}\`.
91
- - \`element.style.base\` is a list of definition refs; other slots go under \`element.style.slots\`.
92
- - **Two kinds of style live in the style schema do not confuse them:**
215
+ - \`element.style.base\` is a **list** of definition refs; other slots go under \`element.style.slots\`.
216
+ - **An element can attach SEVERAL classes at once, and they all apply.** \`style.base\` holds a list, and each
217
+ non-base slot holds its own — every attached definition contributes CSS, and they **cascade** (a later class, then a
218
+ global/id rule, overrides an earlier one on the same property). So when a style looks wrong, the culprit may be
219
+ ANY attached class, not the one you just edited: read the element's \`resolvedStyle\` (it inlines the CSS of every
220
+ class it attaches, keyed by ref) together with its \`globalStyles\`/\`idStyle\` and the type's \`defaultStyle\`, and
221
+ fix the class that actually sets the property — do not just pile another class on top.
222
+ - **Three kinds of style live in the style schema — do not confuse them:**
93
223
  - **Definitions** = reusable CSS **classes** (\`upsertDefinition\`/\`patchDefinition\`/\`deleteDefinition\`, keyed by a
94
224
  class \`ref\`). Attach one to an element via \`style.base\` to style **that** element (and anything else that opts in).
225
+ This is the **default** way to style one element.
95
226
  - **Global styles** = the CSS equivalent of a bare element selector like \`button { … }\`
96
227
  (\`upsertGlobalStyle\`/\`patchGlobalStyle\`/\`deleteGlobalStyle\`, keyed by \`componentType\`). They style **every**
97
228
  element of that type at once. Use these for site-wide intent — e.g. "all buttons rounded":
98
229
  \`{ "type": "upsertGlobalStyle", "componentType": "button", "desktop": { "border-radius": "9999px" } }\`.
99
- - The two share one name space, so a class op refuses a name held by a global and vice-versa (guards against a
100
- typo silently rewriting every element of a type). If refused, you targeted the wrong kind — switch tools or
101
- rename. To style one element only, never reach for a global.
230
+ - **Id styles** = the CSS equivalent of an id selector like \`#hero { }\`
231
+ (\`upsertIdStyle\`/\`patchIdStyle\`/\`deleteIdStyle\`, keyed by \`targetId\`). They style the **single** element whose
232
+ DOM \`id\` attribute equals \`targetId\` — so the element must carry that \`id\` (set it in its props). Prefer a
233
+ **definition** for one element; reach for an id style only when a specific, uniquely-identified node must be
234
+ targeted by id: \`{ "type": "upsertIdStyle", "targetId": "hero", "desktop": { "min-height": "100vh" } }\`.
235
+ - The three share one name space, so an op refuses a name held by another kind (guards against a typo silently
236
+ rewriting every element of a type, or converting a class into an id rule). If refused, you targeted the wrong
237
+ kind — switch tools or rename.
238
+
239
+ ## Style variants & element state
240
+ A **variant** is a named CSS override on a definition (e.g. a button class with a \`primary\` variant). It takes two
241
+ steps across the two schemas:
242
+ - **Declare** the variant CSS on the class (style schema): \`upsertDefinition\`/\`patchDefinition\` with
243
+ \`variants: { "primary": { "desktop": { "background-color": "#111" } } }\` (per slot under \`slots.<slot>.variants\`).
244
+ - **Apply** it to an element (element schema): \`initialState.styleVariant\` =
245
+ \`{ "<class-ref>": { "base": "primary" } }\` — a slot name instead of \`base\` targets that slot; an array applies
246
+ several. Set it via \`upsertElement\`/\`patchElement\`.
247
+ An element read reports \`availableVariants\` (which variant each attached class offers) and the element's current
248
+ \`initialState\`, so you can see a button **has** a \`primary\` variant and whether it uses it. If the user asks for a
249
+ variant that does not exist yet, **create it (upsertDefinition variants) and apply it in the same batch**.
250
+ - \`initialState.visibility\` (boolean) sets whether the element starts shown or hidden.
251
+
252
+ ## Data bindings
253
+ Connect a data **source** to an element field. A binding is \`{ to, source, transformers?, when?, enabled? }\` grouped
254
+ by **category**: \`attributes\` (a prop), \`style\` (a style value), \`initialState\` (an initial-state key).
255
+ - \`upsertBinding\` adds one, or replaces the binding already feeding the same \`to\` (or \`id\`).
256
+ - \`patchBinding\` edits an existing one (matched by \`to\`/\`id\`); \`deleteBinding\` removes it.
257
+ Discover valid source paths **and the transformer catalog** in \`plitzi://data-sources/{env}\`. Example — feed an API
258
+ list into a list element:
259
+ \`{ "type": "upsertBinding", "pageRef": "home", "ref": "myList", "category": "attributes",
260
+ "binding": { "to": "items", "source": "apiContainer_x.data" } }\`.
261
+
262
+ **Source scope — a source is visible to the provider's DESCENDANTS only.** An element source named
263
+ \`<type>_<idRef>\` (e.g. \`apiContainer_products\`, \`list_food-list\`) is published by that element into the scope of
264
+ its **subtree**, so **only elements INSIDE the provider can bind to it**. Binding a sibling or an unrelated element
265
+ to it resolves to nothing at runtime. So to consume \`apiContainer_products.data\`, the bound element must live under
266
+ that apiContainer; inside a \`list\`, the repeated \`listItem\` and its children read the per-row source
267
+ (\`list_<idRef>.item.<field>\`). Module sources (no \`<type>_<idRef>\` head — \`state\`, \`space\`, \`navigation\`,
268
+ \`auth\`, \`collection\`) are global and bindable anywhere. Binding an element to an element source outside its
269
+ provider's subtree is schema-valid but **broken at runtime** (the source is not in scope), so
270
+ \`plitzi_validate\`/\`plitzi_apply\` treat it as an **error and reject the batch** — move the element under the
271
+ provider, or bind a source that is in scope.
272
+
273
+ **mockData is builder-only.** An \`apiContainer\`'s \`mockData\` prop feeds sample data **while editing in the
274
+ builder**; the published runtime fetches the real \`query\` instead. Never rely on mockData as the production source —
275
+ set a real \`query\`/\`method\` so the binding has data at runtime.
276
+
277
+ **\`transformers\` — post-process the value before it reaches the field** (\`source → t₁ → t₂ → field\`). An array of
278
+ \`{ action, params }\`; the runtime runs them in order and resolves each by its \`action\` alone, so an **unknown
279
+ action is silently skipped** and the raw value passes through. Use the **exact** action names from
280
+ \`plitzi://data-sources\` (\`transformers\`). The most common is **\`twigTemplate\`** to format a value — the incoming
281
+ value is the **\`{{source}}\`** token (NOT \`{{value}}\`); \`{{sourceTo}}\` is the field's previous value. Example —
282
+ show a number with units:
283
+ \`{ "type": "upsertBinding", "pageRef": "home", "ref": "food-item-time", "category": "attributes",
284
+ "binding": { "to": "content", "source": "list_food-list.item.cookTimeMinutes",
285
+ "transformers": [ { "action": "twigTemplate", "params": { "template": "{{source}} min de cocción" } } ] } }\`.
286
+ Other transformers: \`dateConverter\` (format a date/timestamp), \`capitalize\`, \`stringToArray\` (split on a
287
+ separator), \`arrayMap\` (remap the keys of each object in an array), \`staticValue\`. Transformer \`params\` values are
288
+ strings. Each transformer also takes an optional \`enabled\` flag: set \`"enabled": false\` to keep it in the chain but
289
+ skip it at runtime (defaults to true) — the value passes through untouched, and a disabled transformer is not
290
+ validated.
291
+
292
+ **\`when\` — gate the binding** with a QueryBuilder RuleGroup: the binding only applies when the guard passes against
293
+ the data source. Shape: \`{ "combinator": "and", "rules": [ { "field": "<path>", "operator": "=", "value": "x" } ] }\`
294
+ (operators: \`=\`, \`!=\`, \`<\`, \`>\`, \`contains\`, \`beginsWith\`, \`empty\`, \`in\`, \`between\`, …; nest RuleGroups for
295
+ and/or). The guard is validated structurally. Example — only bind when a flag is set:
296
+ \`"when": { "combinator": "and", "rules": [ { "field": "status", "operator": "=", "value": "published" } ] }\`.
297
+
298
+ ## Interactions
299
+ An interaction **flow** is a **trigger** (an event like \`onClick\`, \`onPageLoad\`) followed by the callbacks/utilities
300
+ it runs, in order. You pass the steps **in order** and the stored beforeNode/afterNode/flowId links are computed for
301
+ you — never wire them by hand. Each step also has an \`enabled\` flag (see disable vs delete below).
302
+
303
+ **Node types & \`elementId\`** — a step names which element (or module) provides the callback it runs. Picking the
304
+ **wrong node type for an action** makes the runtime resolve it against nothing, so the step **silently does nothing**:
305
+ - \`trigger\` — the event; belongs to the host element. \`elementId\` defaults to the host.
306
+ - \`callback\` — a callback provided by a **specific element**. \`elementId\` is that element's ref (the flow host by
307
+ default, or another element to act on); give its ref or raw id and it is normalised to the idRef. Every element
308
+ registers a built-in **\`setState\`** callback that changes **its own attribute or state**: params
309
+ \`category\` (\`"attribute"\` — set a prop like \`content\`/\`disabled\` — or \`"state"\` — \`visibility\` or a style
310
+ selector), \`key\`, \`value\` (a **scalar** whose type follows the target attribute — a real boolean \`true\`/\`false\`
311
+ for a boolean attribute, a number for a numeric one, otherwise a string), and **\`revertOnFinish\`**. Set
312
+ \`revertOnFinish: true\` for a **temporary** change (a "loading…" label, disabling a button while it works): it is
313
+ **undone automatically when the flow finishes**, so you do **NOT** add manual restore steps at the end. This element
314
+ \`setState\` has **no** \`type\` param (that belongs to the global one below). An element type may also register its
315
+ own extra callbacks.
316
+ - \`globalCallback\` — a callback provided by a **source module**, NOT by any element: \`addNotification\` (source
317
+ \`space\`), \`setState\`/\`clearState\` (\`state\`), \`navigate\` (\`navigation\`), \`authLogin\`/\`authLogout\`/
318
+ \`authRefreshDetails\` (\`auth\`), \`addCollectionRecord\`/\`updateCollectionRecord\`/\`removeCollectionRecord\`
319
+ (\`collection\`). Its \`elementId\` is the **source module id**, never the host element — a node that stored the host
320
+ idRef here would resolve to nothing at runtime. **Omit \`elementId\`**: the MCP sets the correct source and fills the
321
+ builder's **param defaults** (e.g. \`addNotification\` gets \`autoDismiss:true\`, \`autoDismissTimeout:5000\`,
322
+ \`placement:"top-right"\`, \`appeareance:"success"\`) for any params you leave out. Use **only** the params each
323
+ callback declares (exact spelling) — for \`addNotification\` the visible text goes in \`content\`; there is **no**
324
+ \`title\`/\`message\`/\`type\` param, and any unknown key is dropped. See the full param schema for each callback under
325
+ \`globalCallbacks\` in \`plitzi://interactions/{env}\`.
326
+ - **Two \`setState\`s — do not mix them:** the **element** \`setState\` (nodeType \`callback\`, on an element,
327
+ category/key/value/revertOnFinish) changes THAT element's attribute/state and is what you want to change a button's
328
+ label or disabled flag. The **global** \`setState\` (nodeType \`globalCallback\`, source \`state\`, key/type/value)
329
+ writes \`runtime.state.<key>\`. They share a name but have different node types AND different params.
330
+ - \`utility\` — a built-in utility action (no element/source module); nodeType \`utility\`. Use the **exact** param
331
+ names: \`delayTime\` waits \`time\` milliseconds (**not** \`delay\`), \`twigTemplate\` (\`returnMode\`, \`template\`),
332
+ \`webHook\` (\`url\`, \`method\`, …). See \`utilities\` in \`plitzi://interactions/{env}\`.
333
+
334
+ **A param value can be a data binding.** Any interaction param may hold a \`{{ source }}\` token instead of a literal —
335
+ it resolves at runtime exactly like a prop binding, using the same source grammar (\`<type>_<idRef>.<path>\`, or a
336
+ module source like \`navigation\`/\`state\`). This is how a step reacts to *the data in context*: inside a \`listItem\`,
337
+ a click on a row can show \`addNotification\` with \`content: "{{ list_<idRef>.item.name }}"\` — the clicked row's field.
338
+ The value follows the source's type, so a token is valid even where a param expects a boolean/number. Copy/paste of an
339
+ element repoints these tokens to the new idRefs automatically, along with the element's bindings.
340
+
341
+ **Navigating between pages — prefer the \`Link\` element over an interaction.** For a plain "go to page X" the right
342
+ tool is a \`link\` element (a container, see *Pages & folders*), not a \`navigate\` interaction step. Use the
343
+ \`navigate\` globalCallback only when the navigation is one step of a larger flow (e.g. submit a form, then go).
344
+
345
+ Tools:
346
+ - \`upsertInteractionFlow\` — create or replace one flow. The FIRST node must be a \`trigger\`. Pass \`flowId\` (the
347
+ trigger's node id) to replace an existing flow. Example (elementId omitted — the MCP wires it to \`space\` and fills
348
+ the notification defaults):
349
+ \`{ "type": "upsertInteractionFlow", "pageRef": "home", "ref": "cta", "nodes": [
350
+ { "nodeType": "trigger", "action": "onClick", "title": "Click" },
351
+ { "nodeType": "globalCallback", "action": "addNotification", "title": "Notify",
352
+ "params": { "content": "Saved!" } } ] }\`.
353
+ - \`patchInteractionNode\` — change one step in place (by \`nodeId\`); \`params\` merge onto the node.
354
+
355
+ **Disable vs delete a step — do not confuse them (three different intents):**
356
+ - **Disable / deactivate / turn off a step** (keep it in the flow, just stop it running): \`patchInteractionNode\`
357
+ with \`{ "enabled": false }\`. Re-enable with \`{ "enabled": true }\`. This is NOT a deletion — the step stays.
358
+ - **Remove one step** from a flow: \`deleteInteraction\` with \`nodeId\` (its neighbors are re-linked).
359
+ - **Remove the whole flow**: \`deleteInteraction\` with \`flowId\` (the trigger node id).
360
+
361
+ So "deactivate the addNotification step" means \`patchInteractionNode { enabled: false }\` — never delete the step, and
362
+ never delete the flow. \`deleteInteraction\` is **destructive and not undoable**: only use it when the user asked to
363
+ *remove* something, and **confirm with the user before deleting** a step or a flow.
364
+
365
+ Discover valid actions in \`plitzi://interactions/{env}\`: \`actions\` = observed, \`globalCallbacks\` /
366
+ \`elementCallbacks\` / \`utilities\` = the built-in vocabularies with their full param schema, so you know the exact
367
+ node type and valid params per action. An element read lists its flows as ordered nodes (each with its \`id\` and
368
+ \`enabled\`), so a follow-up patch/delete needs no extra read.
102
369
 
103
370
  ## Pages & folders
371
+ - **Always set a \`slug\` when creating a page** (\`upsertPage\`) — it is the page's URL path and good practice for a
372
+ clean, stable route (e.g. \`"pricing"\` or \`"posts/:postId"\`). Omit it and the page ref is used as the slug,
373
+ and \`plitzi_validate\`/\`plitzi_apply\` warn so you remember to set a meaningful one.
374
+ - **A page slug is RELATIVE — do NOT start it with \`/\`.** The runtime prepends the leading slash (and any folder
375
+ path) itself, so a leading slash doubles it. Write \`"pricing"\`, not \`"/pricing"\`. (upsertPage strips a leading
376
+ slash for you, but write it relative.)
377
+ - **Dynamic pages — route params.** A slug segment written \`:name\` (e.g. \`"posts/:postId"\`) is a **route param**,
378
+ exactly like React Router. On that page it is readable **two ways**: as \`{{name}}\` inside a prop, and as the
379
+ data-binding source **\`navigation.routeParams.name\`** (the \`navigation\` module source, global — bindable
380
+ anywhere). So a blog is a \`"posts"\` list page plus a \`"posts/:postId"\` detail page whose \`apiContainer\` query
381
+ binds \`navigation.routeParams.postId\` to fetch that one post. (\`navigation.queryParams.<name>\` exposes \`?query=\`
382
+ string params the same way.)
383
+ - **Navigate with the \`Link\` element, not an interaction.** \`link\` is a **container** — it wraps any children and
384
+ navigates on click, so it is the default way to move between pages. Its \`mode\`: \`"page"\` links to another space
385
+ page (set \`href\` to the target page, folder path resolved for you); \`"internal"\` takes a path inside the space and
386
+ resolves \`{{token}}\` templates in it, so a row's "view" link is \`mode:"internal", href:"posts/{{postId}}"\`;
387
+ \`"external"\` is a full URL. \`target\` is \`self\`/\`blank\`/\`parent\`/\`top\`. Reach for the \`navigate\` globalCallback
388
+ only when navigation must be **one step inside a larger interaction flow** (e.g. save, then go) — for a plain link,
389
+ use \`link\`.
390
+
104
391
  Pages can be grouped into **folders** (the sidebar tree). A folder is \`{ ref, name, slug, parentId? }\`; its \`ref\`
105
- **is its id** (there is no separate aiRef), and that id is what a page and a nested folder reference.
392
+ **is its id** (there is no separate idRef), and that id is what a page and a nested folder reference.
393
+ - **Folder slugs PREPEND to the page URL — this is how nested URLs are built.** The full path is each ancestor
394
+ folder's slug plus the page slug, joined by \`/\`: a page at slug \`"1-1-1"\` inside \`folder-1\` > \`folder-1-1\`
395
+ resolves to \`/folder-1/folder-1-1/1-1-1\`. So a folder slug is part of the route; keep folder slugs relative too.
106
396
  - Create/rename/move a folder with \`upsertFolder\` (the \`ref\` you pass on create becomes its id — pick a stable one
107
397
  like \`"blog"\`). Nest it under another with \`parentId\` (a folder ref); \`parentId: null\` moves it back to the root.
108
398
  - Put a page in a folder with \`upsertPage\`'s \`folder\` (a folder ref). A page's \`folder\` is always either **empty
@@ -111,6 +401,21 @@ Pages can be grouped into **folders** (the sidebar tree). A folder is \`{ ref, n
111
401
  rejected, never stored.
112
402
  - \`deleteFolder\` removes a folder and **promotes its contents up one level** — its child folders and its pages move
113
403
  to its parent (or the root). A folder cannot be nested under itself or one of its descendants.
404
+ - **Disable a page** with \`upsertPage\`'s \`enabled: false\`; \`enabled: true\` re-enables it (defaults to enabled, and
405
+ a page read reports its current \`enabled\`). Disabling only affects the **published SDK runtime** — the page stops
406
+ being routable/accessible to end users. It stays fully **editable here**: you can still read it and apply any op to
407
+ a disabled page. This does not delete it — \`deletePage\` does.
408
+
409
+ ## Settings
410
+ Space-level configuration lives in \`plitzi://settings/{env}\` and is edited with a single **\`patchSettings\`** op
411
+ (merge — only the fields you pass change):
412
+ - \`customCss\` — **raw global CSS** injected for the whole space. Use it only for genuinely site-wide rules
413
+ (\`@keyframes\`, \`@font-face\`, resets). To style an element, write a **definition** and attach it — never customCss.
414
+ - \`keepState\` / \`stateStorage\` — persist element state across reloads (\`localStorage\`/\`sessionStorage\`).
415
+ - **User provider / auth**: \`userProvider\` (\`auth0\`|\`basic\`|\`custom\`|\`""\` to disable), \`auth0Domain\`,
416
+ \`auth0ClientId\`, \`tokenStorage\`, and the \`loginUrl\`/\`userUrl\`/\`refreshUrl\`/\`logoutUrl\` + \`detailsPath\`/
417
+ \`tokenPath\`/\`expirationTimePath\` mapping. Example — inject a keyframe globally:
418
+ \`{ "type": "patchSettings", "customCss": "@keyframes spin { to { transform: rotate(360deg); } }" }\`.
114
419
 
115
420
  ## Semantics
116
421
  - **props are fully replaced** on \`upsertElement\`: send every prop you want to keep. To change only some props,
@@ -123,8 +428,22 @@ Pages can be grouped into **folders** (the sidebar tree). A folder is \`{ ref, n
123
428
  Example — recolor one definition without resending it: \`{ "type": "patchDefinition", "ref": "btn-x",
124
429
  "desktop": { "background-color": "#111" } }\`.
125
430
  - **Atomic batches**: if any operation fails, \`plitzi_apply\` persists nothing.
126
- - **Optimistic concurrency**: pass \`expectedResourceVersions\` (URI the stateVersion you read). If the live data
127
- drifted, apply is rejected with a conflict; re-read the reported resources and retry.
431
+ - **Every resource you touch must be malformation-free pre-existing errors block the save.** When your batch edits
432
+ an element (or a definition/global/id style), the validator also checks the resource's **current stored content**
433
+ for malformations — a broken transformer action, a malformed interaction node, invalid CSS — even in parts your
434
+ edit does not touch. Such a finding is reported as a \`Pre-existing malformation in <resource>: …\` **error**, and
435
+ \`plitzi_apply\` rejects the batch until it is fixed. These are **not caused by your change** (the message says so)
436
+ — do not be confused; fix them **in the same batch** and re-apply. Because the check runs on the resulting state,
437
+ including the fix in your batch is exactly what unblocks the save. (Advisory issues — an unobserved source/action
438
+ name that may still be a valid plugin, a binding target a plugin manifest does not list — come back as
439
+ \`Pre-existing issue …\` **warnings** and do not block.)
440
+ - **Optimistic concurrency — read before you write, and prove your read is current.** Editing a resource means you
441
+ read it first, so you hold its \`stateVersion\`. **Always pass \`expectedResourceVersions\`** (URI → the stateVersion
442
+ you read) for every resource your batch changes. If another agent edited it in the meantime, the live version no
443
+ longer matches and apply is **rejected with a conflict** — nothing persists. Then re-read the reported resources
444
+ (their new content + version) and retry on top of the fresh state. This is exactly how a file editor forces a
445
+ re-read after a stale write: it is what keeps concurrent agents from silently overwriting each other's changes, so
446
+ never omit it "to save a call".
128
447
  `;
129
448
  //#endregion
130
- export { guideText, serverInstructions };
449
+ export { guideQuickstart, guideText, serverInstructions };
@@ -0,0 +1,123 @@
1
+ import { applyBuiltinCallback } from "../catalogs/builtinCallbacks.js";
2
+ import { applyElementCallback } from "../catalogs/builtinElementCallbacks.js";
3
+ import { applyUtility } from "../catalogs/builtinUtilities.js";
4
+ import { generateObjectId } from "./space.js";
5
+ //#region src/modules/mcp/helpers/interactions.ts
6
+ var BINDING_CATEGORIES = [
7
+ "attributes",
8
+ "style",
9
+ "initialState"
10
+ ];
11
+ var NULLISH_ELEMENT_IDS = /* @__PURE__ */ new Set([
12
+ "undefined",
13
+ "null",
14
+ ""
15
+ ]);
16
+ var isNonEmptyObject = (value) => value !== void 0 && Object.keys(value).length > 0;
17
+ var nodeToAI = (node) => {
18
+ const ai = {
19
+ id: node.id,
20
+ title: node.title,
21
+ nodeType: node.type,
22
+ action: node.action
23
+ };
24
+ if (isNonEmptyObject(node.params)) ai.params = node.params;
25
+ if (!node.enabled) ai.enabled = false;
26
+ if (node.when !== void 0) ai.when = node.when;
27
+ if (node.elementId && node.elementId !== node.id) ai.elementId = node.elementId;
28
+ if (isNonEmptyObject(node.preview)) ai.preview = node.preview;
29
+ return ai;
30
+ };
31
+ var orderFlow = (nodes) => {
32
+ const byId = new Map(nodes.map((n) => [n.id, n]));
33
+ const head = nodes.find((n) => !n.beforeNode || !byId.has(n.beforeNode)) ?? nodes[0];
34
+ const ordered = [];
35
+ const seen = /* @__PURE__ */ new Set();
36
+ let current = head;
37
+ while (current && !seen.has(current.id)) {
38
+ seen.add(current.id);
39
+ ordered.push(current);
40
+ current = current.afterNode ? byId.get(current.afterNode) : void 0;
41
+ }
42
+ for (const node of nodes) if (!seen.has(node.id)) ordered.push(node);
43
+ return ordered;
44
+ };
45
+ var flowsFromInteractions = (interactions) => {
46
+ if (!interactions || Object.keys(interactions).length === 0) return [];
47
+ const byFlow = /* @__PURE__ */ new Map();
48
+ for (const node of Object.values(interactions)) {
49
+ const key = node.flowId || node.id;
50
+ const list = byFlow.get(key);
51
+ if (list) list.push(node);
52
+ else byFlow.set(key, [node]);
53
+ }
54
+ const flows = [];
55
+ for (const [flowId, nodes] of byFlow) flows.push({
56
+ flowId,
57
+ nodes: orderFlow(nodes).map(nodeToAI)
58
+ });
59
+ return flows;
60
+ };
61
+ var newNodeId = () => `node_${generateObjectId()}`;
62
+ /** Materialize an ordered list of nodes into the stored linked-node map for ONE flow: assign ids where missing,
63
+ * set flowId to the trigger id, and recompute beforeNode/afterNode from the order. `ownerId` is the default
64
+ * source element for callbacks that name none. */
65
+ var materializeFlow = (nodes, ownerId) => {
66
+ const ids = nodes.map((node) => node.id || newNodeId());
67
+ const flowId = ids[0];
68
+ const record = {};
69
+ nodes.forEach((node, i) => {
70
+ let params = node.params ?? {};
71
+ const supplied = NULLISH_ELEMENT_IDS.has(node.elementId ?? "") ? void 0 : node.elementId;
72
+ let elementId = node.nodeType === "utility" ? null : supplied ?? ownerId;
73
+ if (node.nodeType === "globalCallback") {
74
+ const builtin = applyBuiltinCallback(node.action, params);
75
+ if (builtin.source) {
76
+ elementId = builtin.source;
77
+ params = builtin.params;
78
+ }
79
+ } else if (node.nodeType === "callback") params = applyElementCallback(node.action, params).params;
80
+ else if (node.nodeType === "utility") params = applyUtility(node.action, params).params;
81
+ const interaction = {
82
+ id: ids[i],
83
+ title: node.title,
84
+ type: node.nodeType,
85
+ action: node.action,
86
+ params,
87
+ preview: node.preview ?? {},
88
+ elementId,
89
+ beforeNode: i > 0 ? ids[i - 1] : "",
90
+ afterNode: i < ids.length - 1 ? ids[i + 1] : "",
91
+ flowId,
92
+ enabled: node.enabled ?? true
93
+ };
94
+ if (node.when !== void 0) interaction.when = node.when;
95
+ record[ids[i]] = interaction;
96
+ });
97
+ return {
98
+ flowId,
99
+ record
100
+ };
101
+ };
102
+ var bindingToAI = (binding) => {
103
+ const ai = {
104
+ id: binding.id,
105
+ to: binding.to,
106
+ source: binding.source
107
+ };
108
+ if (binding.transformers && binding.transformers.length > 0) ai.transformers = binding.transformers;
109
+ if (binding.when !== void 0) ai.when = binding.when;
110
+ if (binding.enabled === false) ai.enabled = false;
111
+ return ai;
112
+ };
113
+ var bindingsToAI = (bindings) => {
114
+ if (!bindings) return;
115
+ const result = {};
116
+ for (const category of BINDING_CATEGORIES) {
117
+ const list = bindings[category];
118
+ if (list && list.length > 0) result[category] = list.map(bindingToAI);
119
+ }
120
+ return Object.keys(result).length > 0 ? result : void 0;
121
+ };
122
+ //#endregion
123
+ export { BINDING_CATEGORIES, NULLISH_ELEMENT_IDS, bindingToAI, bindingsToAI, flowsFromInteractions, materializeFlow, newNodeId };
@@ -0,0 +1,54 @@
1
+ //#region src/modules/mcp/helpers/log.ts
2
+ var MCP_DEBUG = process.env.MCP_DEBUG === "1";
3
+ var summarize = (value, max = 300) => {
4
+ if (value === void 0) return;
5
+ let json;
6
+ try {
7
+ json = JSON.stringify(value);
8
+ } catch {
9
+ return "[unserializable]";
10
+ }
11
+ return json.length > max ? `${json.slice(0, max)}…` : json;
12
+ };
13
+ var errorText = (error) => error instanceof Error ? error.message : String(error);
14
+ var consoleRender = (event) => {
15
+ const kind = event.kind === "tool" ? "tools/call" : "resources/read";
16
+ const detail = event.argsSummary ? ` ${event.argsSummary}` : "";
17
+ const status = event.ok ? "ok" : `ERROR ${event.error ?? ""}`;
18
+ console.log(`[mcp] ${kind} ${event.name}${detail} ${Math.round(event.durationMs)}ms ${status}`);
19
+ };
20
+ var noop = () => void 0;
21
+ var inertLog = {
22
+ toolCall: noop,
23
+ resourceRead: noop
24
+ };
25
+ /** Build the request-log sink for one MCP server. Dispatches structured events to the consumer's `logger` when
26
+ * provided; otherwise renders to the console when MCP_DEBUG=1; otherwise a no-op. */
27
+ var createMcpLog = (logger) => {
28
+ if (!logger && !MCP_DEBUG) return inertLog;
29
+ const emit = (event) => {
30
+ if (logger) logger(event);
31
+ else consoleRender(event);
32
+ };
33
+ return {
34
+ toolCall: (name, args, ms, error) => emit({
35
+ kind: "tool",
36
+ name,
37
+ durationMs: ms,
38
+ ok: !error,
39
+ ...error ? { error: errorText(error) } : {},
40
+ ...summarize(args) !== void 0 ? { argsSummary: summarize(args) } : {},
41
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
42
+ }),
43
+ resourceRead: (uri, ms, error) => emit({
44
+ kind: "resource",
45
+ name: uri,
46
+ durationMs: ms,
47
+ ok: !error,
48
+ ...error ? { error: errorText(error) } : {},
49
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
50
+ })
51
+ };
52
+ };
53
+ //#endregion
54
+ export { createMcpLog };