← Back to SKILL.md1#!/usr/bin/env bash2 3set -euo pipefail4 5usage() {6 echo "Usage: $0 <ios|android> <device-id> <server-port> <base-dir> [url-scheme]" >&27 exit 28}9 10[[ $# -ge 4 && $# -le 5 ]] || usage11 12platform="$1"13device_id="$2"14server_port="$3"15base_dir="$4"16url_scheme="${5:-t3code-dev}"17 18case "$platform" in19 ios)20 mobile_origin="http://127.0.0.1:${server_port}"21 ;;22 android)23 mobile_origin="http://10.0.2.2:${server_port}"24 ;;25 *)26 usage27 ;;28esac29 30repo_root="$(git rev-parse --show-toplevel)"31cd "$repo_root"32 33if ! pairing_output="$({34 T3CODE_PORT="$server_port" node apps/server/src/bin.ts auth pairing create \35 --base-dir "$base_dir" \36 --base-url "$mobile_origin" \37 --ttl 15m \38 --label "agent-mobile-${device_id:0:8}"39} 2>&1)"; then40 echo "Could not mint a mobile pairing credential." >&241 exit 142fi43 44pairing_url="$(printf '%s\n' "$pairing_output" | sed -n 's/^Pair URL: //p' | tail -n 1)"45if [[ -z "$pairing_url" ]]; then46 echo "Could not parse the mobile pairing URL." >&247 exit 148fi49 50deep_link="$(PAIRING_URL="$pairing_url" URL_SCHEME="$url_scheme" node - <<'NODE'51const query = new URLSearchParams({52 pairingUrl: process.env.PAIRING_URL,53 autoConnect: "1",54});55process.stdout.write(`${process.env.URL_SCHEME}://connections/new?${query}`);56NODE57)"58 59case "$platform" in60 ios)61 xcrun simctl openurl "$device_id" "$deep_link"62 ;;63 android)64 # adb shell re-joins its arguments and evaluates them through the device65 # shell, so the deep link's `?`/`&` must be quoted once more for that shell.66 adb -s "$device_id" shell \67 "am start -W -a android.intent.action.VIEW -d '$deep_link' com.t3tools.t3code.dev" \68 >/dev/null69 ;;70esac71 72echo "Opened the existing Add Environment route with a fresh pairing credential."73