# attune — tune in to the FRST BBS data crystal.
#
# Thin front end: picks the transport, then hands the deep 9P graft
# (mount + /net/tcp + /n/bbs bind + timesync + onboarding) to the `tunein`
# C builtin.  Doing the walk in one C frame keeps the per-shell zrc stack
# shallow -- L2CAP walks driven from nested rc if-blocks overflow it
# (project_zrc_l2cap_walk_overflow).  `tunein` prints all status/onboarding,
# reads $dc_bind_tcp / $dc_bind_wifi, and binds the BBS at /n/bbs (TCP aetherd
# exports rooms at the crystal root -> /n/dc; L2CAP nodes at /n/dc/srv/bbs).
# Onboarding is one sitting: a fresh caller is offered a key mint (y/n) and a
# handle claim inline, with the redial handled internally -- no second attune.
#
# The DEFAULT transport is build-seeded in $dc_transport by zrc init:
#   web (WASM)  -> tcp : straight to the public crystal over wss
#   deck (ESP32)-> ble : L2CAP scan for a neighbouring crystal/gateway
# $dc_host/$dc_port are seeded build-correct too (bbs.frstcomputer.net;
# 8443 wss on WASM, 9777 plain TCP on native_sim + ESP32).  Override at the
# prompt to point elsewhere.
#
# Usage: attune        default transport ($dc_transport)
#        attune -c     force the public crystal over TCP ($dc_host:$dc_port)
#        attune -b     force BLE L2CAP scan
#        attune -t     force local TCP (localhost:9999, for native_sim)

# Pick the dialstring: build default first, then explicit flags win.
# ('l2cap!?!0' is quoted so the ? isn't glob-expanded in the assignment.)
dial=tcp!$dc_host!$dc_port
if (~ $dc_transport ble) { dial='l2cap!?!0' }
if (~ $1 -b) { dial='l2cap!?!0' }
if (~ $1 -c) { dial=tcp!$dc_host!$dc_port }
if (~ $1 -t) { dial=tcp!localhost!9999 }

echo 'Seeking crystal resonance...'
tunein $dial
