docs/cmd/ez-agent-tunnel.md
ez-agent-tunnel
ez-agent-tunnel is an external stdio capability provider. It registers the
tunnel.localport macro through the existing service connection; it does not
require a leaf. When included in a distribution, the service can start it from
its builtin configuration. It connects only to IPv4 loopback on its own host.
It does not accept a host name or remote address.
The release archive includes this binary. The installer installs it by default,
including with --minimal. Pass --no-tunnel to skip installing it without
changing the Ruby or webfetch selection. This does not remove an existing binary.
TUI port forwarding
A conversation can contain a link such as
[Open dashboard](ez-agent://tunnel/localport/8080/dashboard). The chat
shows the destination beside the link label. Click the link, or use Tab to
focus the chat and then Tab or Shift+Tab to select a link and Enter to activate
it. Check the source localhost port, connected service and path, then choose
Start or Decline. Ctrl+T is an optional link chooser. Displaying a link, browsing
it and declining do not contact the tunnel macro or open a listener. Ordinary
web links are unchanged.
After discovery and bind succeed, the status line shows an assigned
http://localhost:PORT/dashboard URL. /tunnels lists active and pending
forwards and retained setup failures. Select one to see its source, service,
status and local URL, and to stop or cancel it. Active and pending forwards also
appear in Inbox. Active Inbox rows show a compact ID and assigned
localhost:PORT; open details for the full URL. Filtering also searches the full
URL, source port, path, service and state. Each accepted link creates an
independent entry, even when another entry forwards the same source port.
Switching chats does not stop them.
Quitting the TUI stops and joins the forwards. No browser is opened.
After acceptance or decline, the TUI returns to the same chat.
The listener binds IPv4 loopback on the client machine and can be accessed by
other local processes. Each connection opens a new stream to the specified
source localhost port on the connected service's machine. A successful setup
does not prove the source service is running: it is contacted on the first TCP
connection. In local-to-local use the client port differs from the source port.
The path is appended to the HTTP URL only; it is not sent to the macro and does
not restrict the TCP traffic or other paths. Query strings and fragments in the
custom link are rejected. Percent escapes in the path are retained. The TUI
owns up to 32 forward entries independently of the current chat; completed
entries are reclaimed as needed. Ctrl+T remains an optional link chooser and
can stop the first running forward. Setup failures are counted in the status
line and Ctrl+T menu; select a failed entry in /tunnels for its error. Failed
entries are reclaimed as needed.
The embedded client-port-forwarding skill describes how an agent can offer a
link. It declares requires-tunnel: true, so it is only discoverable and loadable
by name while an executable ez-agent-tunnel is beside the physical
ez-agent-builtin executable. For a model-free, isolated manual check, see the
computer-use tunnel demo.
Macro rows
The macro parameter and result are single EzAgent CSV rows. IFO returns
IFO,Source-local TCP port forwarding,localport,1. To open one TCP stream,
send INIT,<id>,localport,<port>. The ID follows the limits in the
tunnel pipe contract. The port is a canonical
decimal integer between 1 and 65535. The provider reserves the ID, connects to
127.0.0.1:<port>, and returns START,<id> only after the connection succeeds.
A duplicate live ID, invalid setup, exhausted stream limit, or failed connection
returns a macro error. CLOSE or ERROR during opening cancels the source dial;
INIT and all already accepted calls complete with that terminal row, without
START. A socket returned concurrently with cancellation is closed before those
calls complete. Each accepted client connection needs a fresh ID and INIT;
the supplied HTTP path is not part of the stream setup.
After START, send pipe rows to the same macro. Each invocation supplies a reply slot, including SEND and ACK calls. Replies contain pipe rows. Calls may remain held while the API sends operation heartbeats. The provider bounds live streams at 128, and each stream has the pipe's independent slot and byte limits. CLOSE and ERROR immediately terminate the stream. All owned calls receive the same terminal row, including calls still queued for dispatch. Unknown IDs and invalid rows return macro errors; the provider does not resume or replay a stream. Closing the provider connection or shutting it down closes its sockets and owned calls. The provider limits output awaiting the transport to 1024 frames and 4 MiB, including flush markers in the frame count. One frame being written is outside that queue. It also permits at most 4096 concurrent reply deliveries. If either limit is exhausted, the provider closes its service connection rather than accumulating more work. On transport closure it releases source streams and exits without waiting indefinitely for an inherited blocked stdio descriptor.
The source socket reader and writer do not run in the pipe owner. A received frame is acknowledged only after its full payload has been written to the source socket. On source EOF, the provider waits until all response frames have been acknowledged before sending CLOSE. The receiving adapter must likewise acknowledge a frame only after its full payload has been written to its destination socket. This drain makes ordinary HTTP responses safe when the source closes after its response; CLOSE itself remains immediate and abortive. This does not support protocols that require a request-side half-close before producing a response.