AI Agent Guide
This page is written for the AI agent driving Etch — you can point it at this page, or it can read it on its own. It covers what's specific to working through the connector. It does not document the API itself — for the actual commands a script calls (etch.blocks, etch.styles, etch.components, and so on), see the Public API docs.
The connector's own agent instructions live in etch-connector --help. It documents the backends, commands, flags, the stdout/stderr/exit-code contract, and how to pull the current Etch docs. Read the entire output before driving a tab.
How scripts run
- Run scripts with
etch-connector eval -t <tab> "<js>"(or-f file.js). See Usage for the full flow. - The body runs as an async function — use
awaitandreturna value. The return value comes back on stdout as JSON. - Tabs connect in safe mode: only the
etchglobal plus standard JS exist. There is nowindow/document— referenceetch.*directly. See Security.
Saving your changes
How a change reaches the database depends on which part of the API you used:
etch.blocks,etch.styles, andetch.loopsare buffered — persist them withawait etch.saveAsync().etch.components.*,etch.stylesheets.*, andetch.assets.*persist immediately; nosaveAsync()needed.
This matches the persistence model in the Public API docs — refer there for the per-namespace details.
Files and images
When the connected runtime supports the relevant operations, use etch-connector upload <file> --alt "…" to upload an image and bind the returned id to an etch/dynamic-image block's mediaId. Use etch-connector download <id> --out <path> to write an existing image to disk. These commands handle encoding; do not paste file contents into an eval. Check the asset capabilities first. Upload-time --compress is not available in EtchWP's partial implementation.