The magic wand

Python code cells, HTML5 snippets, Mermaid charts, the Math items (KaTeX formulas and JSXGraph constructions), and Music notation (ABC tunes), and molecular structures each carry a 🪄 magic wand — one button that asks the configured LLM to write, fix, or improve what’s in the editor and streams the result straight back into it, replacing what was there (with live highlighting; the button pulses while it streams).

It uses whatever model the Chat track is set to — bring your own key or a hosted model. See Connecting a model. With no model configured the wand can’t run; in a code cell the original source is restored and the reason is shown in the output.

What goes into the prompt

You don’t write a separate instruction box — the editor’s current contents are the prompt. That means the wand handles three situations from the same button:

  • Write from scratch — type a plain-English description of what you want and hit the wand; it generates the code or markup.
  • Improve existing code — leave working code in place and the wand refines it.
  • Targeted edit — put a marker comment in the source describing the change you want (#> in Python, HTML and molecule sources, %%> in Mermaid, %> in KaTeX and in ABC music notation, //> in JSXGraph code), and the wand treats that comment as the instruction to apply rather than rewriting everything.

In Python code cells

The wand is built for the notebook context:

  • Fix the last error — if the previous run raised, its traceback is folded into the prompt, so “fix this” just works after a failed run.
  • Knows your linked data — the exact SHEETS and IMAGES keys the cell will see (its own links plus any inherited from ancestor cells) are listed in the prompt, so a rewrite reads them via pd.read_excel(SHEETS["…"]) / PIL.Image.open(IMAGES["…"]) instead of inventing file paths. See linked data.
  • On failure (or with no model configured) the original code is restored and the reason is shown in the cell’s output — the wand never leaves you with a half-written cell.

In HTML5 bubbles

The same wand lives in the HTML5 authoring modal:

  • The editor’s text — a description, existing markup to improve, or a #> targeted edit — is the prompt, and generated HTML (inline <style> and <script> included) streams into the editor. Submit renders it.
  • Knows your linked images — the available IMAGES keys (image1, image2, …) are named in the prompt, so a generated snippet wires the linked images in rather than inventing placeholders. A common flow is to drop an empty bubble, link images onto it, then run the wand — it already knows the images. See linked images.

In Mermaid charts

The same wand lives in a Mermaid chart’s source editor:

  • The editor’s text — a plain-English description of the diagram, or rough Mermaid to improve — is the prompt, and a valid Mermaid definition streams into the editor, replacing its contents. Submit re-renders the diagram.
  • ↶ / ↷ undo and redo the wand’s rewrites, and a %%> comment (Mermaid’s comment marker) flags a targeted edit to apply rather than a full rewrite.

In Music notation

The same wand lives in a Music notation item’s source editor:

  • The editor’s text — a plain-English description of the tune (“a lively jig in D”, “harmonize this in two voices”), or existing ABC to improve — is the prompt, and a complete ABC tune (headers + body) streams into the editor. Submit re-engraves the sheet.
  • ↶ / ↷ undo and redo the wand’s rewrites, and a %> comment (a valid ABC comment) flags a targeted edit to apply rather than a full rewrite.

In molecular structures

The same wand lives in a 3DMol structure’s source editor:

  • The editor’s text — the name of a molecule (“caffeine”, “the SMILES for ibuprofen”), or a structure to correct — is the prompt, and the notation streams into the editor. Submit re-renders the structure.
  • The wand is steered toward SMILES, since models write it reliably and it always renders, whereas a guessed PDB id may fetch nothing.
  • ↶ / ↷ undo and redo the wand’s rewrites, and a #> marker flags a targeted edit to apply rather than a full rewrite.

Tips

  • Be specific in the description or #> comment — the wand only sees what’s in the editor (plus a traceback / your linked-data keys), not the rest of the board.
  • After a failed run, just click the wand — the traceback is already included, so you rarely need to explain the error.