Edit Engine
@plyy/astro-edit-engine (packages/astro-edit-engine) turns visual edits into .astro source rewrites. It parses files with @astrojs/compiler, so edits land at the exact source location Astro’s dev-server annotations point to. See Visual Editing for how it fits into the editor flow.
readElementAt/readElementFromAnnotation— resolve an element (ElementInfo) from a file plus source location ordata-astro-source-*annotationapplyEdit(source, op)— apply anEditOperation(text, classes, wrap, delete, …) and return anEditResultwith the rewritten sourcefindComponentUsage— trace where a component is used across the project
The suite runs with bun test.
astro-edit CLI
Section titled “astro-edit CLI”The package exposes a Bun CLI (src/cli.ts) with four commands:
astro-edit read <file> <loc> # element info at an annotation location (JSON)astro-edit usage <file> <componentPath> # component usage info (JSON)astro-edit edit <file> '<opJson>' # apply an EditOperation, write the fileastro-edit serve # daemon mode (see below)Daemon mode
Section titled “Daemon mode”astro-edit serve reads one JSON request per stdin line and writes one JSON response per stdout line. This keeps the process — and the compiler’s WASM — warm, so editor operations cost about a millisecond instead of a full process spawn. The desktop app keeps a persistent serve process alive (src-tauri/src/engine.rs) and routes its edit commands through it.