Build Mica documents with an agent
A Mica document is plain JSON, so an AI agent — Claude Code, or any model you
prompt yourself — can write one from a description. Three things in the
repository make that reliable: a command that prints what a document may
contain, a hand-written playbook on how to turn a
request into one, and a command that lists every reason import would refuse
the result. A Claude Code skill puts the three together. For an agent you
run yourself, through a model API, the repository also has a set of
authoring tools the model calls to build and edit a
document step by step. The commands run from the repository root after
npm install; none of this is part of mica/runtime.
Use the Claude Code skill
Section titled “Use the Claude Code skill”The repository ships a Claude Code skill, mica-author, in
.claude/skills/mica-author/. Start Claude Code in a
clone of the repository and describe the micro-app you want:
Build a Mica document for a packing checklist: I add items and tick them off.Save it as packing.json.Claude Code picks the skill up when a request is about writing or changing a
Mica document; you can also name it with /mica-author. The skill has Claude:
- choose the pack first, because a document cannot be converted to another pack later;
- load that pack’s vocabulary with
npm run mica:pack -- <pack id>; - read the playbook;
- write the whole document in the exported form, stating the host contract it assumed;
- run
npm run mica:check -- --json <file>and repair the document until import accepts it;
and it reads examples/documents/ and these docs pages when it needs them.
No hosted service or API key beyond your own Claude Code setup is involved.
Open the result in the designer with Import and Replace
document.
A clean check means import accepts the document, not that it does what you asked: preview it, and read the object declarations the agent proposed — they are the contract your host has to implement.
What the agent built
Section titled “What the agent built”The same request — A packing checklist where I add items and tick them off. — went to Claude Opus 5.5 through the authoring tools several times. These two builds both import and both do what was asked: two designs for one prompt. Neither needs a host: the items are a local list in document state.
The agent seeded three items, wrote the page in one call and finished in the
next, with no refusals. Mark packed moves an item from To pack to
Packed with addRow and removeRow, and Unpack moves it back, to the
end of the list. Both lists have an empty state, and Add to list shows only
once a name is typed. The example renames the agent’s “Packed” button to
Mark packed and the app from “Packing checklist” to “Packing list”, the
page’s own title.
Each row carries a Toggle bound to its own done field with $bindItem,
and a packed item’s name turns muted and italic: two Texts per row, one shown
while done is false and the other while it is true. The agent’s first page
was refused, because a Toggle’s label takes a literal value only:
write_page was refused; the draft is unchanged.- Invalid Toggle props on “item-done”: props.label uses unsupported expression “$item”; label takes a literal value only. (/ui/elements/item-done/props/label)In the next response it rewrote the page with the item’s name in a Text beside the Toggle and a literal “Packed” label.
Built by the agent shows more builds step by step, with the refusals Mica returned, the host contracts the agent proposed and what to check in them.
Give the agent the vocabulary
Section titled “Give the agent the vocabulary”npm run mica:pack # both packsnpm run mica:pack -- mica.core # one pack, by idThis prints the knowledge pack: compact text an agent keeps in its context. It is generated from the code import runs — the packs’ prop schemas, the placement rules, the events and actions, the condition grammar, the object declaration grammar, the state paths the object runtime projects, and the limits — so it changes when that code changes, and a snapshot test fails until the change is accepted on purpose.
It is written from what import accepts, not from json-render’s own catalog
prompt, which describes features Mica refuses (such as $template and
$and). Mica’s tests build documents from what the pack lists — every
component, each enumerated prop value and prop expression, every event,
condition operator, action and projected object path — and check that import
accepts each one. The prose that joins those facts, and the one-line
descriptions of each action’s params, are not tested that way.
The pack lists values, not intent: it tells an agent that Choice takes
display: "checkboxes", but not when a form should use one. That is the
playbook’s job: how to translate a request, which
decisions belong to the host, what to do when Mica cannot express something
directly, recipes and style. Prop descriptions and visual notes are on
components and props.
Check what the agent wrote
Section titled “Check what the agent wrote”npm run mica:check -- path/to/document.jsonnpm run mica:check -- --json path/to/document.jsonThe file must be a document in the exported form import
accepts. The command runs the same all-issues validator as listDocumentIssues
and prints every issue with its kind, the element it is about and a JSON
Pointer to where it sits, so the agent can fix them all in one pass:
draft.json: 2 issues1. [props · element “title” · /ui/elements/title/props/level] Invalid Heading props on “title”: Invalid option: expected one of "1"|"2"|"3".2. [interactions · element “next” · /ui/elements/next/on/press/0] Element “next” (on.press[0]): goToPage targets unknown page “results”.It exits with 0 when import accepts the document, 1 when it has issues,
and 2 when it could not check at all — a missing or unreadable file, or a
wrong argument. A file that is not JSON is an issue like any other
(Invalid JSON: …). Put -- before the arguments so npm passes --json
through.
--json prints one object for an agent to read:
{ "file": "draft.json", "ok": false, "issues": [ { "message": "Invalid Heading props on “title”: Invalid option: expected one of \"1\"|\"2\"|\"3\".", "kind": "props", "elementKey": "title", "path": "/ui/elements/title/props/level" }, { "message": "Element “next” (on.press[0]): goToPage targets unknown page “results”.", "kind": "interactions", "elementKey": "next", "path": "/ui/elements/next/on/press/0" } ], "hints": []}A clean document adds "pack": {"id", "version"}; a file that could not be
read carries "error" in place of "issues" and "hints".
After the issues, the check lists hints: recipes from the
playbook that the document skips. Import does not
need them, so a hint never changes the exit code. Today there is one: a
create sends a value a control binds, and nothing in the document shows
the host’s field error for that input
(/meta/objects/{alias}/operations/create/error/fieldErrors/{input}), so
when the host refuses it the person cannot tell which answer to fix. Each
such input gets its own hint, named with the control that binds it — a form
that shows errors for some of its inputs is still hinted for the rest:
signup.json: no issues; import accepts it (mica.core 1.0.0).1 hint (playbook recipes the document skips; import does not need them):1. [element “email”] Create “signup” sends input “email” from control “email”, but nothing shows the host's field error for it. Give that control "error": { "$state": "/meta/objects/signup/operations/create/error/fieldErrors/email" }; on a wizard, give the Value that shows it on the review step the same error.A field error shown anywhere in the document counts: the control’s own
error, a Value’s error, or a Text elsewhere. On a form that spans pages, the playbook’s
wizard pages recipe shows it in the
control’s error on its own step and again in the error of the answer’s Value on the review page,
where the person is when the host answers. In --json output each
hint is {message, elementKey, object, input}. Hints are listed while
issues remain, too.
Authoring tools
Section titled “Authoring tools”src/ai/tools.ts is a tool layer for an agent loop you run yourself, and the
one the designer’s AI mode runs on. Instead of writing a whole
document, the model calls tools: write_page writes a page as a tree of
elements, fine-grained tools change one thing at a time, inspect_element
looks one key up, declare_object, declare_host_action, set_state and set_startup write the
host contract and the starting state, and finish ends the turn. AUTHORING_TOOLS holds each tool’s name,
description and JSON Schema input, ready to hand to a model; an
AuthoringSession runs the calls. It is plain TypeScript with no DOM, so it
runs in Node.
import { AuthoringSession, AUTHORING_TOOLS, emptyDraft, toolResultText } from "./src/ai/tools";import { corePack } from "./src/packs";
// A first build starts from an empty draft; a follow-up from the current document.const session = new AuthoringSession(emptyDraft(corePack, "Gym induction"));
// For each tool call the model makes (AUTHORING_TOOLS tells it what exists):const result = session.run(call.name, call.input);reply(toolResultText(result)); // what the model reads back
// When the model calls finish and it passes, result.document is the new// document and result.hostContract describes what the host must provide.The tools work on a draft, and only the finished draft has to pass import:
- A call is refused only for what is wrong in itself: a component the pack does not have, a missing, malformed or duplicate key, a placement the designer could never build, props import refuses, a malformed action, condition, repeat or startup list, a declaration import refuses. The answer lists every reason, the draft stays exactly as it was, and the model fixes that one call.
- What a value names elsewhere is checked on the whole draft. A button
may go to a page not written yet, a submit may
createan object declared later, and a row’s Text may read$itembefore its Stack repeats. Every answer lists what still stands in the way of import — the same issuesnpm run mica:checkprints — so the model sees them at once without being stopped by them. This is what lets a declaration and the binding that uses it change in either order: adding a required input to acreatedeclaration and to the button that sends it is two calls, and neither order is refused. finishruns import’s check. A draft import refuses is never handed back as a document; the model gets the issues and keeps going.- Hints never stop anything. Every call that changes the draft, and
check, also lists the draft’s hints after its issues — the same onesnpm run mica:checkprints. A call is never refused for one, andfinishpasses with hints outstanding.
write_page takes sparse props: an element gives only the props that
differ from the palette’s values, as the knowledge pack
lists them, and the rest are filled in. Keys an element omits are generated,
and the answer lists every key so later calls can name them.
replace_document writes a whole document in one call, as a model working
without tools would; a session can mix it with the other tools.
Host contract summary
Section titled “Host contract summary”check and a passing finish also return the host contract the draft
declares, generated from its objects and lifecycle.startup and nothing
else, so it always matches the document:
employee = hr.employee (one record) fetch() -> {id, name: string, team: string}claims = expenses.claim (a list of records) fetch() -> [{id, merchant: string, amount: number, status: pending|approved|rejected|withdrawn}] update(id, status: withdrawn, reason: string (minLength 3)) -> {id, merchant: string, amount: number, status: pending|approved|rejected|withdrawn}At startup: fetch employee, fetch claimsAn input or field marked ? is optional; update and delete receive the
record’s identity first. Constraints and conditional requirements appear on
inputs only, because only inputs are checked against them (see field
rules). The function is hostContract in
src/ai/hostContract.ts.
Tool reference
Section titled “Tool reference”Generated from AUTHORING_TOOLS, the definitions the model is given, so it
always matches them. Each element is one node of a page tree, with its
children nested.
# Mica authoring toolsA field without "?" is required.
write_page — Write a whole page as a tree of elements: the first build of a page, or a rewrite of one. A new key adds a page to the root PageStack (at index, else last); an existing page's key replaces that page's props and content in place, and its old elements are removed. Give each element only the props that differ from the palette's; on, visible and repeat go on the element they belong to. The result lists every element's key, generated ones included. key?: text — The page's key (lowercase letters, digits and dashes, starting with a letter, at most 64 characters); pages read best as page-<name>. Omit it for a generated key. props?: object — Page props that differ from the palette's, such as title and background. children?: list of element — The page's content, top to bottom. index?: number — Where among the parent's children, counting from 0; the end when omitted.
add_element — Add one element, with any children nested in it, to an existing page or container. Give only the props that differ from the palette's. parent: text — The key of the page or container to add to. index?: number — Where among the parent's children, counting from 0; the end when omitted. element: element
update_props — Change some props of an element; the others keep their values. reset puts named props back to the palette's value, or removes them when the palette gives none. key: text — The element's key. props?: object — The props to set. reset?: list of text — Names of props to put back to the palette's value.
set_events — Set the actions an element runs on one of its events, replacing the ones it had. An empty list removes the event. key: text — The element's key. event: text — The event, such as press on a Button or commit on an Input, NumberField, Choice or Toggle. actions: list of any JSON — The bindings, in order: [{"action": <action>, "params": {…}}, …].
set_visible — Show an element only while a condition or a boolean $expr holds, or always (condition null). key: text — The element's key. condition: any JSON — A condition, a list of conditions that must all hold, {"$or": [group, …]} when any group may hold, a boolean $expr, or null to always show it.
set_repeat — Make a Stack or Grid render its children once per row of a list (repeat null stops it). Inside, $item reads the row's fields. key: text — The Stack's or Grid's key. repeat: any JSON — {statePath, key}: the list's state path and the row field that tells rows apart; or null.
move_element — Move an element, with its children, into a page or container, or to another place in the same one. key: text — The element's key. parent: text — The key of the page or container to move it into. index?: number — Where among the parent's children, counting from 0; the end when omitted.
remove_element — Remove an element and everything inside it, or a page and its content (the last page stays). goToPage actions targeting a removed page are removed too, and so is its key in any Steps' pages. key: text — The element's or page's key.
declare_object — Declare a business object the host provides, replacing any declaration with that alias, or remove one (declaration null). The declarations are the host contract: type, cardinality, identity, the fields the document reads, the capabilities with their typed inputs, and a design sample. Bindings that use the object can come before or after it. alias: text — The name the document uses for the object, such as attempt or claims. declaration: any JSON — {type, cardinality, identity, fields, capabilities?, sample?}, or null to remove the declaration.
declare_host_action — Declare a named action the host lists, replacing any declaration with that name, or remove one (declaration null). The name is the contract: never a script, never compiled into an object create, never a JavaScript prototype name such as toString. Params use the same field-spec grammar as object inputs except requiredWhen. Bindings that use the action can come after it. name: text — The host verb, such as createLead. declaration: any JSON — {params: {<name>: field spec}}, or {} params for none, or null to remove the declaration.
set_state — Seed the document's starting state at a path, or remove what is seeded there. Seed every path the document reads or binds; never a declared object's /objects or /meta/objects paths. path: text — A JSON Pointer such as /quiz or /quiz/q1. A list is set whole, never one row at a time. value?: any JSON — Any JSON value to seed. remove?: true · false — true removes the path instead.
set_startup — Set the actions that run once when the app starts, replacing any; fetch only. An empty list removes them. actions: list of any JSON — [{"action": "fetch", "params": {"object": <alias>}}, …], in order.
replace_document — Replace the whole draft with a complete document in the exported form (envelopeVersion, ui, meta, objects, hostActions, lifecycle), in the draft's pack. Refused, with every reason, when any part of it is wrong in itself. document: any JSON — The whole document, as a JSON object.
inspect_element — Look up one element of the draft: its type, JSON (props, on, visible, repeat, children keys), the documentReferences sites that belong to it or name it, and the import issues on that key. Does not change the draft. Use this instead of check when a follow-up is about one element. key: text — The element's key.
check — List every reason the draft does not import yet, the hints (playbook recipes it skips, which never block finish), and the host contract it declares. (no input)
finish — End the turn: run import's check on the draft. When it passes, the draft is applied as the new document; otherwise fix the issues it lists and call finish again. (no input)
element (in write_page, add_element) type: text — A component of the document's pack, such as Stack, Heading or Button. key?: text — The element's key: lowercase letters, digits and dashes, starting with a letter, at most 64 characters, unique in the document. Give one to every element an action, a condition or a later edit names; the others get generated keys. props?: object — Only the props that differ from the palette's values; every other prop takes its palette value. on?: object — Events: {"<event>": [{"action": <action>, "params": {…}}, …]}; the actions run in order. visible?: any JSON — A condition, a list of conditions that must all hold, {"$or": [group, …]} when any group may hold, or a boolean $expr. repeat?: any JSON — Stack and Grid only: {statePath, key} renders the children once per row of the list at statePath. children?: list of element — The element's children, in order.The knowledge pack
Section titled “The knowledge pack”This build's pack is 24,426 characters for both packs (Signal alone 21,240, Nocturne alone 16,151).
# Mica document vocabularyGenerated from Mica's code. It describes what document import accepts; anything else is refused.
## DocumentA document is one JSON object. Top level: envelopeVersion, ui, meta, objects, hostActions, lifecycle; ui: root, elements, state; meta: pack {id, version}.Designer extras (graph layout, mock fixtures) live in a {stem}.mica-design.json sidecar, never in the envelope; import refuses fixtures and graph on a document. Sidecar graph.objects/pages/hostActions/state hold map x/y; fixtures.objects and fixtures.hostActions are separate maps so an alias and a host action may share a name.The smallest Signal document: {"envelopeVersion":1,"ui":{"root":"app","elements":{"app":{"type":"PageStack","props":{"name":"Untitled micro-app"},"children":["home"]},"home":{"type":"Page","props":{"title":"New page","background":"paper"},"children":[]}}},"meta":{"pack":{"id":"mica.core","version":"1.0.0"}}}elements maps each element key to {type, props, children, on, visible, repeat}; children lists element keys, and every element sits under the root exactly once.The root is a PageStack. A prop without "?" is required. Values separated by " · " are the alternatives a prop accepts; "= …" is the palette's value.
## Pack Signal (meta.pack {"id": "mica.core", "version": "1.0.0"})Crisp operational surfaces, citrus accents, and practical controls.PageStack — Structural container for pages in a micro-app (holds Page) name: text (not empty) = "Untitled micro-app"Page — A routable page inside a PageStack (holds any component but PageStack, Page) title: text (not empty) = "New page" background: "paper" · "mist" · "ink" = "paper"Stack — Flex layout flowing vertically or horizontally (holds any component but PageStack, Page; repeat) direction: "vertical" · "horizontal" = "vertical" gap: "none" · "xs" · "sm" · "md" · "lg" · "xl" = "md" align: "stretch" · "start" · "center" · "end" = "stretch" justify: "start" · "center" · "end" · "between" = "start" wrap: true · false = false padding: "none" · "sm" · "md" · "lg" · "xl" = "md" surface: "none" · "paper" · "soft" · "ink" · "citrus" · null = nullGrid — Responsive multi-column grid (holds any component but PageStack, Page; repeat) columns: whole number 1–4 = 2 gap: "none" · "xs" · "sm" · "md" · "lg" · "xl" = "md" padding: "none" · "sm" · "md" · "lg" · "xl" = "none" minCellWidth: whole number 120–420 · null = 180Spacer — Purposeful empty space (no children) size: whole number 4–160 = 32 axis: "vertical" · "horizontal" = "vertical"Section — Framed content section (holds any component but PageStack, Page) eyebrow: text · null = null title: text · null = "Section title" tone: "plain" · "outlined" · "raised" · "ink" = "outlined" padding: "none" · "sm" · "md" · "lg" · "xl" = "lg"Heading — Display or section heading (no children) content: text (not empty) · {"$state": "/state/path"} · {"$item": "row/field"} · {"$index": true} · {"$format": "number" | "currency" | "percent" | "date" | "count", "value": <read>, …options} · {"$calc": "sum" | "product" | "difference" | "quotient" | "round" | "min" | "max" | "daysBetween", "args": [<operand>, …]} · {"$expr": "sum" | "product" | "difference" | "quotient" | "round" | "min" | "max" | "daysBetween" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "and" | "or" | "not" | "isEmpty" | "if", "args": [<operand>, …]} = "A clear heading" level: "1" · "2" · "3" = "2" align: "left" · "center" · "right" = "left" accent: true · false = falseText — Body or supporting text (no children) content: text · {"$state": "/state/path"} · {"$item": "row/field"} · {"$index": true} · {"$format": "number" | "currency" | "percent" | "date" | "count", "value": <read>, …options} · {"$calc": "sum" | "product" | "difference" | "quotient" | "round" | "min" | "max" | "daysBetween", "args": [<operand>, …]} · {"$expr": "sum" | "product" | "difference" | "quotient" | "round" | "min" | "max" | "daysBetween" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "and" | "or" | "not" | "isEmpty" | "if", "args": [<operand>, …]} · {"$label": "choice-key"} = "Add your copy here." size: "sm" · "md" · "lg" = "md" tone: "default" · "muted" · "accent" · "inverse" = "default" align: "left" · "center" · "right" = "left" italic: true · false = falseButton — Primary user action (no children; events: press) label: text (not empty) = "Continue" variant: "solid" · "outline" · "ghost" · "danger" = "solid" size: "sm" · "md" · "lg" = "md" disabled: true · false · {"$cond": <condition>, "$then": true, "$else": false} = false fullWidth: true · false = false busy?: true · false · {"$cond": <condition>, "$then": true, "$else": false} busyLabel?: text (not empty)Avatar — Person or team identity (no children) name: text (not empty) = "Avery Stone" imageUrl: URL · null = null size: "sm" · "md" · "lg" = "md" status: "online" · "away" · "busy" · null = "online"DropdownMenu — Compact menu of secondary actions (no children) label: text (not empty) = "Actions" items: text (not empty) = "Open, Duplicate, Archive" align: "left" · "right" = "right" compact: true · false = falseInput — Labeled text entry field, one line or a text area (no children; events: commit) label: text (not empty) = "Email address" placeholder: text = "name@example.com" inputType: "text" · "email" · "search" · "number" = "email" lines?: whole number 1–8 · null required: true · false · {"$cond": <condition>, "$then": true, "$else": false} = false helpText: text · null = null maxLength?: whole number 1–10000 · null value?: text · {"$bindState": "/state/path"} · {"$bindItem": "row/field"} writable?: true · false · {"$state": "/state/path"} error?: {"$state": "/state/path"} rules?: { required?: true, enum?: [text or number, …], pattern?, minLength?, maxLength? }NumberField — Number entry with a stepper, bounds and a number, currency, percent or unit format; stores the raw number (no children; events: commit) label: text (not empty) = "Amount" format?: "number" · "currency" · "percent" · "unit" = "currency" currency?: ISO 4217 code, like "EUR" = "EUR" unit?: Intl unit, like "kilogram" or "kilometer-per-hour" min?: number · null = 0 max?: number · null step?: number above 0 · null required: true · false · {"$cond": <condition>, "$then": true, "$else": false} = false helpText: text · null = null value?: number · {"$bindState": "/state/path"} · {"$bindItem": "row/field"} writable?: true · false · {"$state": "/state/path"} error?: {"$state": "/state/path"} rules?: { required?: true, enum?: [number, …], minimum?, maximum? }Choice — Choice from a fixed list of options (no children; events: commit) label: text (not empty) = "Priority" display: "radio" · "select" · "checkboxes" · "segmented" · "combobox" = "radio" options: list of { value, label, note? } = [{"value":"low","label":"Low"},{"value":"normal","label":"Normal"},{"value":"high","label":"High"}] required: true · false · {"$cond": <condition>, "$then": true, "$else": false} = false helpText: text · null = null value?: text · number · list of (text · number) · {"$bindState": "/state/path"} · {"$bindItem": "row/field"} writable?: true · false · {"$state": "/state/path"} error?: {"$state": "/state/path"} rules?: { required?: true, enum?: [text or number, …], pattern?, minLength?, maxLength? }Toggle — On/off value shown as a switch, a checkbox or a toggle button (no children; events: commit) label: text (not empty) = "Email me updates" display?: "switch" · "checkbox" · "button" onLabel?: text (not empty) offLabel?: text (not empty) required: true · false · {"$cond": <condition>, "$then": true, "$else": false} = false helpText: text · null = null value?: true · false · {"$bindState": "/state/path"} · {"$bindItem": "row/field"} writable?: true · false · {"$state": "/state/path"} error?: {"$state": "/state/path"}DateField — Calendar date stored as YYYY-MM-DD, typed or picked from a calendar (no children; events: commit) label: text (not empty) = "Date" display?: "field" · "picker" min?: date "YYYY-MM-DD" max?: date "YYYY-MM-DD" required: true · false · {"$cond": <condition>, "$then": true, "$else": false} = false helpText: text · null = null value?: date "YYYY-MM-DD" · "" · {"$bindState": "/state/path"} · {"$bindItem": "row/field"} writable?: true · false · {"$state": "/state/path"} error?: {"$state": "/state/path"} rules?: { required?: true, enum?: [text or number, …], pattern?, minLength?, maxLength? }DateRange — Start and end dates, each stored as YYYY-MM-DD, typed or picked from a calendar (no children; events: commit) label: text (not empty) = "Dates" min?: date "YYYY-MM-DD" max?: date "YYYY-MM-DD" required: true · false · {"$cond": <condition>, "$then": true, "$else": false} = false helpText: text · null = null start?: date "YYYY-MM-DD" · "" · {"$bindState": "/state/path"} · {"$bindItem": "row/field"} end?: date "YYYY-MM-DD" · "" · {"$bindState": "/state/path"} · {"$bindItem": "row/field"} writable?: true · false · {"$state": "/state/path"} error?: {"$state": "/state/path"}Slider — Number picked by dragging along a range, such as a rating (no children; events: commit) label: text (not empty) = "Rating" min: number = 0 max: number = 10 step?: number = 1 format?: "number" · "currency" · "percent" · "unit" currency?: ISO 4217 code, like "EUR" unit?: Intl unit, like "kilogram" or "kilometer-per-hour" required: true · false · {"$cond": <condition>, "$then": true, "$else": false} = false helpText: text · null = null value?: number · {"$bindState": "/state/path"} · {"$bindItem": "row/field"} writable?: true · false · {"$state": "/state/path"} error?: {"$state": "/state/path"} rules?: { required?: true, enum?: [number, …], minimum?, maximum? }Image — Responsive image with alt text and an optional caption (no children) src: URL alt: text (not empty) = "Placeholder artwork with a layered horizon" fit: "cover" · "contain" = "cover" ratio: "1:1" · "4:3" · "3:2" · "16:9" · null = "16:9" caption: text · null = nullValue — Labelled read-only value, such as an answer on a review page (no children) label: text (not empty) = "Label" value: text · {"$state": "/state/path"} · {"$item": "row/field"} · {"$index": true} · {"$format": "number" | "currency" | "percent" | "date" | "count", "value": <read>, …options} · {"$calc": "sum" | "product" | "difference" | "quotient" | "round" | "min" | "max" | "daysBetween", "args": [<operand>, …]} · {"$expr": "sum" | "product" | "difference" | "quotient" | "round" | "min" | "max" | "daysBetween" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "and" | "or" | "not" | "isEmpty" | "if", "args": [<operand>, …]} · {"$label": "choice-key"} = "Value" empty?: text (not empty) error?: {"$state": "/state/path"}Steps — Step counter such as “Step 2 of 3”, read from the current page (no children) format: text (not empty) = "Step {n} of {total}" pages?: list of text (not empty)
## Pack Nocturne (meta.pack {"id": "mica.nocturne", "version": "1.0.0"})Cinematic editorial pages with serif scale, sharp rules, and ember accents.Heading — Editorial display heading (no children) content: text (not empty) · {"$state": "/state/path"} · {"$item": "row/field"} · {"$index": true} · {"$format": "number" | "currency" | "percent" | "date" | "count", "value": <read>, …options} · {"$calc": "sum" | "product" | "difference" | "quotient" | "round" | "min" | "max" | "daysBetween", "args": [<operand>, …]} · {"$expr": "sum" | "product" | "difference" | "quotient" | "round" | "min" | "max" | "daysBetween" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "and" | "or" | "not" | "isEmpty" | "if", "args": [<operand>, …]} = "Stories after dark" level: "1" · "2" · "3" = "2" align: "left" · "center" · "right" = "left" accent: "none" · "last" · "underline" = "underline"Text — Editorial copy and captions (no children) content: text · {"$state": "/state/path"} · {"$item": "row/field"} · {"$index": true} · {"$format": "number" | "currency" | "percent" | "date" | "count", "value": <read>, …options} · {"$calc": "sum" | "product" | "difference" | "quotient" | "round" | "min" | "max" | "daysBetween", "args": [<operand>, …]} · {"$expr": "sum" | "product" | "difference" | "quotient" | "round" | "min" | "max" | "daysBetween" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "and" | "or" | "not" | "isEmpty" | "if", "args": [<operand>, …]} = "Write with a point of view." size: "sm" · "md" · "lg" = "md" tone: "default" · "muted" · "accent" · "inverse" = "default" align: "left" · "center" · "right" = "left" italic: true · false = falseButton — Editorial call to action (no children; events: press) label: text (not empty) = "Read the edition" variant: "solid" · "outline" · "text" = "solid" size: "sm" · "md" · "lg" = "md" disabled: true · false · {"$cond": <condition>, "$then": true, "$else": false} = false fullWidth: true · false = false busy?: true · false · {"$cond": <condition>, "$then": true, "$else": false} busyLabel?: text (not empty)Value — Labelled read-only value, such as an answer on a review page (no children) label: text (not empty) = "Label" value: text · {"$state": "/state/path"} · {"$item": "row/field"} · {"$index": true} · {"$format": "number" | "currency" | "percent" | "date" | "count", "value": <read>, …options} · {"$calc": "sum" | "product" | "difference" | "quotient" | "round" | "min" | "max" | "daysBetween", "args": [<operand>, …]} · {"$expr": "sum" | "product" | "difference" | "quotient" | "round" | "min" | "max" | "daysBetween" | "eq" | "neq" | "gt" | "gte" | "lt" | "lte" | "and" | "or" | "not" | "isEmpty" | "if", "args": [<operand>, …]} = "Value" empty?: text (not empty) error?: {"$state": "/state/path"}Quote — Pull quote with attribution (no children) content: text (not empty) = "Clarity is a kind of courage." attribution: text (not empty) = "Avery Stone" role: text · null = "Editor"Divider — Editorial rule between ideas (no children) label: text · null = null weight: "hairline" · "bold" = "hairline"PageStack, Page, Stack, Grid, Spacer, Image, Steps: exactly as in Signal.
## State, lists and conditionsui.state holds the document's starting state. State paths are JSON Pointers into it; paths under /mica are the host's.A prop takes an expression only where its values list one. $item, $index, $bindItem are only available inside the template of a repeated Stack or Grid.$label names a Choice element whose value is bound with $bindState and shows the label of its chosen option (checkboxes: the chosen labels, comma-separated), or nothing while none is chosen; it is for display only, never in conditions or action params.The designer's Inspector can copy a declared enum onto a Choice's options; when writing JSON, list the enum values as options yourself. Import does not compare Choice options to a field's enum.A form control's rules need a $bindState value and an error $state path validate may write (not a declared object path, not overlapping any $bindState). The host is not asked. validate checks only the ruled controls visible on the active page; other pages and hidden controls keep their error slots, and with none visible it succeeds. Import still refuses validate when no control in the document carries valid rules.$format shows one value as display text in the host's locale. value: a $state read, inside a template an $item read, a $calc, or a number $expr; never a literal. number, currency (needs currency), percent, date, count (needs one, other); currency is an ISO code like "EUR", percent reads a fraction (0.25 is 25%), date reads "YYYY-MM-DD", count reads a number or a list and words it with one at exactly 1, other otherwise, in every locale. Display only: never in action params or conditions.$calc calculates a number for display: {"$calc": <function>, "args": [<operand>, …]}. An operand is a number, a $state read, inside a template an $item read, or another $calc, nested at most 3 deep counting the outermost. sum (2 to 16 operands), product (2 to 16 operands), difference (2 operands), quotient (2 operands), round (1 operand), min (2 to 16 operands), max (2 to 16 operands), daysBetween (2 operands); difference is the first minus the second, quotient the first over the second, round takes "places" (0 to 6, default 0), daysBetween counts the days from the first "YYYY-MM-DD" date read to the second. sum, min, max may instead take one field of every row of a list: {"$calc": "sum", "list": {"$state": "/basket"}, "field": "price"}. A missing or non-numeric input or a division by zero shows nothing. Wrap it in $format to show it as currency: {"$format": "currency", "value": {"$calc": …}, "currency": "EUR"}. Display only: never in action params or conditions; the host recomputes anything that counts. $calc stays legal forever; prefer $expr for new formulas.$expr is a typed formula: {"$expr": <function>, "args": [<operand>, …]}. An operand is a number, true/false, text, a $state read, inside a template an $item read, or another $expr, nested at most 6 deep counting the outermost, at most 32 nodes. sum (2 to 16 operands), product (2 to 16 operands), difference (2 operands), quotient (2 operands), round (1 operand), min (2 to 16 operands), max (2 to 16 operands), daysBetween (2 operands), eq (2 operands), neq (2 operands), gt (2 operands), gte (2 operands), lt (2 operands), lte (2 operands), and (2 to 16 operands), or (2 to 16 operands), not (1 operand), isEmpty (1 operand), if (3 operands). Arithmetic (sum, product, difference, quotient, round, min, max, daysBetween) gives a number; eq, neq, gt, gte, lt, lte give boolean; and, or, not take boolean operands (reads are allowed — a read counts as true only when it holds true, unlike a $state condition part; test text or lists with isEmpty, numbers with gt or eq); isEmpty is true for missing, "" or []; if takes a boolean condition, then a then and an else of the same type. sum, min, max may instead take list and field as $calc does. A number $expr may sit where $calc does, including as $format.value; a boolean $expr may be the whole visible, $cond (required, disabled, busy) or requiredWhen. Never in setState, object inputs or host-action params; the host recomputes anything that counts. now, random, concat, templates and host-declared functions are not available. Bad input shows nothing or false, never throws.repeat on Stack, Grid: {statePath, key} — renders the children once per row of the list at statePath; key names the row field that tells rows apart.visible: one condition part, a list of parts that must all hold, or a boolean $expr. A part reads one of $state, $item, may carry one operator and "not": true. eq, neq: text · number · true · false · null · {"$state": "/state/path"} gt, gte, lt, lte: number · {"$state": "/state/path"}Any of: {"$or": [group, …]} holds when one group does; each group is a part or a list of parts that must all hold, at most 8 groups, one level only (no $or inside a group or a list).The same condition grammar serves $cond props and object inputs' requiredWhen, which reads $state only. A boolean $expr may be the whole condition in each of those slots, not mixed with $state parts.
## Events and actionson: {"<event>": [{"action": <name>, "params": {…}}, …]} with at most 8 actions per event; they run in order.setState — statePath: a literal state path; value: text, a number, true/false, a single $state reference, or a record of themgoToPage — page: the key of a Page in the root PageStackvalidate — none — checks ruled controls visible on the active pagefetch — object: the alias of an object the document declares; inputs: optional; { <declared input>: a literal of the input's kind, a single $state reference, or a row field ($item) }; row: a collection's update and delete only; { <identity field>: the row's identity, a $state reference or a row field ($item) }create, update — the params of fetch, plus confirmation: optional; one line of plain text, at most 240 characters, that Mica asks the person to confirm before the write runsdelete — the params of fetch, plus confirmation: required; one line of plain text, at most 240 characters, that Mica asks the person to confirmaddRow — statePath: a literal state path; value: a record of the new row's fields, like { "title": { "$state": "/draft/title" } }removeRow — statePath: a literal state path; row: { <the list's key field>: text, a number, a single $state reference or a row field ($item) }lifecycle: {startup: [bindings]} runs once when the app starts; startup carries fetch only.
## Host actionshostActions: {"<name>": {params}} declares named verbs the host lists. Never scripts. Prefer an object verb when the thing is a record; use a host action when the host owns a verb that is not fetch, create, update, delete of a declared type.Names match ^[A-Za-z][A-Za-z0-9_]{0,63}$ and may not be setState, goToPage, validate, fetch, create, update, delete, addRow, removeRow, pushState, removeState, validateForm, push, pop or a JavaScript prototype name (toString, valueOf, hasOwnProperty, isPrototypeOf, propertyIsEnumerable, toLocaleString). params uses the same field-spec grammar as object inputs except requiredWhen: a literal of the declared kind, a $state read, or a whole-param $item.A declared host action may bind on an element event; it cannot run at startup. Import refuses an undeclared name as Unknown action. The host implements the handler; designer preview runs it against sidecar fixtures (succeed, cancelled or failed) or succeeds when no sidecar is present.
## Host objectsobjects: {"<alias>": {type, cardinality, identity, fields, capabilities, sample}} declares the business objects the host provides.alias, field and input names match ^[A-Za-z][A-Za-z0-9_]{0,63}$; type is a host type key matching ^[A-Za-z][A-Za-z0-9_]*(\.[A-Za-z][A-Za-z0-9_]*)*$.cardinality: "one" · "many". identity: a required, non-null top-level field of kind string, integer, number.capabilities: {<fetch, create, update, delete>: {inputs: {<name>: field spec}}}; inputs never name the identity; object actions need the capability declared.field spec: {kind, required, nullable, enum, format, pattern, minLength, maxLength, minimum, maximum, fields}; kind: "string" · "number" · "integer" · "boolean" · "object"; format: "date" · "date-time" · "email" · "uri".By kind: enum only on string, number, integer; format, pattern, minLength, maxLength only on string; minimum, maximum only on number, integer; fields only on object; kind "object" requires fields with at least one field.An operation input's field spec may also carry requiredWhen (a condition), never next to required: true; declared fields never carry it.pattern, minLength, maxLength, minimum, maximum and requiredWhen are checked on operation inputs, never on host records or samples.The runtime projects each declared object into state; documents read these paths with $state and visible and never write them: /objects/{alias}/data /objects/{alias}/data/{field} (cardinality one only) /meta/objects/{alias}/count (cardinality many only): number /meta/objects/{alias}/operations/{operation}/phase: "idle" · "loading" · "success" · "error" /meta/objects/{alias}/operations/{operation}/error: null or {category, code, message, retryable, fieldErrors}; category: "validation" · "permission" · "not-found" · "conflict" · "unavailable" · "cancelled" · "unknown" /meta/objects/{alias}/operations/{operation}/error/fieldErrors/{input}: text /meta/objects/{alias}/capabilities/{operation}/{implemented|allowed|reason} /meta/objects/{alias}/fields/{field}/{writable|reason} (cardinality one only)Under data a nested field is one path segment per level (/data/contact/email); under fields it is the declared leaf dot-joined (/fields/contact.email/writable).
## LimitsMAX_BINDINGS_PER_EVENT 8 · MAX_CHOICE_NOTE_LENGTH 500 · MAX_CHOICE_OPTIONS 64 · MAX_CONDITION_GROUPS 8 · MAX_CONFIRMATION_LENGTH 240 · MAX_FIELD_PATTERN_LENGTH 256 · MAX_HOST_ACTIONS 32 · MAX_LIST_ROWS 500 · MAX_OBJECT_DECLARATIONS 32 · MAX_OBJECT_ENUM_VALUES 64 · MAX_OBJECT_FIELDS 64 · MAX_OBJECT_FIELD_DEPTH 6 · MAX_RECORD_DEPTH 4 · MAX_RECORD_KEYS 32 · MAX_RECORD_LEAVES 64 · MAX_STATE_DEPTH 12 · MAX_STATE_PATH_LENGTH 512