typst_edit_file
Apply multiple targeted edits to one Typst file in a single save, using unique oldText anchors and expectedHash to reject stale changes; invalid edits fail without saving.
Instructions
Apply all targeted edits against one original file snapshot, with one save. Prefer short unique oldText anchors and expectedHash from typst_read_file to reject stale edits. Exact matching by default (LF/CRLF resilient); matchMode='fuzzy' opts into Unicode/whitespace fallback. Malformed, ambiguous, or overlapping edits fail without saving. Summary output by default; dryRun previews a bounded diff. Unchanged characters and BOM are preserved.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| edits | No | One or more targeted non-overlapping replacements. Each oldText must be unique in the original file. | |
| dryRun | No | Validate and preview edits without saving (default: false). Returned contentHash still identifies unchanged cloud text. | |
| output | No | summary (default): counts, new contentHash, firstChangedLine; diff: also a bounded display diff; full: also bounded patch and full metadata. dryRun defaults to diff. | |
| newText | No | Optional replacement text for single replacement shorthand | |
| oldText | No | Optional shorthand for a single replacement (used if edits is omitted) | |
| filePath | No | File path/name (e.g. 'main.typ') or file ID | |
| matchMode | No | exact (default) matches source with newline normalization. fuzzy enables Unicode quote/dash/space/NFKC fallback only when an exact match is absent. | |
| projectId | No | The Typst project ID | |
| expectedHash | No | Recommended: contentHash from the latest read. Checked against fresh downloaded text inside the file mutation queue; stale files fail without saving. | |
| maxDiffBytes | No | Byte budget per diff/patch field (default: 8192). Each also has a 100-line cap. Truncation is explicit; read affected ranges for full details. | |
| preferWebSocket | No | Push real-time TextUpdate over /editing/v3 WebSocket in addition to REST persistence (default: true) |