Metadata-Version: 2.4
Name: replx-agent
Version: 2.0.0.post1
Summary: Local MicroPython board-management agent for replx.
License-Expression: MIT
Project-URL: Homepage, https://planxlab.com
Project-URL: Repository, https://github.com/PlanXLab/replx
Project-URL: Issues, https://github.com/PlanXLab/replx/issues
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pyserial>=3.5
Requires-Dist: psutil>=7.2.2
Requires-Dist: esptool<6,>=5.6.0
Requires-Dist: mpy-cross>=1.29.0
Dynamic: license-file

# replx-agent

`replx-agent` is the board-management service used by the `replx` MicroPython CLI. It owns serial discovery and connections, board filesystem operations, transfer staging, and firmware flashing through `esptool`.

## Package Boundary

The CLI depends on `replx-agent`; the agent never imports `replx`. The packages communicate through a versioned TCP RPC protocol, allowing separate builds while protocol versions remain compatible. The distribution version is defined in `src/replx_agent/__init__.py`.

## Runtime

- The agent is a single process per endpoint and supports multiple TCP clients using `ThreadingTCPServer` and bounded command worker pools.
- Serial access is owned by the agent. Commands for the same board are serialized; separate boards can be serviced concurrently.
- Client sessions are identified by source IP and terminal SID. `replx agent status` reports the current client's foreground/background board assignments.
- The default endpoint is `127.0.0.1:49153`. The CLI creates `.vscode/.replx` as needed and stores `AGENT_IP` and `AGENT_PORT` there.
- Legacy `~/.replx/config`, `~/.replx/.config`, and `~/.replx/.agent_port` settings are read for migration compatibility.

## Remote Access

The default loopback endpoint does not require a token. Binding to a non-loopback interface or connecting to a non-loopback agent requires the same `REPLX_AGENT_TOKEN` environment variable on the agent and every client.

```powershell
$env:REPLX_AGENT_TOKEN = "<shared-secret>"
replx agent start --host 192.168.1.20 --port 49153
```

On Linux/macOS, export the variable before starting the agent or running the client:

```sh
export REPLX_AGENT_TOKEN="<shared-secret>"
replx agent connect 192.168.1.20 --port 49153
```

The RPC transport is plain TCP, not TLS. Use remote access only on a trusted LAN or VPN; do not expose the port to an untrusted network.

## CLI Lifecycle

```sh
replx agent status
replx agent start --port 49153
replx agent connect 192.168.1.20 --port 49153
replx agent disconnect 192.168.1.30
replx agent stop
```

`agent start` restarts an existing local agent at the selected endpoint. `agent connect` verifies the endpoint before saving workspace settings. `agent disconnect IP` removes that client's sessions and releases only boards not still assigned to another client. `agent stop` stops the configured agent and releases its board connections.
