# The web workstation

`tra web` opens a browser-based workstation bound strictly to `127.0.0.1` (localhost). It gives beginners and desk operators a live view of market cycles, agent reasoning, portfolio metrics, `.env` credentials, `strategy.toml` configuration, and safety controls without touching an exchange SDK from the browser.

![TRA localhost web workstation](https://bijectivelabs.github.io/bitra/images/web-workstation.png)

## 1. Install the web extra

The base `tra` CLI stays lightweight. To enable the web workstation, include the `[web]` extra:

```bash
uv tool install 'bitra[ccxt,anthropic,openai,google,data,web]'
```

Or in an existing virtual environment:

```bash
pip install 'bitra[web]'
```

## 2. Open the web workstation

There are two ways to start the workstation inside any desk directory (the folder containing `strategy.toml`):

1. **Standalone mode** (recommended before starting a run, to configure keys and settings first):

   ```bash
   tra web
   ```

   The terminal prints a one-time URL bound to `127.0.0.1` with a session token:

   ```text
   tra web: http://127.0.0.1:8420/?token=<ephemeral-token>
   tra web: reading /path/to/desk/runs (localhost only, Ctrl-C to stop)
   ```

   Open that URL in your browser. The server exchanges the token for an `HttpOnly`, `SameSite=Strict` session cookie and redirects to `/`.

2. **Auto-attach mode** (active automatically while trading runs):

   When you run `tra run --every 15m`, `tra paper`, or `tra live`, TRA automatically starts the localhost workstation on port `8420` (or the next free port) and prints `dashboard: http://127.0.0.1:<port>/?token=...`. If `tra web` is already running for the same desk, the runner attaches to the existing session instead of starting a second server.

   Use `--no-web` to disable auto-attach, or `--web-port <port>` to request a specific port.

## 3. Navigation and features

The collapsible left sidebar contains the navigation rail, live desk telemetry, execution controls, **Stop Trading**, and the **Dark / Light** theme toggle.

| Page | What it shows | How to use it |
| --- | --- | --- |
| **Workstation** | Live Execution & Gate Flow (`MARKET -> DECISION -> COST -> RISK -> EXEC -> VENUE`), primary chart, and Cycle Decisions table | Switch between **Line**, **Y-Bar**, **X-Bar**, and **Table** views using the toggle in the chart header so graphs and bars never overlap |
| **Portfolio** | Connected venue and environment, promotion ladder tier, declared equity, cumulative net bps, win rate, max drawdown, equity curve, and recent fills | Review overall desk performance and verify account tier before moving to `live` |
| **Agents** | CLI-equivalent agent lifecycle (`data`, `structure_lead`, `reviewers`, `risk_gate`, `execution`), analyst thesis, refusal reasons, and per-role LLM token and cost breakdown | Inspect why the model proposed or held a trade and monitor token spend in `usage.jsonl` |
| **Telemetry** | Outcome distribution (`PLACED`, `HELD`, `REFUSED`, `TOTAL`), fills summary, and refusal or hold reasons | Audit why gates blocked entries over recent cycles |
| **Config** | Raw `strategy.toml` editor alongside a parsed contract summary | Edit settings and click **Validate & Save**. Changes are validated through `load_strategy_config()` before writing and a `.bak` backup is created |
| **Key Vault** | Write-only `.env` credential manager and active desk readiness table | Select **LLM Provider** or **Exchange Venue** (TRA-integrated venues such as `BYBIT [TRA]` and `BINANCE [TRA]` appear first), enter keys, and click **Save Credentials (0600)** or **Verify Active Keys** |
| **Audit & Logs** | Structured `runs/web_audit.jsonl` trail and live `runs/runner.log` console output | Trace every control action and monitor the detached trading runner |

## 4. Safety rules and VPS resilience

- **Localhost-only by design:** The server refuses non-loopback `Host` headers and external `Origin` headers on mutating requests. Plaintext secrets from `.env` are never sent back to the browser. Only 8-character SHA-256 fingerprints are shown.
- **Mode preflight before starting:** Select **Paper Trading**, **Cycle Run (60s)**, or **Live Canary** in the sidebar. The workstation immediately checks `strategy.toml`, `ladder.json`, and `.env` via the backend and displays a notice if any key or setting is missing for that mode.
- **Configuration lock while trading is active:** Saving `strategy.toml` or `.env` keys from the web is blocked (`409 Conflict`) while a trading runner is active. Click **Stop Trading** first, save your changes, and restart the runner when prompted.
- **Detached runner daemon:** A runner started from the web workstation runs as a detached process (`runs/.tra-runner.lock` and `runs/runner.log`). Closing your browser tab or restarting `tra web` does not stop trading. Reopening `tra web` or running `tra watch` reconnects to the live runner status automatically.
- **Two-step Kill Switch:** Clicking **Pause** immediately holds new entries while open positions keep their exits. Arming **Kill** requires typing `ARM KILL SWITCH` to prevent accidental liquidation.
