edit
Run JavaScript against the live CreativeEngine to change a design, then commit the result as a new revision. Requires a parent revision ID.
Instructions
Edit the CE.SDK canvas by running JavaScript against the live CreativeEngine, then commit the result as a new revision.
⚠ Call skill({ name: 'handbook' }) BEFORE your first edit. It documents the design loop, the typeface schema, and the engine recipes; on cryptic errors, query its quirks.md.
REQUIRED: parent is a revision id (returned by a previous edit), or the JSON null literal (no quotes) to start a new design. Omitting it is an error — there is no implicit 'continue from wherever'. In a fresh conversation, a request for a new design means parent: null — never resume a workspace design the user didn't reference.
Returns: the first content part is JSON { revision, parent, names? } — store revision so you can pass it as parent on the next edit. names lists every named block in the committed scene: those are exactly the strings engine.design.findByName(name) resolves in your NEXT edit, so name what you build and re-find it instead of matching copy. When the edit changed the scene, the result also ends with a downscaled render of the (first) changed page — verify your work from it instead of spending a preview call. preview remains required for full-size judging (the judge loop) and multi-page review; set render: false to skip the image on read-only/diagnostic edits.
code return contract (STRICT): return undefined (no message back), { type: "text", text }, { type: "image", data: "<base64>", mimeType }, or an array of those. Anything else (raw strings, Blobs, plain objects) is rejected.
DIALECT (enforced): mutations go through engine.design (create/build/setProps/…). Code that mutates via engine.block.* is rejected before execution with the equivalent calls; // engine.block: <reason> opts out for calls the facade lacks.
code scope: engine (with engine.design), plus findText(copy) / findAllText(copy) for reaching a block by its text. Use them instead of comparing text strings with === — the copy on the page routinely carries a trailing space or an NBSP (before a €/%), which is what makes hand-rolled lookups throw. Matching folds those space variants and trims; a miss lists the copy actually on the page.
Dirty-on-throw: if your code throws, the engine slot is marked dirty and the next edit pays one engine reload (regardless of parent). Do not catch-and-swallow errors that should propagate — let them throw so this safety contract kicks in.
Optional: title (set on parent=null only — the design's display name) and note (a one-liner describing what this edit accomplished — purely descriptive, helps you re-ground after a rewind).
Refused parents: if the user saved changes in the browser editor between your parent and the design head, this edit would discard them, so it is rejected — call changes to see what they did and which revision to build on.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | Async JS body. `engine` is in scope, plus `engine.design` — the preferred nested-props facade; EVERY member returns a Promise (await it): create({ type, name?, props?, children? }, { parent? }), setProps(id, props), getProps(id, select?) — see the api skill. Strict return contract per the handbook. | |
| fork | No | Set true ONLY when the user explicitly asked to discard their own browser-editor changes and branch from an older revision. Without it, `edit` refuses a parent whose path to the head contains a save the user made in the editor. | |
| note | No | Freeform descriptive text — what this edit accomplished. Metadata only; never load-bearing. | |
| title | No | Display name for the design. Set only when parent=null (creating a new design). For mid-chain renames use the `rename` tool. | |
| parent | Yes | Parent revision id from a previous edit (a string). To start a new design root, use the JSON null literal. REQUIRED — there is no implicit default. | |
| render | No | Default true: a mutating edit's result ends with a downscaled render of the (first) changed page. Set false to skip the image on read-only or diagnostic edits where seeing the canvas adds nothing. |