pi-egress0.1.0
Pi extension that routes the agent's network egress through configurable proxy profiles
Untested on omp
This is a pi package. No one has reported whether it works on omp yet. If you try it, add your result below.
Reports 0
No reports yet.
Readme
pi-egress
Route Pi's outbound traffic through configurable HTTP/HTTPS proxy profiles, selected per session with /egress or the set_egress tool. Routing covers the global undici dispatcher (including Node's fetch) and subprocesses that honor proxy environment variables.
Install
Requires Node.js 22.19.0 or newer and Pi.
pi install npm:pi-egress
Create ~/.config/pi-egress/config.json using config.example.json as a starting point, then set the proxy URLs to your running proxy endpoints. The extension connects to existing proxies; it does not start them. Restart Pi or run /reload, then use /egress to see the route or /egress direct to switch it.
If you previously loaded this extension through a symlink or an explicit extension path, remove that entry before enabling the npm package to avoid duplicate registrations.
How it works
The extension installs a wrapper as the global undici dispatcher and routes each request:
- Private-host bypass matches IP literals and local hostname suffixes: loopback, RFC 1918, link-local, CGNAT,
.local, and.ts.net. - In normal modes, model backend traffic stays direct; tool and extension traffic goes through the selected proxy profile.
- In
-fullmodes, model traffic goes through the proxy too. - Proxy environment variables (
HTTP_PROXY,HTTPS_PROXY,ALL_PROXY,NO_PROXY, plus lowercase variants) are set or restored to match the route, so subprocesses follow it as well. autotries the profiles in config order and blocks public requests through the dispatcher if none is reachable. A named profile that is unreachable produces an error instead.
Modes
| Mode | Meaning |
|---|---|
direct |
No profile proxy; restore inherited network settings |
auto |
First reachable profile in config order |
full |
auto with model traffic proxied too |
<profile> |
That specific profile |
<profile>-full |
That profile with model traffic proxied too |
<profile>-light |
Alias for <profile> |
Mode changes apply to the current session. /reload retains the selected mode; a new session starts with defaultMode.
Config
The config file is resolved from the PI_EGRESS_CONFIG environment variable, or defaults to pi-egress/config.json under the XDG config home (~/.config/pi-egress/config.json).
See config.example.json for a working example.
| Field | Type | Default | Description |
|---|---|---|---|
profiles |
array | required | Proxy profiles, tried in listed order for auto |
defaultMode |
string | auto |
Mode applied at session start |
noProxy |
string[] | localhost, loopback, private ranges, CGNAT, .local, .ts.net |
Exported through NO_PROXY for proxy-aware subprocesses |
connectTimeoutMs |
number | 750 |
Default reachability check timeout |
modelProxy |
object | absent | Route model backends through a pre-existing proxy when activateEnv equals 1; the proxy URL is read from the environment variable named by urlEnv (checked at both cases) |
Each profile:
| Field | Type | Default | Description |
|---|---|---|---|
name |
string | required | Lowercase identifier matching ^[a-z0-9_]+$; built-in mode names are reserved |
label |
string | name |
Human-readable name for error messages |
url |
string | required | Proxy URL, http or https |
proxyTunnel |
boolean | true |
Passed to undici ProxyAgent |
connectTimeoutMs |
number | global value | Per-profile reachability check timeout |
A missing or invalid config file does not break the extension: it falls back to direct-only mode and reports the problem in /egress status.
Debugging
Start Pi with NODE_DEBUG=pi-egress pi. Diagnostics go to stderr and record mode changes, proxy probe outcomes, request route selection, and session cleanup. URLs and request contents are omitted.
Development
npm ci
npm run check
npm test
npm pack
npm pack checks types and runs the tests, including the package installation test, before creating the npm tarball. The package ships TypeScript modules, which Pi loads directly, and declares undici as a runtime dependency. Pi supplies the host API and TypeBox.
The installation test registers the tarball with pi install in a temporary Pi configuration and checks extension loading and /egress through RPC without calling a model. Run it on its own with npm run test:package.
Releases
Commit the package version to main, then push a matching v<version> tag. The publish workflow verifies the tag and tests the package before producing a tarball. After approval in the protected npm environment, it submits that same tarball to npm using OIDC. Approve the staged package on npm with 2FA to make the release public.
The npm trusted publisher must authorize publish.yml and the npm environment for staging. No npm token is stored in GitHub. A manual workflow run verifies the package without submitting it to npm.