diff --git a/crates/mcp/src/prompts.rs b/crates/mcp/src/prompts.rs index 59b4ee818..3e82b1865 100644 --- a/crates/mcp/src/prompts.rs +++ b/crates/mcp/src/prompts.rs @@ -187,4 +187,30 @@ mod tests { assert!(out.contains(&bomb)); assert!(out.len() < 3 * bomb.len(), "{}", out.len()); } + + /// Every command the server's instructions and the prompts name exists: an agent told to run a + /// renamed or misspelt one gets an error instead of the workflow. + #[test] + fn the_commands_the_instructions_and_prompts_name_exist() { + let ids: Vec<&str> = figcraft_engine::all_commands().iter().map(|c| c.id).collect(); + let namespaces: Vec<&str> = ids.iter().filter_map(|id| id.split('.').next()).collect(); + let texts = std::iter::once(crate::INSTRUCTIONS).chain(PROMPTS.iter().map(|p| p.template)); + let mut named = 0; + for text in texts { + for word in text.split(|c: char| !(c.is_ascii_alphanumeric() || c == '.')).map(|w| w.trim_end_matches('.')) { + let Some((ns, rest)) = word.split_once('.') else { continue }; + // wait_for_changes events, which the prompts name too. + let event = matches!(word, "comment.added" | "comment.replied"); + if event || rest.is_empty() || !rest.starts_with(|c: char| c.is_ascii_lowercase()) || !namespaces.contains(&ns) { + continue; + } + named += 1; + assert!(ids.contains(&word), "`{word}` is not a command"); + } + } + assert!(named > 10, "the check found the command ids ({named})"); + for id in ["component.create", "instance.create", "component.addProperty", "instance.setProperties", "component.combineVariants"] { + assert!(crate::INSTRUCTIONS.contains(id), "the instructions name {id}"); + } + } } diff --git a/crates/mcp/src/server.rs b/crates/mcp/src/server.rs index 70ac05999..58eb6b2e2 100644 --- a/crates/mcp/src/server.rs +++ b/crates/mcp/src/server.rs @@ -36,7 +36,16 @@ reports both x/y relative to the parent frame (groups don't count) and absoluteB positioned by the layout (set layout, gap, padding, mainAlign, crossAlign, sizingH/sizingV instead). \ Every menu item, panel action and shortcut is a command: find ids and params with list_commands (use a filter) \ and run them with run_command, or several as one undo step with batch. Commands act on `ids` when given, else \ -on the selection; new layers become the selection. Colours are \"#RRGGBB\" or \"#RRGGBBAA\". Verify your work: \ +on the selection; new layers become the selection. Colours are \"#RRGGBB\" or \"#RRGGBBAA\". \ +Repeated UI (buttons, inputs, cards, list rows, tab bars, icons) is a component: build it once, make it one with \ +component.create (or create_node type component), then place every other copy with \ +instance.create {component, parent?, x?, y?} instead of duplicating layers, so every copy follows its main component. \ +States and sizes are variants of one set: name the mains Property=value (State=Default, State=Hover) and run \ +component.combineVariants on them; component.addVariant {id} adds one more. What changes from copy to copy is a \ +component property: component.addProperty {id, name, type: text|boolean|instanceSwap, layer} on the component (on the \ +set once its variants are combined, then component.bindProperty {layer, property} for each other variant's layer), and \ +instance.setProperties {ids, properties} sets it on each copy. get_node shows whether a layer is an instance and of \ +which main. Verify your work: \ inspect_document / get_node return the layer tree as JSON (check sizes, fills, layout, overrides), and \ screenshot returns a PNG of the page or of given layers to look at. undo/redo step through history. \ Comments: comment.list returns threads (text, anchor node id, frame, page, x/y, replies); fix open ones, \ diff --git a/docs/mcp.md b/docs/mcp.md index c032b93ab..46e729fc0 100644 --- a/docs/mcp.md +++ b/docs/mcp.md @@ -182,6 +182,18 @@ Or in a project's `.mcp.json`: leaves its contents where they are, and so does resizing a frame with `cmd` held (constraints ignored); a layer a mask hides can't be clicked there, and a mask group's box and exports are the mask's (plus any layers under the mask). +- Repeated UI (buttons, inputs, cards, list rows, tab bars, icons) is a component and its copies + are instances: make it once with `component.create` (or `create_node` type `component`) and place + each other copy with `instance.create {component, parent?, x?, y?}` rather than duplicating the + layers, so every copy follows the main. States and sizes are variants of one set: name the mains + `Property=value` (`State=Default`, `State=Hover`) and run `component.combineVariants` on them; + `component.addVariant {id}` adds one more. What changes per copy is a component property: + `component.addProperty {id, name, type: text|boolean|instanceSwap, layer}` on the component, or + on the set once its variants are combined, then `component.bindProperty {layer, property}` for + each other variant's layer (a property added to one variant before combining stays that + variant's, so an instance switched to another variant loses it); `instance.setProperties {ids, + properties}` sets it on each copy. The server's `initialize` instructions say this too, since + agents otherwise tend to copy layers. - Children of an auto-layout frame are positioned by the layout: set `layout`, `gap`, `padding`, `mainAlign`, `crossAlign`, `sizingH`/`sizingV` instead of x/y. In one call, `layout` applies before the keys that tune it, so `{"layout": {"mode": "vertical"}, "gap": 8}` keeps the gap;