engawa-chat 0.2.0

A peer-to-peer chat lobby for editors and browsers
# <img src="https://raw.githubusercontent.com/yukimemi/engawa/main/assets/logo.svg" alt="Engawa" width="240" height="64">

Drop into a public chat room from your editor or browser. Everyone shares a lobby, but nobody needs to host it. The `engawa` binary runs a peer while you're using it; the browser dashboard and Neovim plugin are two ways to talk to that peer.

## Get started

Install [engawa-chat](https://crates.io/crates/engawa-chat) with Cargo, then open the dashboard:

```sh
cargo install --locked engawa-chat
engawa web
```

Select a room in the dashboard, or create one and choose whether it keeps history. Stop the process with Ctrl-C. The browser UI runs on your own machine, not on a hosted website. For Neovim, see [engawa.nvim](https://github.com/yukimemi/engawa.nvim).

### Invite someone on a phone

From a room in `engawa web`, copy its **invite link**, not the address bar. Keep Engawa running and stay in the room until your friend joins. They open the link in a modern mobile browser, check the room name and history policy, and tap **Join**. No CLI, VPN, or shared Wi-Fi is required on the phone.

The phone runs its own iroh endpoint and signs its own posts; it never receives your local API token. The link fragment contains the room, policy, inviting endpoint and relay address. It is a bootstrap hint for a **public** room, not a private access key. Browsers use a secure relay connection instead of native UDP/DHT discovery. Opening a link after its inviter has left or restarted may require a fresh invitation.

Guest messages and keys live in tab memory. Retained rooms can supply recent posts from online peers; a reload or new guest session loses the ability to withdraw that session's posts. A live-only room never supplies history.

### Host the static invite page

The `invite-pages.yml` workflow builds the browser guest and deploys it to GitHub Pages on `main` (select **GitHub Actions** under repository Settings → Pages). For another HTTPS static host, build the same bundle:

```sh
rustup target add wasm32-unknown-unknown
cargo install wasm-bindgen-cli --version 0.2.130 --locked
python browser/build.py
```

Serve the contents of `target/invite-site/` with `application/wasm` for `.wasm`. Before starting the desktop peer, set `ENGAWA_INVITE_BASE` to the URL of that page (default: `https://yukimemi.github.io/engawa/`). A loopback HTTP URL is also supported for local development. Only the static client is hosted: room discovery, messages and history do not pass through the static site.

For an opt-in end-to-end check, build the native binary and site, install Python Playwright and its WebKit engine, then run `python tests/browser_invite.py target/debug/engawa` (`.exe` on Windows). It uses a temporary profile, an actual HTTPS iroh relay, and a phone-sized WebKit browser. It does not announce the test room to the public lobby.

## What survives when everyone leaves?

Built-in rooms always appear in the lobby. Other rooms are announced by their participants. An activity indicator means a peer was seen recently, not that an exact number of people are online.

- **Live only:** The client keeps messages in memory while you're in the room and discards them when you leave.
- **With history:** Each peer keeps up to 200 posts per room from the last seven days in a local SQLite database. Returning peers exchange history. A newcomer can't fetch a conversation from a peer that's offline. Data that expires while the app is closed is pruned when it runs again.

The history policy is part of the room ID. Two rooms can share a display name without sharing messages. Withdrawing your own post sends a signed removal notice; it can't erase screenshots, backups, or copies kept by other clients.

The default profile lives under `engawa` in your OS's local application data directory. Use `engawa --data-dir <directory> web` or set `ENGAWA_DATA_DIR` to choose another profile. Use separate directories for independent peers.

## Network and privacy

Engawa discovers lobby peers through the Mainline DHT with `distributed-topic-tracker`, connects over iroh, and uses `iroh-gossip` for room announcements and messages. Chat logs are not published to the DHT. Networks that block UDP may prevent public peer discovery.

No account or real name is required. Rooms are public: participants can read and record their contents. Encrypted transport does **not** hide your IP address from a direct peer, and the local database is not encrypted.

## Connect another editor

Start `engawa serve --stdio` as a child process. Read one line of JSON from stdout: `{"url":"http://127.0.0.1:<port>","token":"…"}`. Keep stdin open for the session; closing it stops the child. The API listens only on a randomly assigned loopback port. Send `Authorization: Bearer <token>` with each request.

| Method | Path | Request or response |
|---|---|---|
| GET | `/api/state` | Poll for `rooms`, `room` (current ID or null), `messages`, and `status`. |
| POST | `/api/rooms` | `{"name":"Tea room","history":true}` — create and enter. |
| POST | `/api/join` | `{"id":"<room id>"}` |
| POST | `/api/leave` | `{}` |
| POST | `/api/send` | `{"text":"Hello"}` |
| POST | `/api/retract` | `{"id":"<your message id>"}` |

Use `Content-Type: application/json` for POST requests. A successful action returns `204 No Content`; it is not a delivery receipt.

## Run the checks

```sh
cargo test --bin engawa
cargo build --bin engawa
python tests/peers.py target/debug/engawa
```

On Windows, pass `target/debug/engawa.exe`. The integration test uses temporary profiles and ephemeral ports, without posting to the public lobby. Leave `ENGAWA_PEER` unset for normal discovery, set it to an empty string for a loopback seed, or set it to `<endpoint-id>@127.0.0.1:<port>` to connect to that seed.