Files
airc/docs/operations.md
Tommi Kyntola a111823bfc Give every tunnel its own switch, and put ngrok first
Tailscale Funnel has been the flaky one here: the public *.ts.net path goes
dead while every local tailscale check stays green, and it takes the advertised
URL down with it. ngrok has never done that. But `publicUrl` — one string,
outranking ngrok by construction — left no way to lean on ngrok without
deleting the Funnel URL, and no place to park a third tunnel while trying it
out.

So tunnels become a group, one entry each with its own `enabled` flag:

  "tunnels": {
    "prefer": ["ngrok", "tailscale", "external"],
    "ngrok":     { "enabled": false, "domain": ..., "binary": ..., "apiUrl": ... },
    "tailscale": { "enabled": false, "url": "" },
    "external":  { "enabled": false, "url": "" }
  }

`prefer` is precedence, not exclusivity. Every enabled tunnel still reaches the
server; the first one that can name a URL is merely what gets baked into
bookmarks, the pairing QR and /api/config. Swapping the advertised route is a
reorder of that list plus a restart, with the losing tunnel left configured and
live as a spare. `external` is the slot for whatever comes next — Cloudflare, a
reverse proxy — without another schema change. A partial `prefer` ranks the
rest last rather than hiding them; an unknown name in it is a load error, since
a typo there would otherwise silently re-point the advertised URL.

Only ngrok is supervised, as before: `tailscale` and `external` are URLs airc
advertises for tunnels somebody else keeps up, which is all `publicUrl` ever
was. Because a reserved ngrok domain is knowable before the agent is up, it is
now advertised from the first request instead of after the agent reports; the
live URL replaces it when it lands (the two differ only without a reserved
domain), and both paths log through one announce().

`--no-ngrok` now means only what it says — skip the agent, let the next tunnel
down the list take over. `--no-tunnels` is new and means LAN/loopback only;
`tools/airc local` and `npm run dev` use it, which is what keeps local mode
preferring a LAN URL in pairing payloads now that disabling ngrok no longer
implies disabling everything. /healthz and /api/status gained a `tunnels` block
listing the routes in preference order with the advertised one named, and
`tools/airc status` prints that name next to the URL.

Old configs load untouched: a top-level `ngrok` block becomes `tunnels.ngrok`,
a top-level `publicUrl` becomes `tunnels.external.url`, and a file still in
that shape keeps its old precedence — publicUrl over ngrok — so pulling this
cannot silently re-point an existing pairing at a different tunnel. Only a
config that opts into `tunnels` gets the new ngrok-first default.

test/tunnels.test.js covers the ordering, both migration paths and the two
flags. Checked live against both orderings on a scratch port before restarting
the real server; with ngrok advertised, both it and the still-enabled Funnel
answer 200. Worth naming the cost: ngrok's free-tier interstitial does not
render in the Tesla browser, so the car keeps its ts.net bookmark, which works
precisely because a demoted tunnel stays up.
2026-08-26 13:09:57 +03:00

7.9 KiB

Operations

Running

A tmux session must already exist — any name will do, since Airc follows every live session unless told otherwise:

tmux new -s main

Start local same-WLAN mode (the default, no accounts needed):

tools/airc local
tools/airc pair-app

Start configured ngrok mode (requires ngrok setup — see INSTALLATION.md):

tools/airc on
tools/airc pair-web

Narrow the scope with --session NAME (repeatable) when you want Airc to see only some sessions — for example tools/airc local --session work --session ops.

tools/airc local prepends --host 0.0.0.0 --no-tunnels, so no tunnel is advertised even when one is configured. Use tools/airc on when the configured tunnels should be used (and the ngrok agent started by the server); every tunnel ships disabled, so on is a no-tunnel local run until you enable one.

Which tunnel gets advertised is tunnels.prefer, best first — the rest stay reachable, just not what bookmarks and pairing payloads point at. tools/airc status names the winner in its public: column. Flipping the preference is a prefer reorder plus a restart; --no-ngrok drops just the ngrok agent and lets the next tunnel down the list take over.

To serve both LAN and a tunnel at once (so a phone uses a direct LAN connection at home and the tunnel away), the server must bind a non-loopback address while the tunnel stays enabled. host defaults to 127.0.0.1, which only a tunnel can reach (it dials localhost on the laptop) — the LAN interface is left unbound, so same-WLAN phones get connection-refused. Set "host": "0.0.0.0" in config.json (or pass --host 0.0.0.0 to tools/airc on) so the LAN interface is bound too. Verify the bind with ss -tlnp | grep 8080: it should show 0.0.0.0:8080, not 127.0.0.1:8080.

Common commands:

tools/airc status
tools/airc off
tools/airc logs

Runtime state is written to ignored files:

  • .airc-server.pid
  • .airc-server.json
  • .airc-server.log

Airc does not currently install or use a systemd unit. The wrapper starts a detached Node process and manages it through those state files.

Pairing

Pairing commands print QR codes plus manual values:

  • tools/airc pair-app: Android JSON with the control token, preferred URL, public URL, and LAN URLs.
  • tools/airc pair-web: browser QR/URL/token with the view token.
  • tools/airc pair-web-control: browser QR/URL/token with the control token.

tools/airc pair remains an alias for pair-app. The Android app stores the profile after QR scan or manual entry.

Re-pair after changing:

  • server URL
  • server port
  • viewToken or controlToken

Airc stores separate viewToken and controlToken values. The view token can only load the terminal viewer. The control token can also send text and quick keys. The browser viewer shows input controls only when opened with the control token.

In local mode, QR payloads should use a LAN URL such as http://10.x.x.x:8080. If the phone saves 127.0.0.1, re-pair from tools/airc local ...; on Android, 127.0.0.1 means the phone itself.

For Android fallback between LAN and public/tunnel access, pair while the payload contains both URL families. If the app was paired from tools/airc local, it may only know LAN URLs because local mode disables every tunnel.

App Usage

  • The app follows the active tmux pane by default.
  • Tap active to pick or pin a pane. The picker lists only sessions that are currently live; configured sessions that aren't running are omitted.
  • A configured sessions entry may use shell-style globs (* matches any run of characters, ? a single one), so foo* follows every live session whose name starts with foo. Entries without glob characters stay exact matches. The default is ["*"] — every live session — so sessions only needs setting when you want a narrower scope.
  • Type in the bottom field, then tap send or use the keyboard send action.
  • Quick buttons send Up, Down, and Enter.
  • A- and A+ adjust app-side font rendering only; they do not resize tmux.
  • If the pairing payload includes both LAN and public URLs, the app tries LAN first and falls back to the public URL.
  • The app remembers the last successful endpoint. When it is using a public URL, it periodically tries LAN again, so returning to the same network switches back automatically — including while a websocket is actively streaming, by probing the LAN addresses on a background thread and dropping the tunnel once one answers. This only works if the laptop is actually reachable on the LAN (server bound to 0.0.0.0, both devices on a network that doesn't isolate clients); otherwise the public URL keeps carrying the connection.
  • While connected over the public URL, the app also periodically pulls the laptop's current LAN addresses from /api/config and merges them into its stored list. So if the laptop later joins a different network (a new IP the pairing snapshot never had), the app discovers it and switches to a direct LAN connection on its own — no re-pairing needed. This works whenever both devices share a network that does not isolate clients; on guest/AP-isolated networks the public URL continues to carry the connection.

Browser Usage

Use tools/airc pair-web for read-only browser viewing. This is the expected Tesla bookmark flow because Tesla local/private LAN access was unreliable in testing.

Use tools/airc pair-web-control only for trusted browsers. It prints a QR and URL with the control token; it does not open a browser from the CLI. Browser controls send input to the currently viewed pane.

With dais.enabled (off by default), the control bar also gets a 🎙 speak latch that records on the laptop, transcribes locally, and types the text into the viewed pane — you still tap Enter yourself. It greys out when the dais daemon isn't running. See dais.md, including what enabling it does to the control token's reach.

/probe is available after auth for browser diagnostics.

The browser top row shows public tunnel liveness and laptop battery status when available. Frame updates use WebSockets when supported and fall back to polling.

Display Sizing

Tmux grid size is the main readability lever. For Samsung S23 portrait, a tmux size around 58x50 has worked well.

If text is too small:

  1. Reduce tmux rows/columns.
  2. Use A+ for a small local app-side nudge.

If scrolling appears, reduce tmux rows/columns or use A-.

Troubleshooting

  • Another service will not start while Airc is running: Airc defaults to port 8080. Check for old manual runs on the same port.
  • ngrok tunnel does not come up: check tail -f "$(tools/airc logs)". The ngrok free tier allows only one active agent session, so a manually started ngrok can block Airc's supervised child.
  • QR scan is blurry: move the phone farther away until the QR is sharp, or use manual pairing with the printed baseUrl and token.
  • App cannot connect on WLAN: confirm the server is bound to a non-loopback address (ss -tlnp | grep 8080 should show 0.0.0.0:8080; set "host": "0.0.0.0" if it shows 127.0.0.1), and that the phone is on the same network.
  • App stays on ngrok at home and never switches to LAN: watch the app's decisions with adb logcat -s airc:I. A prefer-lan probe ... -> HTTP 200 followed by endpoint switched: means it flipped to LAN; a ConnectException means the server is loopback-bound or a firewall blocks the port, and a SocketTimeoutException means that address is on an unreachable subnet (e.g. a VPN/tun0 IP the laptop also advertises, which is harmless noise).
  • Tesla cannot connect to a LAN URL: use ngrok/public browser pairing. Tesla hotspot-local/private address access failed in earlier tests.
  • ADB install fails with unauthorized: accept the USB debugging prompt on the phone, then rerun adb install -r ....
  • Check server state with tools/airc status.
  • Read logs with tail -f "$(tools/airc logs)".