file_edit_lines
Apply multiple line-based edits—patch, insert, delete, or append—to one file in a single atomic call using original line numbers, with validation and dry-run before writing.
Instructions
Apply one or more edits to a single file in one atomic operation. All patches are validated and then applied bottom-up - supply the ORIGINAL line numbers from your last read.
actions:
patch: replace startLine..endLine with content (both inclusive, 1-based)
insert: insert content after startLine; use startLine=0 to prepend
delete: remove startLine..endLine; content is ignored
append: add content at the end of the file; line numbers are ignored Content is lines separated by line breaks; one final line break does not add an empty line.
COPY, DO NOT RETYPE: patch, insert and append may carry "from" instead of content. The server copies the lines (same file, another file, another workspace); you write none of them. "from": { "file": "Services/A.cs" (default: this file), "workspace": "Other" (default: this workspace), "startLine": 40, "endLine": 80 (leave both out for the whole file), "expectFirstLine": "public void Foo()", "expectLastLine": "}" (compared trimmed; the copy is refused if the lines moved), "remove": true (cut: the lines are deleted from their file too; both expect lines required), "replace": [{"find": "Invoice", "with": "Order", "count": 12}] (literal text, the match count must equal count), "csharp": {"namespaces": {"Old.Ns": "New.Ns"}, "identifiers": {"OldName": "NewName"}} (C# files only, by syntax; strings and comments are never touched; use replace for other languages), "indent": -4 (shift every line; negative removes leading spaces or tabs) } Use from whenever you move or duplicate more than about 10 lines that stay mostly the same. Take the line numbers from code_outline or code_method. Copied text that holds a secret is refused. Line numbers in from refer to the source as it is now.
dryRun=true runs every check and copy and reports what would happen without writing.
MANDATORY BATCHING RULE - violations cause wrong-place edits: When making several changes to the same file, send ALL patches in a SINGLE file_edit_lines call. Waymark applies them bottom-up, so line numbers stay correct across all patches. A second call uses line numbers that changed with the first one and lands at the WRONG LINE. Correct: one call with patches [{lines 10-12}, {lines 45-50}, {lines 80-85}] Wrong: three separate file_edit_lines calls for the same file.
OVERLAP RULE: ranges must not overlap - this is checked before anything is written. The file keeps its encoding and line endings. A cut from another file changes both files or neither. RETURNS: final line count, size in bytes, last-modified time, lines affected and, for copies, where the text came from.
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"workspace": "<workspace>",
"relativeFilePath": "<relativeFilePath>",
"patchesJson": "<patchesJson>"
},
"name": "file_edit_lines"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| guide | No | true: put the files guide first in the result. Use on your first files call, or when told it changed. | |
| dryRun | No | true: check and report only, write nothing (default false) | |
| workspace | Yes | Workspace name as shown in Waymark (a single workspace; '*' is not accepted) | |
| patchesJson | Yes | JSON array of patch operations. Each entry: { "action": "patch|insert|delete|append", "startLine": 45, "endLine": 89, "content": "<new content>" } or, to copy lines instead of typing them, replace content by "from": { ... } (see the tool description). startLine/endLine are 1-based. content is ignored for delete. | |
| relativeFilePath | Yes | Relative file path from the workspace root (e.g. 'Services/OrderService.cs') |