aft icon indicating copy to clipboard operation
aft copied to clipboard

Support safe remote file edits through SSH-config hosts

Open jjjermiah opened this issue 1 month ago • 1 comments

Editing a remote host's OpenCode config required an inline script over ssh because AFT read/edit/write only accept local paths. In my case, the shell quoting failed and took several retries. This comes up with Proxmox containers, NAS config and systemd units.

v0.63.5 has no ssh:// path handling for these file tools. Could AFT support SSH-config host paths with the normal read/edit safety and an optimistic check that the remote file did not change between read and write? A documented fetch-edit-upload recipe with a concurrency check would also address the immediate need. This is a feature request, not a regression claim.

jjjermiah avatar Nov 01 '26 19:11 jjjermiah

Thanks for the request, @jjjermiah. We're not adding SSH hosts to AFT's file tools. It would need a remote file backend, its own permission model, and a safe way to notice when the remote file changes underneath an edit.

This pattern works today and stays safe when the remote file changes in the meantime:

# 1. Copy the file and record the remote checksum.
scp myhost:/etc/app/config.json /tmp/config.json
ssh myhost 'sha256sum /etc/app/config.json' > /tmp/config.json.sha

# 2. Edit /tmp/config.json with read and edit as usual.

# 3. Upload next to the original, then replace it only if the original is unchanged.
scp /tmp/config.json myhost:/etc/app/config.json.new
ssh myhost 'sha256sum -c --quiet - && mv /etc/app/config.json.new /etc/app/config.json' < /tmp/config.json.sha

If step 3 reports a mismatch, someone changed the file on the host; copy it again and redo the edit. mv replaces the file in one step, so set ownership and permissions on the .new file first if they matter. On hosts without sha256sum, use shasum -a 256.

aft-alfonso[bot] avatar Nov 17 '26 12:11 aft-alfonso[bot]