Skip to content

Your phone, on your command. Gotcha is world's first fully on-device AI copilot for Android that turns natural language into real device actions — safely.

feat(termux): wire skills into the model, docs, and error messages

Gotcha Contributorf31520ebc6b6
diff --git a/README.md b/README.md
index 388d64f..b9cd788 100644
--- a/README.md
+++ b/README.md
@@ -29,6 +29,22 @@ llama.cpp / LM Studio / Ollama.
The full table — every tool, its test tier, and how it is verified — is
generated from a manifest into [`docs/FEATURE_TEST_COVERAGE.md`](docs/FEATURE_TEST_COVERAGE.md).
+## Termux (Linux shell)
+
+Termux (the F-Droid or GitHub build) gives Gotcha a real Linux user-space
+on Android and is reached through the `run_termux_command` tool, which
+runs headlessly under Termux's user id. It is genuinely useful for
+package installs, scripts, compilers, Python, git, and the rest of the
+long Unix tail — but it is not a server. There is no root, no systemd,
+no kernel access, and no persistence between shell calls. Long-running
+processes must be backgrounded explicitly; large packages may need a
+mirror change on slow networks. The bundled `termux_*` skills
+(`termux_operations`, `termux_repositories`, `termux_filesystem`,
+`termux_background`, `termux_proot`) enumerate the realistic limits; ask
+the assistant to `search_skills` for `termux_operations` if anything is
+unclear. See [`docs/termux-setup.md`](docs/termux-setup.md) for the
+one-time setup walkthrough.
+
### Monitor vs Operator
Two agent modes, switchable mid-conversation:
diff --git a/RUNNING.md b/RUNNING.md
index 3a05fcf..0d9fee3 100644
--- a/RUNNING.md
+++ b/RUNNING.md
@@ -231,6 +231,17 @@ Type natural-language requests. Examples:
- **run_command** runs as the unprivileged app user (no root). Many system paths
are unreadable; destructive commands (`rm -r`, `dd`, `reboot`, `su`, …) are
blocked, with a 15 s timeout and 32 KB output cap.
+- **run_termux_command** runs inside Termux's user-space, which gives you a
+ real Linux shell with `pkg`/`apt`, Python, git, compilers and the rest of
+ the Unix tail. It is not a server: no root, no systemd, no kernel access,
+ no persistence between calls, output capped at 32 KB, hard 600 s timeout,
+ and 4 concurrent commands. Long-running processes need to be backgrounded
+ with `nohup ... &` + `disown` and can be killed by Doze / battery savers —
+ call `search_skills('termux_background')` for the full pattern. The default
+ Termux mirror is slow or blocked on some networks; if `pkg install` hangs,
+ ask the user to open Termux and run `termux-change-repo` once. See
+ [`docs/termux-setup.md`](docs/termux-setup.md) for the one-time setup
+ walkthrough.
### Monitor vs Operator modes
diff --git a/app/src/main/java/com/gotcha/tools/TermuxMessages.kt b/app/src/main/java/com/gotcha/tools/TermuxMessages.kt
index 3e27465..e4c897d 100644
--- a/app/src/main/java/com/gotcha/tools/TermuxMessages.kt
+++ b/app/src/main/java/com/gotcha/tools/TermuxMessages.kt
@@ -48,7 +48,8 @@ internal object TermuxMessages {
"background, Android is refusing the start — from Android 12 a backgrounded app cannot launch " +
"another app's foreground service. Ask the user to bring Gotcha to the foreground (or switch the " +
"assistive ball on, which keeps it exempt) and try again. Otherwise Termux may have been disabled " +
- "or force-stopped; use run_command for the app's own sandbox meanwhile."
+ "or force-stopped; use run_command for the app's own sandbox meanwhile. " +
+ "For the full background-process rules, call search_skills('termux_background')."
)
/**
@@ -84,8 +85,16 @@ internal object TermuxMessages {
append("\n- it is waiting for typed input that will never come, since there is no terminal ")
append("here. Retry with a non-interactive flag (e.g. -y) or pass the answer in stdin.")
}
- append("\n- or it is genuinely slow. Retry with a larger timeout_seconds. Note it keeps running ")
- append("either way — I cannot kill another app's process — so check Termux before starting again.")
+ append("\n- or it is genuinely slow. Retry with a larger timeout_seconds (the hard ceiling is 600). ")
+ append("Note it keeps running either way — I cannot kill another app's process — so check Termux ")
+ append("before starting again.")
+ append("\n- or, if the command was `pkg install` or `apt install` and it never moved past the ")
+ append("mirror-connect phase, the default Termux mirror is slow or blocked on the user's network. ")
+ append("Ask the user to open Termux, run `termux-change-repo` once, pick a closer mirror, and retry.")
+ append("\n- or, if this was a long-running process (server, watcher, build) rather than a one-shot ")
+ append("command, it should be backgrounded with `nohup ... > log 2>&1 < /dev/null & echo $! > pid; ")
+ append("disown` and the call should `exit 0` immediately; `termux-wake-lock` locks Doze off.")
+ append("\nFor the full list of pitfalls, call search_skills('termux_operations').")
}
)
diff --git a/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt b/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt
index 87d86b1..0378635 100644
--- a/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt
+++ b/app/src/main/java/com/gotcha/tools/ToolDefinitions.kt
@@ -1877,7 +1877,16 @@ object ToolDefinitions {
"Termux runs under its own user id, so Gotcha's working directory and app files are NOT " +
"visible here — use run_command for those. Shared storage (/sdcard) is only reachable if " +
"the user has run `termux-setup-storage` in Termux; if a /sdcard path fails, say so " +
- "rather than retrying.",
+ "rather than retrying.\n" +
+ "\nRealistic limits to factor in:\n" +
+ "- No interactive prompts — there is no terminal here, so any command that waits for typed input (pkg install without -y, ssh password, read, mysql>) blocks until the 600s timeout. Always pass -y / --yes / -q where the tool supports them.\n" +
+ "- Output is capped at 32KB by Gotcha and ~100KB by Termux. For larger output, redirect to a file inside Termux (e.g. `... > /sdcard/Download/out.txt`) and read it back via read_file.\n" +
+ "- You cannot kill a command after submitting it. A timed-out command keeps running under Termux's UID. There is no kill from here.\n" +
+ "- Hard ceiling: timeout_seconds <= 600. `pkg install` of ffmpeg, chromium, rust, golang, or texlive can hit this — raise timeout_seconds to 600 and warn the user before starting one.\n" +
+ "- 4 commands in flight, process-wide. Sub-agents share the same semaphore. A 5th call returns an error.\n" +
+ "- Android 12+ foreground-service rule: if Gotcha is in the background and the assistive ball is off, this tool fails with 'Not allowed to start service'. Tell the user to bring Gotcha to the foreground (or switch the assistive ball on).\n" +
+ "\nIf `pkg install` hangs at \"0% [Connecting to packages.termux.dev]\" or fails with NO_PUBKEY, the default mirror is slow or blocked on the user's network. Tell the user to open Termux and run `termux-change-repo` once, then retry. The full mirror list and the non-interactive sources.list swap are in the termux_repositories skill.\n" +
+ "\nFor long-running processes (servers, watchers, daemons), the foreground process is orphaned the moment Gotcha returns. The persistence pattern (`nohup ... > log 2>&1 < /dev/null & echo $! > pid; disown`) and the termux-wake-lock requirement are in the termux_background skill. For full Debian/Ubuntu via proot-distro (when Termux's bionic/busybox is not enough), see the termux_proot skill.",
schema {
putJsonObject("properties") {
putJsonObject("command") {
diff --git a/docs/termux-setup.md b/docs/termux-setup.md
index 8e6a459..d90c3fb 100644
--- a/docs/termux-setup.md
+++ b/docs/termux-setup.md
@@ -74,3 +74,74 @@ The Settings → Permissions → *Termux Commands (Optional)* row links to the s
assistant to run something: `pkg install python -y` and `python3 --version`.
7. Revoke the permission in system Settings → the page's permission step unchecks on
the next resume, and the copy box / Check button disappear until it is granted again.
+
+## What may go wrong
+
+`run_termux_command` works, but it is not a server. The realistic limits,
+in order of how often they bite:
+
+- **Each call is a fresh shell.** `cd`, `export`, activated virtualenvs,
+ and `source` do not carry over. Chain dependent steps in one command
+ with `&&`, never split across calls.
+- **No interactive prompts.** The plugin API does not connect a TTY, so
+ anything that waits for typed input (a `pkg install` without `-y`, an
+ `ssh` password prompt, `read`, `mysql>`) blocks until the 600 s
+ timeout. Always pass `-y` / `--yes` / `-q` where the tool supports it.
+- **Output is capped** at 32 KB by Gotcha (and ~100 KB by Termux itself).
+ For larger output, redirect to a file inside Termux and read it back
+ through Gotcha's `read_file`.
+- **The model cannot kill a command.** A timed-out command keeps running
+ under Termux's UID. Before launching anything long, warn the user.
+- **Hard ceiling: 600 s.** `pkg install` of `ffmpeg`, `chromium`, `rust`,
+ `golang`, or `texlive` can hit this. Raise `timeout_seconds` to 600
+ and warn the user before starting one.
+- **4 commands in flight, process-wide.** Sub-agents share the same
+ semaphore. A 5th call returns an error.
+- **Android 12+ background restriction.** If Gotcha is in the background
+ and the assistive ball is off, `run_termux_command` fails with
+ *Not allowed to start service*. Bring Gotcha to the foreground, or
+ switch the assistive ball on.
+- **The Play-Store build of Termux has no RUN_COMMAND API** and can
+ never work with Gotcha. Only the F-Droid or GitHub build is usable.
+
+The `termux_operations` bundled skill is the in-prompt summary of these
+limits; the model picks it up automatically when Termux is in the
+foreground.
+
+## What works but is non-obvious
+
+Most things that look broken have a non-obvious workaround. The model
+should know these so the user does not have to:
+
+- **Mirror switching.** The default `packages.termux.dev` mirror is slow
+ or blocked on networks in China, parts of India, behind corporate
+ firewalls, and on some ISPs. The user runs `termux-change-repo` inside
+ Termux once and picks a closer mirror (Tsinghua, USTC, ISCAS, CERN, NJU
+ for China; the official primary or the Netherlands mirror otherwise).
+ After a mirror change, run `pkg update -y` to verify.
+- **Large packages.** `ffmpeg`, `python`, `rust`, `chromium`, `golang`,
+ `nodejs-lts`, `texlive`, and `qt` typically take 5-15 minutes to
+ install even on a fast mirror. Always raise `timeout_seconds` to 600.
+ If a `pkg install` keeps failing midway, split the network step from
+ the install step with `pkg download <pkg>` and `dpkg -i` from the local
+ cache.
+- **Shared storage (`/sdcard`).** `/sdcard/Download` is the only safe
+ cross-uid bridge between Gotcha and Termux. It is empty inside Termux
+ until the user runs `termux-setup-storage` once in Termux.
+- **Long-running processes.** A foreground process started by
+ `run_termux_command` is orphaned the moment Gotcha returns. The
+ persistence pattern is
+ `nohup cmd > /sdcard/Download/x.log 2>&1 < /dev/null & echo $! > /sdcard/Download/x.pid; disown`,
+ then `exit 0` immediately. For tasks longer than ~30 s, also call
+ `termux-wake-lock` (and `termux-wake-unlock` to release).
+- **glibc binaries.** Termux uses bionic, so a `*.deb` built for glibc
+ (Debian/Ubuntu) will not run. Use `proot-distro install debian` (or
+ `ubuntu`, `alpine`, `fedora`, `archlinux`) and run the command inside
+ via `proot-distro login debian -- bash -c "..."`. Performance penalty
+ is ~10× because proot uses `ptrace`.
+- **Real root.** `proot` is not a security boundary — it does not grant
+ real root. On a rooted device, `pkg install tsu -y` then `tsu -c "cmd"`
+ runs with real root via Magisk/SuperSU.
+
+The `termux_repositories`, `termux_filesystem`, `termux_background`, and
+`termux_proot` bundled skills cover each of these in detail.