--- name: simulator-smart-forms description: > Simulator.Company Smart Form (CDU / Script / Application) specialist. Use when the user wants to create, edit, inspect, or deploy a Smart Form; work with its pages, locale, viewModel, styles, definitions, or widgets; understand the CDU page protocol; pull or push form files; manage releases; or ask questions about the app_content / applications / releases / file_history APIs. Activate on: "smart form", "CDU", "script application", "pullSmartForm", "pushSmartForm", "page config", "viewModel", "locale", "deploy smart form", "edit page layout", "add component to CDU", "rollback release". --- # Simulator.Company Smart Form Author You are a specialist in creating and editing **Smart Forms** (also called CDU, Script, or Application) on the Simulator.Company platform, using the `simulator` MCP server plus the `pullSmartForm` / `pushSmartForm` engine tools. --- ## Core Concepts A **Smart Form** is three things in one: | Layer | What it is | |---|---| | **Actor** | An actor in the `scripts` system form — has `id`, `ref`, `title`, `data.sharedWith` | | **Versioned project** | A folder/file tree per environment: pages, locale, viewModel, styles, definitions, widgets | | **Backend binding** | Corezoid credentials per env — dynamic data and control flow come from Corezoid at runtime | A Smart Form is **not** a data-schema form. Compare: ``` Regular Form (template) Smart Form (actor + app) ────────────────────── ─────────────────────── defines field schema is itself an actor in "scripts" form actors are instances of it carries pages/styles/i18n as versioned files account definitions Corezoid process supplies runtime data ``` --- ## Environments Every Smart Form always has exactly **two environments**: | Env | `readonly` | Purpose | |---|---|---| | `develop` | `false` | Active editing target | | `production` | `true` | Live, served to end users | **Rule:** never write directly to `production`. Edit `develop`, then deploy `develop → production` via a release. The server rejects writes to readonly envs. --- ## Project File Structure After `pullSmartForm` the local directory looks like: ``` / develop/ .manifest.json ← file IDs + SHA-256 hashes (used by pushSmartForm) pages/ index/ config ← Page layout (JSON): { grid, forms[] } locale ← Page-scoped i18n (JSON): { key: { en: "…", uk: "…" } } locale ← App-wide i18n (JSON) viewModel ← Default view-model values (JSON) widgets ← Widget/control settings (JSON, ctrlSettings) definitions/ button ← Reusable component fragment (JSON), used via "$ref": "#/button" styles/ index ← Less stylesheet (text/css); compiled → scoped CSS at serve time production/ .manifest.json … (same tree, read-only) ``` ### File roles | File | MIME | Purpose | |---|---|---| | `pages//config` | `application/json` | Page layout: grid + forms + sections + items | | `pages//locale` | `application/json` | Page-level i18n strings | | `locale` | `application/json` | App-wide i18n strings; merged with page locale at serve time | | `viewModel` | `application/json` | Default values; merged with Corezoid-supplied viewModel at serve time | | `definitions/` | `application/json` | Reusable component fragments; inlined by `$ref` at serve time | | `styles/index` | `text/css` | Less source; compiled to scoped CSS (`.cdu-page` scope); `@import "pages//style"` works | | `widgets` | `application/json` | ctrlSettings for embedded third-party widgets | --- ## Standard Workflow ### Creating a new Smart Form ``` createSmartForm(title="My App", ref="my-app") → { actorId: "...", envs: [{id: 1, title: "develop"}, {id: 2, title: "production"}] } ``` `corezoidCredentials` is optional — omit it for static/design-only forms and configure the Corezoid binding later. Then immediately pull the default skeleton: ``` pullSmartForm(actorId="") → downloads all envs to /develop/ and /production/ ``` ### Edit cycle (existing or newly created form) ``` 1. pullSmartForm(actorId="") → downloads all envs to /develop/ and /production/ → writes .manifest.json (file IDs + hashes) in each env dir 2. Edit files under /develop/ (page config, locale, viewModel, styles, definitions) 3. pushSmartForm(actorId="") → walks /develop/, diffs every file/folder against .manifest.json → validates new + changed files against the CDU page protocol schema → audits the WHOLE tree for cross-file token defects (see below) → if errors: aborts with { validationErrors: [...] } — fix and retry → POSTs new folders (parents first) and new files, then PUTs modified files → updates .manifest.json with returned ids + content hashes → returns { created: { folders, files }, updated, unchanged, orphanFiles, warnings? } 4. Deploy (when ready to publish): deploySmartForm(actorId="") → deploys develop → production; returns { releaseId, releaseNumber, status } ``` ### The cross-file token audit (`validationErrors` vs `warnings`) Per-file schema validation cannot see whether a `[[key]]` resolves or a `{{key}}` has a default — those need the locale and viewModel files alongside the page. `pushSmartForm` therefore also audits the **whole** env tree (not just the files being written: deleting a viewModel default breaks an untouched page). The split follows what the runtime can still rescue: | Finding | Where | Why | |---|---|---| | `[[key]]` in neither app `locale` nor that page's `locale`, **and** that page or one of its locale files is in this push | **`validationErrors`** — push aborts | locale resolves from files only; nothing at runtime can supply it, so it always reaches the browser as the literal text `[[key]]` | | the same miss in a page **nobody touched** in this push | `warnings` (tagged `pre-existing`) | it was already live before the push; blocking would strand an unrelated fix, since `pushSmartForm` has no force flag | | `{{key}}` with no `viewModel` default | `warnings` | the bound Corezoid process returns a per-request viewModel merged over the defaults, so it may be filled at runtime — it renders literally only when the backend call fails | | a `label`/`image` whose whole value is `{{key}}` and whose default is `""` | `warnings` | the renderer rejects an empty value outright; use a non-breaking space (label) or a **fetchable** placeholder URL (image — a `data:` URI is rejected by the image proxy) | | a `viewModel` default no page or definition references | `warnings` | dead key, usually left behind by a removed component | | a section with **literal** `contentLoop` entries missing a key its template uses | `warnings` | those rows render the literal `{{key}}` — checked per entry, and named | A **templated** `contentLoop` (`"contentLoop": "{{promos_loop}}"`) is backend-filled, so the placeholders inside its `content` template are not viewModel keys and are never reported. Only `content` is loop-scoped — the section's own fields (`title`, `visibility`, …) are ordinary viewModel placeholders. `regexp` and `mask` are skipped entirely: a character class such as `^[[:alpha:]]+$` is pattern syntax, not a `[[locale]]` token. --- ## Page Config Format (`pages//config`) The page `config` is the layout template. Structure: **Page → Grid → Form → Section → Item**. ### Minimal page ```json { "grid": { "type": "one_column", "components": { "center": ["main"] } }, "forms": [ { "id": "main", "title": "My Form", "sections": [ { "id": "body", "type": "body", "content": [ { "id": "greeting", "class": "label", "value": "[[hello]]" }, { "id": "name", "class": "edit", "value": "{{defaultName}}", "type": "text", "placeholder": "Enter your name", "required": true }, { "id": "submit", "class": "button", "title": "Submit", "type": "default" } ] } ] } ] } ``` ### Page (root of `config`) ```jsonc { "title": "My orders", // browser tab title; see below "grid": { /* layout */ }, "forms": [ /* content */ ], "language": "uk", // base locale for [[…]] and date formatting "styleClass": "orders-page", "query": { "ref": "{{ref}}" }, "notifications": [ /* shown when the page opens */ ], "extra": { "showScrollToTop": true, "focusVisible": true } } ``` `title` names the browser tab. Omit it and the tab is named by the host application — ` -