portal_patch
Apply patches to a remote file with hash-based conflict detection, preventing overwrites when the file changes concurrently.
Instructions
Apply patches to a remote file with hash-based conflict detection.
Workflow:
Call portal_read to obtain content + file_hash + range_hash for each region.
Call portal_patch with the SAME file_hash and per-patch range_hash.
If the file was modified by anyone else in between, this call returns {"result": "error", "reason": "Content hash mismatch ...", "current_file_hash": ...} — re-read and try again. The remote file is untouched.
patches_json must decode to a list of patch objects: [{"start": int, "end": int|null, "contents": str, "range_hash": str}, ...]
Notes:
Patches are applied bottom-to-top so line numbers stay valid.
Overlapping patches are rejected.
Writes are atomic (tmp file + rename) and re-hashed after write.
When auto_newline is true, missing trailing newlines on patch contents are auto-appended only if the slice they replace ended with one. The result includes a "warnings" list either way.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| host | Yes | ||
| path | Yes | ||
| encoding | No | utf-8 | |
| file_hash | Yes | ||
| auto_newline | No | ||
| patches_json | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |