From 82ab91b0efced9de89684abcc3ff2ca42de5e672 Mon Sep 17 00:00:00 2001 From: "Hermes (pixel)" Date: Tue, 27 Oct 2026 01:23:20 +0100 Subject: [PATCH] Skills von pixel: autonomous-ai-agents/hermes-a2a software-development/android-debugging-from-termux software-development/termux-go-builds --- .../autonomous-ai-agents/hermes-a2a/SKILL.md | 124 ++++++++++++++++ .../hermes-a2a/templates/a2a-peer-setup.sh | 52 +++++++ .../android-debugging-from-termux/SKILL.md | 136 ++++++++++++++++++ .../references/tailscale-termux.md | 51 +++++++ .../termux-go-builds/SKILL.md | 111 ++++++++++++++ .../references/tailscale-android.md | 70 +++++++++ .../termux-go-builds/templates/ts-up.sh | 46 ++++++ 7 files changed, 590 insertions(+) create mode 100644 skills/autonomous-ai-agents/hermes-a2a/SKILL.md create mode 100644 skills/autonomous-ai-agents/hermes-a2a/templates/a2a-peer-setup.sh create mode 100644 skills/software-development/android-debugging-from-termux/SKILL.md create mode 100644 skills/software-development/android-debugging-from-termux/references/tailscale-termux.md create mode 100644 skills/software-development/termux-go-builds/SKILL.md create mode 100644 skills/software-development/termux-go-builds/references/tailscale-android.md create mode 100644 skills/software-development/termux-go-builds/templates/ts-up.sh diff --git a/skills/autonomous-ai-agents/hermes-a2a/SKILL.md b/skills/autonomous-ai-agents/hermes-a2a/SKILL.md new file mode 100644 index 0000000..4a5e573 --- /dev/null +++ b/skills/autonomous-ai-agents/hermes-a2a/SKILL.md @@ -0,0 +1,124 @@ +--- +name: hermes-a2a +description: "Connect Hermes agents over A2A: setup, peers, verify." +version: 1 +author: "Hermes Agent" +license: MIT +metadata: + hermes: + tags: [a2a, agents, multi-agent, hermes, tailnet, delegation] + related_skills: [hermes-agent, termux-go-builds] +--- + +# Hermes A2A (Agent-to-Agent) — connecting agents to each other + +A2A is the open Agent2Agent protocol (v1.0) for inter-agent communication. +The Hermes A2A plugin is bidirectional: +- **Inbound**: your Hermes serves an Agent Card + JSON-RPC 2.0 endpoint (port 9900) + → other agents can send you tasks. +- **Outbound**: the `a2a` toolset gives YOUR agent tools to call other agents + (`a2a_discover`, `a2a_call`, `a2a_list`, `a2a_history`, `a2a_orchestrate`). + +Use A2A when crossing process/machine/framework boundaries. For multiple agents +on the SAME machine, prefer `delegate_task` (in-process) or the kanban board. + +Docs: https://hermes-agent.nousresearch.com/docs/user-guide/messaging/a2a + +## When to Use +- The user wants two Hermes agents (or a Hermes agent and any other agent) to talk to each other, send tasks, or chain multi-agent work across machines. +- Setting up or debugging an A2A inbound/outbound connection (port 9900, bearer token, peer registration). +- Deciding between in-process `delegate_task`/kanban (same machine) vs A2A (crosses process/machine/framework boundaries). +- Verifying that an A2A peer is actually reachable and answering, not just showing up in `tailscale status`. + +## Quick setup (verified 2026-10-23) + +1. **Enable the platform + toolsets:** + ```bash + hermes config set gateway.platforms.a2a.enabled true + hermes tools enable a2a --platform cli + hermes tools enable a2a --platform a2a # lets inbound tasks call peers (agent chaining) + ``` +2. **Tokens & bind (in `~/.hermes/.env` — credentials go in .env, never config.yaml).** + Generate a token: `python3 -c "import secrets;print(secrets.token_hex(24))"`. + ``` + A2A_BEARER_TOKEN=<64-hex> + A2A_HOST=0.0.0.0 # widens bind ONLY when a token is set (security invariant) + A2A_PORT=9900 + A2A_PUBLIC_URL=http://.:9900 # routable URL the Agent Card advertises + A2A_AGENT_NAME= + ``` + Security model: **no token ⇒ binds 127.0.0.1 only.** Remote exposure requires a + bearer token AND `A2A_HOST`. Per-peer alt: `A2A_PEER_TOKENS="alice:tok1,bob:tok2"`. +3. **Register peers** (each peer must point at the OTHER's public URL + same token): + ```bash + hermes config set a2a_agents..url "http://.:9900" --force + hermes config set a2a_agents..auth.type bearer --force + hermes config set a2a_agents..auth.token "" --force + ``` +4. **Start the gateway** in its own tmux session (survives session churn): + ```bash + tmux new-session -d -s gateway 'env TERM=xterm hermes gateway run 2>&1 | tee -a ~/.hermes/logs/gateway-run.log' + ``` + +## Verification (do this — don't trust the config) +- Agent Card: `curl -sS http://127.0.0.1:9900/.well-known/agent-card.json` → JSON with `name` and `url`. +- Inbound task: + ```bash + curl -sS -X POST http://127.0.0.1:9900/ -H 'Authorization: Bearer ' \ + -d '{"jsonrpc":"2.0","id":1,"method":"SendMessage","params":{"message":{"messageId":"m1","role":"ROLE_USER","parts":[{"text":"hi"}]}}}' + ``` +- **The audit log is the source of truth**: `~/.hermes/a2a_audit.jsonl` records + inbound/outbound task + reply even when the HTTP response is lost. If you see + an `inbound` and a matching `outbound` line, the round-trip worked. + +## Pitfalls (hit in-session) +- **curl timeout ≠ failure.** A self-test that times out (e.g. `-m 40`) can still + have a COMPLETE audit-log entry (inbound task + outbound reply). Check + `a2a_audit.jsonl` before concluding A2A is broken. A long LLM reply easily + exceeds a short curl timeout; the server logs `BrokenPipeError` after the client + gave up — that is a client-side timeout, not a server failure. +- **Same rule for a client-timed-out `a2a_call` — with one twist.** A client + timeout does not mean the task wasn't delivered: `a2a_list` (outbound count + rose) and the conversation's `a2a_history` prove delivery if your message is + listed there. But unlike the audit-log curl case, the lost reply is usually + LOST — the peer may still finish processing with no one listening for the + answer. If the result matters, follow up with a new call that references the + original task; don't blindly re-send the same text. +- **Peer agents have their own security heuristics.** A peer LLM can refuse a + relayed instruction containing a URL or auth token as "untrusted external + input" (because it arrived from another agent, not the user). Recover by + stating provenance explicitly (direct request from the user, the user's own + service/device) AND re-instructing with a concrete action verb ("call this + endpoint and report the response body") instead of "follow this URL". +- **Set the token BEFORE widening the bind.** `A2A_HOST=0.0.0.0` only widens the + bind when `A2A_BEARER_TOKEN` is set; without the token the server stays on + 127.0.0.1 and remote peers get connection-refused. +- **Peers must be running too.** A node showing in `tailscale status --peers` is + NOT the same as its A2A server being up. Verify each peer's card first: + `curl -m 5 http://.:9900/.well-known/agent-card.json`. +- **Token must match on BOTH sides.** A mismatch does NOT always return HTTP 401 — + verified in-session: the peer answered `HTTP 200` with a JSON-RPC error body + `{"code": -32050, "message": "unauthorized"}`. Treat `-32050 unauthorized` as the + token-mismatch signature (card fetch needs no auth, so a 200 card + -32050 task call = + network fine, auth wrong). +- **`a2a_agents` is a custom top-level key** — `hermes config set` warns "not a + recognized config key"; use `--force`. It works and is read by the plugin. +- **Magic DNS may not exist for the tailnet.** `.` URLs (in + `A2A_PUBLIC_URL`, peer `url`s, and the advertised Agent Card `url`) only resolve + if the control server has Magic DNS enabled for that zone. Symptom that bites: + even your OWN node's advertised URL fails with `curl: (6) Could not resolve + host` — the card is fine, the name just doesn't exist. Fix: enable Magic DNS on + the control server, or switch all references to the CGNAT address + (`tailscale ip -4` → `http://100.x.y.z:9900`) and regenerate `A2A_PUBLIC_URL`. + Diagnosis order when a peer is "unreachable": `curl (6)` = DNS, fix the name; + `curl (7) Failed to connect` = port closed, the peer's A2A server genuinely + isn't running (most common). A node in `tailscale status` does not imply either. + +## Templates +- `templates/a2a-peer-setup.sh` — idempotent per-peer inbound setup (enables the + platform/toolsets, derives the tailnet IP via `tailscale ip -4` so it works + without Magic DNS, sets A2A_* env vars incl. token, self-tests the card). + Run it on EVERY box that must receive A2A tasks. + +## See also +- Tailscale networking that A2A often rides over: see the `termux-go-builds` skill (references/tailscale-android.md there) for Termux/Android bring-up. diff --git a/skills/autonomous-ai-agents/hermes-a2a/templates/a2a-peer-setup.sh b/skills/autonomous-ai-agents/hermes-a2a/templates/a2a-peer-setup.sh new file mode 100644 index 0000000..507f108 --- /dev/null +++ b/skills/autonomous-ai-agents/hermes-a2a/templates/a2a-peer-setup.sh @@ -0,0 +1,52 @@ +#!/usr/bin/env bash +# +# a2a-peer-setup.sh — A2A inbound on a Hermes peer box (verified pattern, 2026-10-23) +# +# Run on EVERY box that must RECEIVE A2A tasks (NAS, RPi, MacBook, …). +# bash a2a-peer-setup.sh [AGENT_NAME] # e.g. bash a2a-peer-setup.sh nas +# +# Requires on the box: hermes (+ A2A plugin) and tailscaled in the same tailnet. +# Magic DNS NOT required — the published URL is the box's 100.x CGNAT address. +# +set -euo pipefail + +NAME="${1:-peer}" +PORT="${A2A_PORT:-9900}" +TOK="${A2A_BEARER_TOKEN:?run with A2A_BEARER_TOKEN= to avoid editing this file}" +ENVF="${HERMES_HOME:-$HOME/.hermes}/.env" + +echo "→ enabling A2A platform + toolsets (agent_name=$NAME, port=$PORT)" +hermes config set gateway.platforms.a2a.enabled true >/dev/null 2>&1 || true +hermes tools enable a2a --platform a2a >/dev/null 2>&1 || true +hermes tools enable a2a --platform cli >/dev/null 2>&1 || true + +# Tailnet IP (works without Magic DNS); first 100.x interface as fallback +TS_CLI="$(command -v tailscale || echo tailscale)" +TS_IP="$("$TS_CLI" ip -4 2>/dev/null || true)" +[ -z "${TS_IP:-}" ] && TS_IP="$(ip -4 -o addr 2>/dev/null | awk '{print $4}' | cut -d/ -f1 | awk -F. '$1==100{print; exit}')" +[ -z "${TS_IP:-}" ] && { echo "✗ no tailnet IP found — is tailscaled running and logged in?"; exit 1; } +PUBLIC_URL="http://${TS_IP}:${PORT}" + +# ~/.hermes/.env — idempotent upsert (never duplicate keys) +mkdir -p "$(dirname "$ENVF")"; [ -f "$ENVF" ] || : > "$ENVF" +set_var() { # key value + if grep -qE "^$1=" "$ENVF" 2>/dev/null; then + sed -i.bak "s#^$1=.*#$1=$2#" "$ENVF" && rm -f "$ENVF.bak" + else + printf '%s=%s\n' "$1" "$2" >> "$ENVF" + fi +} +set_var A2A_HOST "0.0.0.0" +set_var A2A_PORT "$PORT" +set_var A2A_PUBLIC_URL "$PUBLIC_URL" +set_var A2A_AGENT_NAME "$NAME" +set_var A2A_BEARER_TOKEN "$TOK" + +echo "→ done. Public URL: $PUBLIC_URL" +echo "→ start (or restart) the gateway in its own tmux session:" +echo " tmux new -d -s gateway 'env TERM=xterm hermes gateway run 2>&1 | tee -a ~/.hermes/logs/gw.log'" +echo "→ verify (from inside the box): curl -sS ${PUBLIC_URL}/.well-known/agent-card.json | head -c 200" +echo "→ verify from ANOTHER tailnet box: curl -sS ${PUBLIC_URL}/.well-known/agent-card.json" +echo +echo "NOTE: other peers must now point their a2a_agents..url at ${PUBLIC_URL}" +echo " (CGNAT-IP form) if their tailnet has no Magic DNS for the old name." diff --git a/skills/software-development/android-debugging-from-termux/SKILL.md b/skills/software-development/android-debugging-from-termux/SKILL.md new file mode 100644 index 0000000..e0c4bf3 --- /dev/null +++ b/skills/software-development/android-debugging-from-termux/SKILL.md @@ -0,0 +1,136 @@ +--- +name: android-debugging-from-termux +description: Debug an Android device from Termux running on the device. +version: 1 +author: hermes +license: MIT +metadata: + hermes: + tags: [android, termux, adb, grapheneos, debugging, sync, contacts, tailscale, networking] + related_skills: [systematic-debugging] +--- + +# Android debugging from Termux (on-device terminal) + +## When to Use + +- The user asks to debug, sync-fix, or inspect an Android phone, AND the agent's terminal already runs ON that same phone (Termux, non-root). +- The agent needs to reach a peer Android device over LAN (adb over WLAN / wireless debugging from a non-root context). +- Permission denial patterns are blocking diagnosis from Termux: `Permission Denial … DUMP`, `/bin/sh: cannot execute`, empty `dumpsys`/`settings`/`cmd account` output. + +Skip this skill when: the terminal is on a separate host and the phone is already attached via USB (plain `adb shell` flow), or the device is rooted (most of §1 does not apply). + +Key context that is easy to get wrong: +- The shell is a normal app uid (e.g. `u0_a227`), NOT root. +- GrapheneOS hardening blocks the privileged CLI subset even where stock Android would allow it. +- Termux symlinks `/system/bin/sh` to `/bin/sh` in its PATH, and `/bin/sh` doesn't + exist — any tool that needs `sh` (most Java-based `app_process` wrappers: `content`, + `cmd` on some builds) silently fails with "cannot execute: required file not found". +- `logcat` works fine via absolute path. + +## Tailscale / tailnet connectivity +- Non-root Termux tailscaled usually runs `--tun=userspace-networking` → proxy-only (SOCKS5/HTTP on localhost); stock Android browsers don't use local proxies, so browser access to tailnet names needs the official Tailscale app (real VpnService) or a TUN-capable proxy client. +- Full playbook (daemon cmdline, CLI socket trap, MagicDNS name verification, probe-by-name-vs-IP ladder, peer-vs-public reachability): `references/tailscale-termux.md`. + +## 1. Which /system/bin tools actually work from a non-root app + +| Tool | Status on GrapheneOS (no root) | Notes | +| --- | --- | --- | +| `/system/bin/logcat` | ✅ works | use `-v time`, `-b events\|crash\|system` for coverage | +| `/system/bin/pm list packages` | ✅ works | package inventory only | +| `/system/bin/input` | ✅ works | tap/swipe for UI automation | +| `/system/bin/cmd account list` | ⚠️ often empty | AccountManager refuses listing to unprivileged callers | +| `/system/bin/dumpsys` | ❌ DENIED | `Permission Denial … missing android.permission.DUMP` | +| `/system/bin/settings list` | ❌ often empty | secure/global/system reads require perms | +| `/system/bin/content query` | ❌ broken via `/bin/sh` | fix: call `app_process /system/bin com.android.commands.content.Content …` with `CLASSPATH=/system/framework/content.jar`, but READ_CONTACTS still required | +| `adb` (client) | ✅ works | client is fine; target server is what you connect to | + +Rule: use ABSOLUTE paths for any /system/bin tool. The Termux PATH is a lie. + +## 2. Live log-capture recipe that actually works + +```bash +LOG=$HOME/sync_capture.log # $HOME, never /root (blocked) +/system/bin/logcat -c # clear old noise +# then background: +/system/bin/logcat -v time > "$LOG" 2>&1 & +``` + +- Start BEFORE the user triggers the action you want to observe + (manual sync, opening Contacts, dialing) — logcat ring buffer is small + (≈512 KiB/main) and rotates fast on a busy phone. +- **SELinux audit lines from Termux itself will dominate** (`avc: denied … app=com.termux + …`). Filter with `grep -ivE 'avc:|audit'`. +- Third-party app classes (DAVx5 `at.bitfire.davdroid`, Nextcloud, etc.) are + loggable, but only for a few seconds before rotation; combine a narrow + `grep -i "davx5\|carddav"` filter with a fast post-hoc pass. +- If an "expected sync" produces **zero** matching lines in a capture that spans + the user's action, the app either wasn't running (`ps -A | grep -i bitfire`) or + its log level is below the buffer window — that's data, act on it. + +## 3. Contacts/phone/sms inconsistency — diagnosis ladder + +**Symptom:** same person shows different name/number in Phone vs SMS vs Contacts app, +or a newly created contact won't "stick." + +**Common root cause (verify, don't assume):** after a GrapheneOS-Backup-Tool restore +into a device that also syncs via DAVx5/Nextcloud, the restored contacts live +**outside** the DAV account (Storage = "local" / none), while +newly-created ones enter DAVx5's provider. Two records for one number → the +Phone/SMS apps pick one record for display, Contacts shows both → apparent "not +synced." + +Ladder of checks, cheapest first: +1. **Nextcloud web UI** (user's browser, NOT the phone): + - Is there exactly ONE record for the person? + - What number format does it show (E.164 `+49…` vs local `0…`)? + - Does the record have a storage/label marker for "DAVx5"? +2. **On the device** (once we have a privileged path — see §4): + ``` + content query --uri content://com.android.contacts/raw_contacts \ + --projection raw_id:account_type:account_name + content query --uri content://com.android.contacts/data \ + --projection data1:data2:mimetype --where "mimetype='vnd.android.cursor.item/phone_v2'" + ``` + Look for two `raw_contacts` rows whose `data1` values are numerically equal + after stripping `+`/`0`. +3. **Merge fix** (once identified): + - In Nextcloud web **or** the Contacts app: merge the local dup into the DAV one. + - Force a reindex: Settings → Apps → Contacts → Storage → "Clear cache" (safe — it + just rebuilds the lookup table, does NOT delete contacts). + - Confirm with `adb shell dumpsys contacts | grep -A2 "lookup"` that the + target number now maps to the DAV-owned row id. + +Do NOT do: "wipe the Contacts app data" as a first fix. That destroys the +local-side dup (usually your pre-migration contacts) — only do it after you've +confirmed the dup is recoverable from Nextcloud. + +## 4. Reaching the phone from your terminal — adb-over-WLAN vs local ADB + +**Prefer local ADB when the terminal is on the same device (try FIRST — not verified in the originating session, so treat as a best-effort option):** +1. Phone UI: Settings → System → Developer options → **Local ADB** ON. +2. Termux: `adb devices` → device may appear as `emulator-…` or `localhost:…`. +3. This sidesteps the entire wireless-pairing dance (codes, expiring ports, TLS). + If it doesn't appear, fall back to wireless debugging (§4b) or give the user + the Nextcloud-web diagnosis path (§3.1) instead of burning more pairing attempts. + +**Wireless debugging (Settings → Developer options → Wireless debugging):** +- GUI shows a PAIR port (one-time, ephemeral) and a SESSION port (persistent). +- Flow: `adb pair HOST:PAIRPORT <6-digit-code>` then `adb connect HOST:SESSIONPORT`. +- Codes are **one-shot and short-lived** (~1 min). A second attempt with the same + code fails even if the first "failed" — user must open the GUI to regenerate. +- Termux's `adb` (android-tools build) accepts the pairing code as an argument — + `adb pair 192.168.x.y:42805 290347` (see `strings $(which adb)` → `pair HOST[:PORT] [PAIRING CODE]`) — + this avoids the PTY/expect fragility, BUT note that in the originating session BOTH + interactive-PTY and arg-based pairing hit the same `protocol fault` error, so the + code was the likely culprit, not the input method. +- Failure mode we hit: `error: protocol fault (couldn't read status message): Success` + with the pair port closing after code entry and the session port staying open + but `adb connect` failing → root cause is most likely a stale/already-used code + (codes are one-shot, ~1 min TTL) or server-side rate limiting after failed attempts. + **Get a FRESH code+port from the phone GUI, re-pair within ~30 s, then connect. + A fresh code has not been verified as working in the originating session.** +- Sanity checks before suspecting the client: + - `nc -z -w2 HOST PAIRPORT` — closed = code was consumed (good sign), open = GUI still showing (expected) + - `nc -z -w2 HOST SESSIONPORT` — must stay open + - `adb version` — verify android-tools build ≥ 35; older versions had TLS issues with Android 13+ pairing diff --git a/skills/software-development/android-debugging-from-termux/references/tailscale-termux.md b/skills/software-development/android-debugging-from-termux/references/tailscale-termux.md new file mode 100644 index 0000000..e400b3e --- /dev/null +++ b/skills/software-development/android-debugging-from-termux/references/tailscale-termux.md @@ -0,0 +1,51 @@ +# Tailscale / tailnet debugging from Termux (non-root) + +Use when the user can't reach a tailnet service (browser, curl, ssh) from the phone and tailscaled runs as a Termux app rather than the official Android app. + +## 0. Establish how tailscaled actually runs (before any fix) +```bash +ps -ef | grep tailscaled +cat /proc//cmdline | tr '\0' ' ' +``` +- `--tun=userspace-networking` means the daemon can only offer a local SOCKS5/HTTP proxy (address in `--socks5-server=…`); there is NO device-wide VPN and NO system-DNS interception. Expect stock App-level tailnet access to fail in this mode — the fix is a real VPN path (official Tailscale app) or a TUN-capable proxy client, not curl flags. +- `--socket=` in the cmdline is the source of truth for where the daemon listens; it is often NOT the path the CLI dials by default. + +## 1. Wire the CLI to the running daemon (socket-mismatch trap) +CLI keeps erroring `dial unix $PREFIX/tmp/tailscaled.sock: no such file or directory` even though tailscaled is running → it is dialing its default path, not the daemon's socket. Some Termux CLI builds ignore `TS_SOCKET`/`TAILSCALE_SOCKET` and keep using the default; stop chasing env vars and use the symlink, which verified works: +```bash +ln -sF /data/data/com.termux/files/usr/tmp/tailscaled.sock +tailscale status # must now list peers +``` + +## 2. Verify the NAME before blaming the tunnel +```bash +tailscale status # peer hostnames + 100.64/10 IPs + live state +tailscale status --json | python3 -c 'import sys,json; d=json.load(sys.stdin); print(d["Self"]["DNSName"]; [ (k,v["Hostname"]) for k,v in d["Peers"].items() ]') +``` +- MagicDNS peer name form is `.ts.` — `Self.DNSName` shows the exact form, don't guess it. +- If the user's typed name isn't a peer (e.g. missing the `.ts.` part), it is very likely a PUBLIC DNS name that just shares the domain. Cross-check with the system resolver (`getent hosts X`, plain `ping X`): if it lands on a non-100.x IP, the traffic was never tailnet traffic — diagnose it as an ordinary web service (redirects, TLS, auth) instead of tunneling. + +## 3. Probe reachability through the daemon (works even in userspace mode, no TUN needed) +```bash +# remote-DNS variant (socks5h) makes tailscaled resolve AND route the name; +# -sv to capture the discriminating line + curl --socks5-hostname 127.0.0.1: -sv -o /dev/null --max-time 6 \ + http://:/ 2>&1 | grep -iE 'trying|opened|socks|refused|timed|connect' +``` +Isolation ladder, cheapest first: +1. **Baseline control**: any public host/IP (e.g. `socks5h://1.1.1.1:443`). FAILs → the proxy itself is down (check the socks port from cmdline is listening) — stop, this is not a peer problem. +2. **Peer by name**: `cannot complete SOCKS5 connection … (1)` while control passed → name or peer path. +3. **Peer by raw 100.x IP** at the same port AND at ports that are usually open (22): + - still failing → the peer/tunnel path itself is broken (wireguard or user-space forwarding), not DNS and not port choice. Do NOT keep guessing ports. Check the peer's live state in `tailscale status` (active vs idle, tx/rx), re-`up`/re-auth, or fall back to the official app for app-level access. + - passing, name failing → DNS record/naming problem, or the service genuinely isn't listening on the guessed port. +4. **Refused vs timeout**: `connection refused` = peer reachable, no listener on that port (harmless — try another port). Timeout or SOCKS-level failure = no route. + +## 4. Browser access (stock Chrome on Android) +- Stock Chrome on Android cannot be pointed at a local SOCKS5/HTTP proxy. In userspace-daemon mode, "open in Chrome" fails by design — say so directly instead of re-probing. +- Clean fix: install the official Tailscale app (Play Store / F-Droid), log into the same tailnet → device-wide VPN + DNS. Then the correct `.ts.:` opens in Chrome with no extra config. +- Proxy-only fallback: a SOCKS-capable browser (e.g. Kiwi) or a TUN-mode proxy client (NekoBox/KitsuneBI) importing `socks5 127.0.0.1:`. + +## Anti-patterns +- Don't conclude "Tailscale is broken" from a single failed name: verify name validity (§2) and baseline control (§3.1) first — the name may simply not be tailnet traffic. +- Don't blame DNS when the raw-100.x-IP probe also fails — that's a routing/peer problem. +- Don't present a proxy-only (userspace) setup as an app-level workaround: it cannot intercept stock browser traffic, ever. diff --git a/skills/software-development/termux-go-builds/SKILL.md b/skills/software-development/termux-go-builds/SKILL.md new file mode 100644 index 0000000..7d000f8 --- /dev/null +++ b/skills/software-development/termux-go-builds/SKILL.md @@ -0,0 +1,111 @@ +--- +name: termux-go-builds +description: "Build Go software from source on Termux." +version: 1 +author: hermes +license: MIT +metadata: + hermes: + tags: [termux, android, go, build, tailscale, network, from-source] + related_skills: [android-debugging-from-termux] +--- + +# Building Go software from source on Termux (Android) + +## When to Use +- User asks to install software on an Android/Termux box and `pkg` has no package (`pkg search` misses, or the package is glibc-only like most network daemons). +- The target is a Go program (Tailscale, most CLI tooling, local LLM proxies, etc.). Go compiles cleanly for `android/arm64` inside Termux — this is the reliable path where a `.deb` install isn't. + +Skip when: `pkg install ` works (always try that first — it's a minute vs. ten). + +## Verified workflow (Tailscale v1.104.2, 2026-10-23) + +1. **Check the package manager first**, then set up the toolchain: + ``` + pkg search tailscale # -> "Unable to locate package" is normal for these + pkg install -y golang # Go 1.27.3, targets `android/arm64` out of the box + ``` +2. **Shallow-clone the exact release tag** (full repo is huge; use latest from GitHub API): + ``` + curl -s https://api.github.com/repos/tailscale/tailscale/releases/latest | grep -m1 tag_name + git clone --depth 1 --branch v1.104.2 https://github.com/tailscale/tailscale.git src + ``` +3. **Build with CGO OFF** — Termux links against bionic, not glibc; static builds are the only sane target: + ``` + CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -o tailscale ./cmd/tailscale + ``` + +## Build-tag pitfalls (the part you will not guess) + +Go projects pin desktop-only deps behind platform tags; Android trips them both ways: + +- **Desktop systray deps** (`fyne.io/systray`) fail with `undefined: nativeLoop` etc. + because the native files are linux/darwin-only. Tailscale's official escape hatch: + `-tags ts_omit_systray` (see `cmd/tailscale/cli/systray_omit.go`: build tag `!linux || ts_omit_systray`). +- **Android-excluded features**: `tailscale.com/feature/ssh` is `linux && !android` and is + imported by `cmd/tailscaled/ssh.go` — fails with "build constraints exclude all Go files". + Official hatch: `-tags ts_omit_ssh`. +- **Taildrop extension**: `-tags ts_omit_taildrop` exists (condregister `maybe_taildrop.go`) + and is also part of the verified daemon build; drop Taildrop if profiles are not needed, or + if the daemon SIGSEGVs inside `taildrop.(*Extension).onChangeProfile` on profile changes. +- **General rule**: when a build dies on "undefined: X" from a desktop dep, or on + "build constraints exclude all Go files", grep the project for its `ts_omit_*` / `*_omit` + build tags and `go:build` constraints around the failing import — projects ship + first-class omit tags for exactly these cross-OS gaps. Don't fork code or edit build tags + by hand; use the project's own. + +``` +CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -tags ts_omit_systray -o tailscale ./cmd/tailscale +CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -tags ts_omit_ssh,ts_omit_taildrop -o tailscaled ./cmd/tailscaled +``` + +Note: `ts_omit_taildrop` is optional but recommended — the daemon SIGSEGV'd inside +`taildrop.(*Extension).onChangeProfile` on profile change (see pitfalls); omitting +Taildrop removes that crash path. + +## Install into Termux's PATH +Termux's real prefix bin is `$PREFIX/bin` (`/data/data/com.termux/files/usr/bin`): +``` +ln -sf $HOME/ts-build/tailscale $PREFIX/bin/tailscale +ln -sf $HOME/ts-build/tailscaled $PREFIX/bin/tailscaled +``` +Verify with `tailscale --version` and `tailscale --help` (daemon binaries run `--version` fine standalone). + +## Android runtime caveats for network daemons +- **No TUN without root**: run userspace networking (`--tun=userspace-networking` on tailscaled) and + expose traffic via local SOCKS5/HTTP proxy + SSH; it is NOT a system-wide VPN — other apps only + see the mesh if routed through those local listeners. Say so to the user, don't let them believe + a TUN is up. +- **How to actually REACH 100.x peers from this box (verified):** direct + `/dev/tcp/100.x.y.z/PORT` and plain HTTP to 100.x addresses **time out** — without TUN there is + no local route into the mesh. The way in is tailscaled's local listener: + - `curl --socks5 127.0.0.1:1055 http://100.64.0.x:PORT/…` ✅ (verified reaching a peer's + Hermes A2A server on :9900, HTTP 200) + - SSH: `-o ProxyCommand='ncat --proxy 127.0.0.1:1055 --proxy-type socks5 %h %p'` — note + **`ncat` (Go nmap), NOT `nc`**: the classic `nc -X 5 -x host:port` syntax errors out on + Termux's ncat. + - `tailscale ping <100.x>` works as a first reachability check (verified: pong in 9–56ms). + - Tailnet **host** names (`macbook-robert`) don't resolve from local curl — use the 100.x + CNI IP (or enable Magic DNS at the control server). + - What's open on a peer is up to that peer: a closed port times out either way. A2A (:9900) + may be the only open service on a Hermes-agent box. +- **Process lifetime = Termux lifetime**: a `nohup`-ed daemon dies when the user kills Termux. + Recommend Termux wake-lock + keeping the session. +- **Custom socket paths**: when tailscaled runs with `--socket `, the CLI needs + `TAILSCALE_SOCKET=` exported before CLI calls (or `--socket ` on the CLI), or + `tailscale status` says "it doesn't appear to be running". +- **`--state` is a FILE, `--statedir` is a DIRECTORY.** Starting the daemon with + `--state=` (a directory) makes the CLI's `up` fail with + `500 … state store is unhealthy`. Use `--statedir=` (it creates `/tailscaled.state`) + or `--state=`. Verified both ways in-session. +- **No `--logdir` flag** in the Android/user tailscaled build — running it with `--logdir=…` + hard-exits with `flag provided but not defined: -logdir` (then dumps usage). Logs go to stdout. +- **Launching the daemon from Hermes:** the terminal tool rejects shell-level `nohup … &` wrappers. + Start `tailscaled` via the tool's `background=true` (read its stdout with `process` poll/log), then + run `tailscale up` in a separate foreground call. (`nohup … &` is only for a raw human shell.) +- **Custom login server + hostname:** `tailscale up --login-server=https:// --hostname=` + prints a `…/register/hskey-authreq-…` URL for browser auth (verified reached the control server). + +## References & templates +- `references/tailscale-android.md` — the complete verified Tailscale recipe: exact commands, flag list, state-dir layout, what is verified vs best-effort. +- `templates/ts-up.sh` — daemon start + connect helper (copy, adjust paths, feed the user's auth key). diff --git a/skills/software-development/termux-go-builds/references/tailscale-android.md b/skills/software-development/termux-go-builds/references/tailscale-android.md new file mode 100644 index 0000000..b218f0c --- /dev/null +++ b/skills/software-development/termux-go-builds/references/tailscale-android.md @@ -0,0 +1,70 @@ +# Tailscale on Android/Termux — verified recipe (v1.104.2, 2026-10-23) + +## Status legend +✅ verified in an actual session | ⚠️ best-effort, not exercised end-to-end + +## Build (all ✅) + +```bash +# 1. toolchain (pkg has NO tailscale package — verified "Unable to locate package") +pkg install -y golang # Go 1.27.3 -> go1.27.3 android/arm64 + +# 2. source (shallow, exact tag from the releases API) +curl -s https://api.github.com/repos/tailscale/tailscale/releases/latest | grep -m1 '"tag_name"' +git clone --depth 1 --branch v1.104.2 https://github.com/tailscale/tailscale.git src +cd src/cmd/tailscale +CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -tags ts_omit_systray -o ../../ts-out/tailscale . +cd ../../cmd/tailscaled +CGO_ENABLED=0 GOOS=android GOARCH=arm64 go build -tags ts_omit_ssh,ts_omit_taildrop -o ../../../ts-out/tailscaled . +``` + +Failure → fix table (all hit in-session): +| Symptom | Cause | Fix | +|---|---|---| +| `fyne.io/systray@…/systray.go: undefined: nativeLoop` etc. | desktop systray deps, native files missing on android | `-tags ts_omit_systray` (official: `cli/systray_omit.go` build tag `!linux || ts_omit_systray`) | +| `imports tailscale.com/feature/ssh: build constraints exclude all Go files` | `feature/ssh` is `(linux && !android)`, but `cmd/tailscaled/ssh.go` imports it unconditionally (guarded only by `!ts_omit_ssh`) | `-tags ts_omit_ssh` (drops tailnet SSH server — fine for a client that dials out) | +| daemon SIGSEGV `[signal SIGSEGV …]` in `tailscale.com/feature/taildrop.(*Extension).onChangeProfile (ext.go:181)` while handling a profile/login change | Taildrop extension hits a nil profile on Android | drop Taildrop from the daemon build: `-tags ts_omit_taildrop` (official condregister tag; condregister/`maybe_taildrop.go`) — verified: daemon rebuilt with it stayed up across login churn | + +Verify: `tailscale version` (prints 1.104.2-dev…), `tailscaled --version` (works — daemon binary runs standalone). +Install: `ln -sf /tailscale{,d} $PREFIX/bin/`. + +## Run (✅ verified end-to-end: daemon start, browser tap-to-auth against a self-hosted control server `vpn.robbis.space`, node `Running` with `100.64.0.5`, direct peer ping 9 ms; peer discovery: `tailscale status` lists the whole tailnet) + +```bash +TS=$HOME/ts-build; mkdir -p $TS/state +# --statedir takes a DIRECTORY (creates /tailscaled.state). Do NOT pass a directory to --state. +# There is NO --logdir flag in the Android build; daemon logs go to stdout. +$TS/tailscaled --statedir=$TS/state --socket=$TS/tailscaled.sock \ + --tun=userspace-networking --verbose=1 # + redirect stdout to a log in a raw shell +TAILSCALE_SOCKET=$TS/tailscaled.sock $TS/tailscale up --auth-key=tskey-… +# or browser: tailscale up --login-server=https://host --hostname=NAME -> prints register/... URL +TAILSCALE_SOCKET=$TS/tailscaled.sock $TS/tailscale status +``` + +Run-stage failure → fix (all hit in-session, 2026-10-23): +| Symptom | Cause | Fix | +|---|---|---| +| `flag provided but not defined: -logdir` (daemon exits, dumps usage) | this Android/user build of tailscaled has no `-logdir` | drop `--logdir`; daemon logs to stdout — capture it where the process runs | +| CLI `up` → `500 Internal Server Error: cannot start backend when state store is unhealthy` | daemon started with `--state=`; `--state` expects a **file**, `--statedir` expects a **directory** | start with `--statedir=` (creates `/tailscaled.state`); confirm the `.state` file appears under it | +| `tailscale up --socks5-server=… --outbound-http-proxy=…` instantly dumps usage, exit 2 | those are **daemon** flags (tailscaled), not `up` flags | pass them on the tailscaled command line only; `up` accepts `--login-server`, `--hostname`, `--auth-key`, `--socks5-server`?? — no: keep proxy/listen flags on the daemon | +| user approves the login URL but node stays `Logged out` | the confirmed URL belongs to a `tailscale up` process that already died (e.g. `unexpected EOF` during WaitLoginURL); auth links are per-process and silently stale | only hand the user a URL for a `up` process that is still running, and re-derive the URL from that process's output right before sharing; if login keeps failing over mobile, switch to `up --auth-key=tskey-…` (single request, no long-lived browser handshake). CONFIRMED WORKING (2026-10-23): with the `up` process alive, a plain tap of the register URL in the user's phone browser completed the join — EOF flapping is normal retry noise, not a login failure | +| running `pkill -f tailscaled` from a Hermes terminal call kills the call's own shell (SIGTERM mid-command) | the wrapping shell's command line contains the pattern string, so `pkill -f` self-matches | kill by PID from `pgrep tailscaled`, or `pkill -f '^/.*tailscaled '` — never bare `pkill -f ` inside the very command that manages the daemon | + +- **Run the daemon in its own tmux session** (survives Hermes session/terminal-tool churn, + and `pgrep tailscaled || tailscaled …` stays idempotent): + ```bash + pkg install -y tmux + tmux new-session -d -s tsd 'tailscaled --tun=userspace-networking \ + --socket=$PREFIX/var/run/tailscaled.sock --statedir=$HOME/.tailscale \ + --socks5-server=localhost:1055 --outbound-http-proxy-listen=localhost:1055' + ``` + Watch it with `tmux capture-pane -t tsd -p | tail`; kill+restart with + `tmux kill-session -t tsd` then re-create. + +- `--tun=userspace-networking`: required on non-root Android; emulates TUN in-process. + Expose traffic via local SOCKS5/HTTP proxy / SSH — NOT a system VPN. +- `TAILSCALE_SOCKET` env (or `--socket` on the CLI) must match the daemon's `--socket`, + or the CLI says "tailscaled … not running". +- **From Hermes:** the terminal tool refuses `nohup … &`. Launch the daemon with the tool's + `background=true` (logs → `process` poll/log), then `tailscale up` in a separate foreground call. +- Helper with the corrected flags baked in: `templates/ts-up.sh`. diff --git a/skills/software-development/termux-go-builds/templates/ts-up.sh b/skills/software-development/termux-go-builds/templates/ts-up.sh new file mode 100644 index 0000000..d2b9a58 --- /dev/null +++ b/skills/software-development/termux-go-builds/templates/ts-up.sh @@ -0,0 +1,46 @@ +#!/data/data/com.termux/files/usr/bin/bash +# Tailscale start helper for Termux (Android, userspace networking) +# Usage: +# ./ts-up.sh -> start tailscaled + tailscale up with your key +# ./ts-up.sh -> if no key, prints the login URL from tailscaled log + +TS=${TS_DIR:-$HOME/ts-build} +DAEMON="$TS/tailscaled" +LOG="$TS/tailscaled.log" +SOCK="$TS/tailscaled.sock" +STATE="$TS/state" +mkdir -p "$STATE" + +# If authkey was provided via env or arg, use it +AUTHKEY="${1:-$TS_AUTHKEY}" + +# Start tailscaled if not already running +if ! TAILSCALE_SOCKET="$SOCK" "$TS/tailscale" status >/dev/null 2>&1; then + echo "[ts-up] starting tailscaled (userspace)…" + # --statedir takes a DIRECTORY (-> /tailscaled.state); a directory under --state breaks + # the CLI with "state store is unhealthy". No --logdir flag exists in the Android build. + # (In-Hermes: start this daemon with the terminal tool's background=true instead of nohup.) + nohup "$DAEMON" \ + --statedir="$STATE" \ + --socket="$SOCK" \ + --tun=userspace-networking \ + --verbose=1 \ + >>"$LOG" 2>&1 & + TSPID=$! + disown + echo "[ts-up] tailscaled pid=$TSPID, log=$LOG" + sleep 2 +fi + +# Point the CLI at our socket +export TAILSCALE_SOCKET="$SOCK" + +if [ -n "$AUTHKEY" ]; then + echo "[ts-up] running: tailscale up --auth-key=… (masked)" + "$TS/tailscale" up --auth-key="$AUTHKEY" +else + echo "[ts-up] no auth key given; running 'tailscale up' to print login URL" + "$TS/tailscale" up +fi + +"$TS/tailscale" status