Files
airc/AGENTS.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

3.6 KiB

Agent Notes

This repo is an AI remote control for viewing and controlling a laptop tmux session from a browser or Android. It's open-sourced under MIT but stays lean — prefer small, direct changes over framework-y abstractions.

Start Here

ai/ is a curated, grep-friendly index of repo-specific ground truth — read it before greping from scratch, and add to it when you learn something non-obvious:

  • ai/glossary.md — easily-confused vocabulary, one TERM :: definition per line.
  • ai/where-to-look.md — task :: path pointers for "to do X, start in Y".
  • ai/gotchas.md — silent-failure and version-fragile knowledge (auth, tmux capture, the attention scanner, anything that logs).

Code wins on conflict: if a fact there is stale, fix the file.

Architecture

  • Laptop server: dependency-light Node code in src/.
  • Android client: native Kotlin project in android-app/.
  • Operational wrapper: tools/airc.
  • Browser viewer/static terminal assets: public/.

Important behavior:

  • Airc defaults to port 8080.
  • tools/airc local prepends --host 0.0.0.0 --no-tunnels.
  • Pairing payloads in local mode should prefer LAN URLs over 127.0.0.1.
  • Auth uses viewToken and controlToken; permissions come from the token.
  • Browser UI reads canControl from /api/config; the backend still enforces /api/tmux/input with the control token.
  • tools/airc pair-app prints Android JSON with the control token.
  • tools/airc pair-web prints a browser URL with the view token.
  • tools/airc pair-web-control prints a browser URL with the control token.
  • The Android app stores LAN and public URLs, tries LAN first, and falls back to the public/tunnel URL.
  • Tunnels are configured under tunnels in config.json (ngrok, tailscale, external), each with its own enabled flag; tunnels.prefer decides which one is advertised. Only ngrok is supervised by airc. Legacy top-level ngrok and publicUrl keys still load.
  • The app follows the active pane unless the user pins a pane.
  • Browser controls follow the currently viewed pane.
  • Text input goes through tmux send-keys -l; named quick keys go through tmux send-keys.
  • Optional voice dictation (dais.enabled, off by default) hands the viewed pane to the local dais daemon over its Unix socket; enabling it lets the control token open the laptop's microphone, so treat that config key as a security decision. See docs/dais.md.
  • Tmux grid size is the main readability lever. The app-side A-/A+ controls only adjust local rendering.
  • Tesla/browser access should use ngrok/public URLs; local private LAN access from Tesla was unreliable in testing.

Build And Test

Use the repo-root Makefile (make help lists targets); make push/deploy rebuild only when sources changed:

make check                  # npm run check (eslint + node --check); needs Node >= 20.19 for eslint
make build                  # cd android-app && ./gradlew assembleDebug
make push                   # rebuild if needed, then adb install -r

Or the raw equivalents:

npm run check
cd android-app && ./gradlew --no-daemon assembleDebug

Android SDK/tooling is expected under ~/android; android-app/local.properties is intentionally ignored and may point to the local SDK.

When using adb from this environment, sandboxed commands may fail to start the adb daemon. Rerun adb commands with escalation when needed.

Git Hygiene

Do not commit runtime or machine-local files:

  • config.json
  • .airc-server.*
  • node_modules/
  • android-app/local.properties
  • Android/Gradle build directories

Before committing, check git status --short and keep commits focused.