<!-- rye:signed:2026-04-07T03:32:52Z:f3489a1fb145940d3ac7ac726f495de5c2e6eb1fb9a1236d72912a4d364c8135:vQ59b9MDgmRxtfqkYAQJfuIWgiRt2kquZ_C8pjmX-pWQNwRqI47qzmoMBmaa90CKCpQWxzGnnxdom1czQ8LcCA:6ea18199041a1ea8 -->
# Edit Lines

Edit specific lines in a file using line IDs from a prior read.

```xml
<directive name="edit_lines" version="1.0.0">
  <metadata>
    <description>Edit specific lines in a file by line ID. Requires reading the file first to obtain line IDs.</description>
    <category>rye/file-system</category>
    <author>rye-os</author>
    <model tier="fast" />
    <limits turns="3" tokens="2048" />
    <permissions>
      <execute>
        <tool>rye.file-system.edit_lines</tool>
      </execute>
    </permissions>
  </metadata>

  <inputs>
    <input name="file_path" type="string" required="true">
      Path to the file to edit (absolute or relative to project root)
    </input>
    <input name="changes" type="array" required="true">
      List of changes. Each change is either {line_id, new_content} for single-line edits or {start_line_id, end_line_id, new_content} for range replacements.
    </input>
  </inputs>

  <outputs>
    <output name="result">Edit result with number of lines changed</output>
  </outputs>
</directive>
```

<process>
  <step name="validate_inputs">
    Validate that {input:file_path} is non-empty and {input:changes} is a non-empty array.
    Each change must have either (line_id + new_content) or (start_line_id + end_line_id + new_content).
  </step>

  <step name="prerequisite">
    **Important:** The file must be read first using `rye/file-system/read` to obtain line IDs.
    Line IDs are generated by the read tool and are required to identify which lines to edit.
    `rye_execute(item_type="tool", item_id="rye/file-system/read", parameters={"path": "{input:file_path}"})`
  </step>

  <step name="call_edit_lines">
    Apply the edits:
    `rye_execute(item_type="tool", item_id="rye/file-system/edit_lines", parameters={"path": "{input:file_path}", "changes": {input:changes}})`
  </step>

  <step name="return_result">
    Return the edit result with the number of lines changed.
  </step>
</process>
