troll 0.4.0

The port manager that guards the bridge: permanent claims, expiring leases, and a live view of who listens where.
![troll port manager banner](https://raw.githubusercontent.com/michelabboud/troll/main/docs/assets/readme/hero.webp)

# troll

The port manager for one machine: permanent **TCP & UDP** claims, expiring leases, and a live view of who listens where (including passive read-only Docker/Podman container attribution). One Rust binary providing the CLI, local HTTP API, embedded three-screen web console, and MCP stdio server across **Linux (`x86_64` & `arm64`), macOS (`arm64` & `x86_64`), and Windows (`x86_64`)**.

## Install

- **Cargo (Linux, macOS, Windows):**

```sh
cargo install troll --locked
```

- **Shell installer (Linux & macOS, SHA-256 verified):**

```sh
curl -fsSL https://raw.githubusercontent.com/michelabboud/troll/main/scripts/install.sh | sh
```

- **PowerShell installer (Windows, SHA-256 verified):**

```powershell
irm https://raw.githubusercontent.com/michelabboud/troll/main/scripts/install.ps1 | iex
```

- **Homebrew (macOS & Linux):**

```sh
brew tap michelabboud/troll https://github.com/michelabboud/troll
brew install michelabboud/troll/troll
```

Prebuilt archives (`x86_64-linux`, `aarch64-linux`, `aarch64-macos`, `x86_64-macos`, `x86_64-windows` + `SHA256SUMS.txt`) are also published on [GitHub Releases](https://github.com/michelabboud/troll/releases/latest), and WinGet manifests live in [`packaging/winget/`](https://github.com/michelabboud/troll/tree/main/packaging/winget).

## Quick start

```sh
troll init
troll check 8123
troll claim 8123 --project demo --service web
troll lease --project demo --purpose preview --json
troll with --project demo -- sh -c 'printf "Leased port %s\n" "$PORT"'
troll explain 8123
troll list
troll doctor
troll serve
```

## Four surfaces, one locked registry

- **Command line (`troll ...`):** manage TCP & UDP claims (`--proto tcp|udp`), leases, named `[pools]`, apps, declarative `troll.toml` (`sync`), atomic `env --write`, red zones, 30-day removal `history` (with atomic restore), drift inspection, `explain`, and `doctor`. Add `--json` for machine output or `--llm-guide` for agent instructions.
- **Web console (`troll serve`):** local loopback HTTP API and embedded three-screen browser console (**Console**, **Apps**, **History**) with six themes, passive service detection, and one-click copy/restore actions.
- **MCP server (`troll mcp`):** Model Context Protocol server over stdio for coding agents (`troll setup claude` / `troll setup codex`).
- **Background service (`troll setup service`):** writes a systemd user unit on Linux, a `launchd` user agent plist on macOS, or a Task Scheduler XML definition on Windows.

![troll web console screenshot](https://raw.githubusercontent.com/michelabboud/troll/main/docs/assets/console/console-light.png)

## Guarantees

- **Never kills arbitrary processes:** sweeps remove only reclaimable leases from `registry.toml` and leave running processes alone (the sole documented signal exception is `troll with` forwarding a received stop signal unchanged to its own child).
- **Safe locked writes:** file-locked atomic updates with a backup copy on every change.
- **Loopback only:** `troll serve` binds `127.0.0.1`, enforces an exact `Host` allowlist, and requires a session token and matching `Origin` for mutations.
- **Zero `unsafe` code** across the workspace.

## Workspace crates

This binary crate is built on two companion library crates:

- **[`troll`]https://crates.io/crates/troll** *(this crate)* — CLI, `troll serve` HTTP API + embedded web console, `troll mcp` stdio server, setup wizard, and OS service installers.
- **[`troll-core`]https://crates.io/crates/troll-core** — platform-free registry model, file-locked atomic store, claims, leases, pools, red zones, 30-day history, drift, and sweep engine.
- **[`troll-probe`]https://crates.io/crates/troll-probe** — read-only OS listener, ephemeral/excluded range, process liveness, and owner-classification probe for Linux, macOS, and Windows.

## Documentation

- [GitHub repository & full illustrated README]https://github.com/michelabboud/troll
- [Command-line guide]https://github.com/michelabboud/troll/blob/main/docs/guides/command-line.md
- [Console guide]https://github.com/michelabboud/troll/blob/main/docs/guides/console.md
- [JSON, HTTP & MCP reference]https://github.com/michelabboud/troll/blob/main/docs/guides/json-output.md
- [Runbook]https://github.com/michelabboud/troll/blob/main/RUNBOOK.md
- [Architecture]https://github.com/michelabboud/troll/blob/main/ARCHITECTURE.md

## Licence

MIT — see [LICENSE](https://github.com/michelabboud/troll/blob/main/LICENSE).