graflag.ssh
SSH operations for GraFlag.
- graflag.ssh.remote_path(*parts: str) str[source]
Join path components and quote the result for the remote shell.
Every remote command is a string interpreted by the manager’s shell, so any component that comes from user input (experiment name, method name, dataset) must be quoted before interpolation. Use this for paths and
shlex.quote()for bare values.Separators are collapsed only at the join boundaries – the content of a component is never altered, so a name that happens to contain
/stays intact (and quoted) rather than being silently rewritten.
- graflag.ssh.NON_INTERACTIVE_OPTS = ['-o', 'BatchMode=yes', '-o', 'ConnectTimeout=15']
Options that make ssh fail instead of asking. A client with nobody at the keyboard – the MCP server, whose stdin and stdout are the protocol – must not wait on a password or passphrase prompt: the tool call would hang until the client gave up, with nothing saying why.
- class graflag.ssh.SSHManager(manager_ip: str, ssh_port: str = '22', ssh_key: str = None, batch_mode: bool = False)[source]
Bases:
objectHandle SSH operations to remote manager.
- execute(command: str, capture_output: bool = True) CompletedProcess[source]
Execute command on manager via SSH.
The command is passed to ssh as a single argv element, so no local shell ever parses it. This keeps quoting, heredocs and newlines in
commandintact – the manager’s shell sees exactly what was built here. Callers are still responsible for quoting values they interpolate (seeremote_path()), because the remote shell does parse the string.
- path_exists(remote_shared_dir: str, path: str) bool[source]
Check if path exists on remote manager.
- list_dir(remote_shared_dir: str, path: str) List[str][source]
List directory contents on remote manager.
- copy_files(source_paths, dest_path: str, recursive: bool = False, from_remote: bool = False) str[source]
Copy files/directories bidirectionally via rsync.
- Parameters:
source_paths – Source path(s) - can be single string or list
dest_path – Destination path
recursive – Accepted for compatibility; rsync -a always recurses
from_remote – If True, copy from remote to local; if False (default), copy from local to remote
- Returns:
Destination path