H.RemoteAgent (H v0.3.0)

Copy Markdown View Source

In-VM cooperative remote execution agent GenServer (H.ExecutionEnv.Remote transport seam).

Owns a host-backed H.ExecutionEnv.t() (H.ExecutionEnv.Host) and an explicit plain environment descriptor (%{id: id, kind: "remote", cwd: cwd}). Process state lives in memory for the duration of the run and excludes credentials or auth secrets.

Future network transport

This module implements the local in-VM RPC endpoint proving fencing, lease-TTL heartbeats, bounded execution output, and process-group reaping semantics. A future network adapter (authenticated mTLS WebSocket/HTTPS or SSH subsystem) will replace the GenServer call/message framing while preserving this protocol contract.

Summary

Functions

Aborts an active fenced execution and waits for its process group to be reaped.

Returns the list of currently active execution fences on this agent.

Remotely resolves path and verifies that it exists as a directory.

Remotely canonicalizes path by resolving symlinks on the target agent.

Returns a specification to start this module under a supervisor.

Returns the agent's canonical base working directory.

Returns the plain JSON-safe environment descriptor (id, kind: "remote", cwd).

Executes command on the remote agent under fence and optional lease semantics.

Lists a remote directory with sorting, pagination, hidden/dir filters, and markers.

Recursively discovers bounded files and directories on the remote agent.

Reads bounded raw bytes from a remote file.

Reads bounded UTF-8 lines from a remote file.

Renews the lease TTL (in milliseconds) for an active fenced execution.

Remotely resolves path using target OS POSIX path semantics.

Starts a H.RemoteAgent process.

Atomically writes content to a remote file, creating missing parent directories.

Types

descriptor()

@type descriptor() :: %{id: String.t(), kind: String.t(), cwd: String.t()}

fence()

@type fence() :: {term(), term(), term(), term()}

server()

@type server() :: GenServer.server()

Functions

abort(agent, fence)

@spec abort(server(), fence()) :: :ok | {:error, :not_found | {:agent_down, term()}}

Aborts an active fenced execution and waits for its process group to be reaped.

active_fences(agent)

@spec active_fences(server()) :: [fence()]

Returns the list of currently active execution fences on this agent.

bind_cwd(agent, path, opts \\ [])

@spec bind_cwd(server(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, term()}

Remotely resolves path and verifies that it exists as a directory.

canonical_path(agent, path, opts \\ [])

@spec canonical_path(server(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, term()}

Remotely canonicalizes path by resolving symlinks on the target agent.

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

cwd(agent)

@spec cwd(server()) :: String.t()

Returns the agent's canonical base working directory.

descriptor(agent)

@spec descriptor(server()) :: descriptor()

Returns the plain JSON-safe environment descriptor (id, kind: "remote", cwd).

exec(agent, command, opts \\ [])

@spec exec(server(), H.ExecutionEnv.command(), keyword()) ::
  {:ok, H.ExecutionEnv.exec_result()} | {:error, term()}

Executes command on the remote agent under fence and optional lease semantics.

Supports :session_id, :incarnation, :task_id, :attempt_id, :lease_ms, :cwd, :timeout_ms, :window_bytes, :window_lines, :abort_ref, :on_output, and :env. Rejects duplicate or older fences with {:error, :stale_fence}.

list_dir(agent, path, opts \\ [])

@spec list_dir(server(), String.t(), keyword()) ::
  {:ok, %{entries: [map()], next_cursor: nil | non_neg_integer()}}
  | {:error, term()}

Lists a remote directory with sorting, pagination, hidden/dir filters, and markers.

list_files(agent, path, opts \\ [])

@spec list_files(server(), String.t(), keyword()) ::
  {:ok, %{entries: [map()], truncated: boolean()}} | {:error, term()}

Recursively discovers bounded files and directories on the remote agent.

read_file_bytes(agent, path, opts \\ [])

@spec read_file_bytes(server(), String.t(), keyword()) ::
  {:ok, binary()} | {:error, term()}

Reads bounded raw bytes from a remote file.

read_file_lines(agent, path, opts \\ [])

@spec read_file_lines(server(), String.t(), keyword()) ::
  {:ok, map()} | {:error, term()}

Reads bounded UTF-8 lines from a remote file.

renew_lease(agent, fence, lease_ms)

@spec renew_lease(server(), fence(), pos_integer()) ::
  :ok | {:error, :not_found | :invalid_lease_ms | {:agent_down, term()}}

Renews the lease TTL (in milliseconds) for an active fenced execution.

resolve_path(agent, path, opts \\ [])

@spec resolve_path(server(), String.t(), keyword()) ::
  {:ok, String.t()} | {:error, term()}

Remotely resolves path using target OS POSIX path semantics.

start_link(opts)

@spec start_link(keyword()) :: GenServer.on_start()

Starts a H.RemoteAgent process.

Options

  • :env (required) - base H.ExecutionEnv.t() instance owned by the agent
  • :id - non-empty environment identifier string (defaults to H.ExecutionEnv.env_id(env))
  • :name - optional GenServer registration name

write_file(agent, path, content, opts \\ [])

@spec write_file(server(), String.t(), iodata(), keyword()) :: :ok | {:error, term()}

Atomically writes content to a remote file, creating missing parent directories.