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.
fix(termux): restore notification Exit as only kill path, remove wasteful DPKG pkill
Gotcha Contributor996e2c2dfeb9
diff --git a/app/src/main/assets/skills/termux_background.json b/app/src/main/assets/skills/termux_background.jsonindex 3a1e5b6..626d760 100644--- a/app/src/main/assets/skills/termux_background.json+++ b/app/src/main/assets/skills/termux_background.json@@ -20,5 +20,5 @@"disown","service"],- "instructions": "1. A foreground process started by run_termux_command is bound to the lifecycle of that one call. The moment Gotcha returns from awaited completion, the process is orphaned and at the mercy of Android's lmkd, Doze, and OEM battery managers.\n2. Persistence pattern (the safe one):\n - `nohup myserver > /sdcard/Download/myserver.log 2>&1 < /dev/null & echo $! > /sdcard/Download/myserver.pid; disown`\n - Then `exit 0` immediately so the call returns success.\n - Next call: read the pid with `cat /sdcard/Download/myserver.pid`, then `kill $(cat /sdcard/Download/myserver.pid)` to stop it.\n - The `< /dev/null` is mandatory \u2014 without it, the process inherits the pipe and gets a SIGPIPE the moment the wrapping shell exits.\n3. Wake lock: `termux-wake-lock` (Termux-side; auto-grants WAKE_LOCK on first use). `termux-wake-unlock` to release. Required for any task longer than ~30s that does not write its own progress to disk.\n4. Android 12+ background restriction: if Gotcha is in the background and the assistive ball is off, runs fail with `Not allowed to start service` because Termux exposes a foreground service. Tell the user to bring Gotcha to the foreground (or switch the assistive ball on).\n5. Doze / battery saver: long-running `npm install`, `cargo build`, `pip install -r requirements.txt`, or `pkg install` of a large package can be suspended mid-flight. There is no in-Termux workaround beyond asking the user to add Gotcha to the battery-saver whitelist in Android Settings.\n6. Do not promise scheduled tasks. termux-cron / termux-job-scheduler exist but run inside Termux's own alarms, which Android's job scheduler can throttle. They are best-effort, not real cron.\n7. What you CANNOT do in Termux: run a process as a system service (no systemd), have it auto-restart on boot, or have it survive `force-stop` of Termux. The model should not promise any of these.\n8. Health probe pattern: when waiting for a server to come up, prefer `until curl -sSf http://127.0.0.1:PORT/healthz >/dev/null 2>&1; do sleep 1; done` inside a single run_termux_command call, with a tight timeout, rather than polling from Gotcha.\n9. Process hygiene and recovery: before starting a new long-running service, check `ps -ef | grep <name>` and offer to kill the existing one. If a previous command timed out and holds the dpkg lock, recover programmatically with `fuser $PREFIX/var/lib/dpkg/lock-frontend || dpkg --configure -a` or `pgrep -fl <name> && pkill -9 -f <name>` via a new run_termux_command call before falling back to the notification-shade Exit (which kills every Termux session). The model cannot kill via the timed-out call itself, but a new call can.\n9b. Wake-lock wrapping for long tasks: for any task >30s (pkg install of large package, npm/pip/cargo build), wrap with `termux-wake-lock && { <cmd>; } ; termux-wake-unlock` inside the same run_termux_command payload. This prevents Doze CPU throttling that turns a 30s task into a 10-minute hang.\n10. Consequence: when the assistive ball is on, Gotcha holds a foreground service that exempts it from the Android 12+ backgrounded-start restriction. Without the ball, the same call fails with the \"Not allowed to start service\" error."+ "instructions": "1. A foreground process started by run_termux_command is bound to the lifecycle of that one call. The moment Gotcha returns from awaited completion, the process is orphaned and at the mercy of Android's lmkd, Doze, and OEM battery managers.\n2. Persistence pattern (the safe one):\n - `nohup myserver > /sdcard/Download/myserver.log 2>&1 < /dev/null & echo $! > /sdcard/Download/myserver.pid; disown`\n - Then `exit 0` immediately so the call returns success.\n - Next call: read the pid with `cat /sdcard/Download/myserver.pid`, then `kill $(cat /sdcard/Download/myserver.pid)` to stop it.\n - The `< /dev/null` is mandatory \u2014 without it, the process inherits the pipe and gets a SIGPIPE the moment the wrapping shell exits.\n3. Wake lock: `termux-wake-lock` (Termux-side; auto-grants WAKE_LOCK on first use). `termux-wake-unlock` to release. Required for any task longer than ~30s that does not write its own progress to disk.\n4. Android 12+ background restriction: if Gotcha is in the background and the assistive ball is off, runs fail with `Not allowed to start service` because Termux exposes a foreground service. Tell the user to bring Gotcha to the foreground (or switch the assistive ball on).\n5. Doze / battery saver: long-running `npm install`, `cargo build`, `pip install -r requirements.txt`, or `pkg install` of a large package can be suspended mid-flight. There is no in-Termux workaround beyond asking the user to add Gotcha to the battery-saver whitelist in Android Settings.\n6. Do not promise scheduled tasks. termux-cron / termux-job-scheduler exist but run inside Termux's own alarms, which Android's job scheduler can throttle. They are best-effort, not real cron.\n7. What you CANNOT do in Termux: run a process as a system service (no systemd), have it auto-restart on boot, or have it survive `force-stop` of Termux. The model should not promise any of these.\n8. Health probe pattern: when waiting for a server to come up, prefer `until curl -sSf http://127.0.0.1:PORT/healthz >/dev/null 2>&1; do sleep 1; done` inside a single run_termux_command call, with a tight timeout, rather than polling from Gotcha.\n9. Process hygiene: before starting a new long-running service, check `ps -ef | grep <name>` and offer to kill the existing one via the notification-shade Exit \u2014 a run_termux_command cannot kill another call's process; only tapping Exit on the Termux notification (global_action or press_key 'notifications' + tap the Exit action, which ends every Termux session) reliably stops it. If you cannot reach Exit, ask the user to tap it. Do not try `pkill`, `fuser` or `dpkg --configure -a` via another run_termux_command to kill it \u2014 that will hang until timeout and not release the lock.\n9b. Wake-lock wrapping for long tasks: for any task >30s (pkg install of large package, npm/pip/cargo build), wrap with `termux-wake-lock && { <cmd>; } ; termux-wake-unlock` inside the same run_termux_command payload. This prevents Doze CPU throttling that turns a 30s task into a 10-minute hang.\n10. Consequence: when the assistive ball is on, Gotcha holds a foreground service that exempts it from the Android 12+ backgrounded-start restriction. Without the ball, the same call fails with the \"Not allowed to start service\" error."}\ No newline at end of filediff --git a/app/src/main/java/com/gotcha/tools/TermuxMessages.kt b/app/src/main/java/com/gotcha/tools/TermuxMessages.ktindex 5a98f27..09b8c7a 100644--- a/app/src/main/java/com/gotcha/tools/TermuxMessages.kt+++ b/app/src/main/java/com/gotcha/tools/TermuxMessages.kt@@ -66,13 +66,11 @@ internal object TermuxMessages {fun tooManyInFlight(limit: Int) = ToolResult.error("$limit Termux commands are already running and none has finished yet. Earlier commands keep running " +- "even after they time out — a run_termux_command cannot kill them from the timed-out call itself, " +- "but a new call can try `pgrep -fl <name> && pkill -9 -f <name>` or " +- "`fuser \$PREFIX/var/lib/dpkg/lock-frontend || dpkg --configure -a` first. To stop them, open the " ++ "even after they time out — a run_termux_command cannot kill them. To stop them, open the " +"notifications shade (global_action or press_key 'notifications') and tap the Exit action on the " +- "Termux notification, which ends every Termux session. If you cannot reach it, ask the user to tap " +- "Exit on the Termux notification. Otherwise wait for them to finish (use the sleep tool) rather " +- "than starting another."+ "Termux notification, which ends every Termux session. You have tap/globalAction tools to do " ++ "this yourself; if you cannot reach it, ask the user to tap Exit on the Termux notification. " ++ "Otherwise wait for them to finish (use the sleep tool) rather than starting another.")/**@@ -91,13 +89,12 @@ internal object TermuxMessages {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 (the hard ceiling is 600). ")- append("Note it keeps running either way — a run_termux_command cannot stop it from the timed-out ")- append("call itself, but a new call can try `pgrep -fl <name> && pkill -9 -f <name>` or ")- append("`fuser \$PREFIX/var/lib/dpkg/lock-frontend || dpkg --configure -a` first — so check Termux ")- append("before starting again. To stop a stuck one, open the notifications shade ")- append("(global_action or press_key 'notifications') and tap the Exit action on the Termux ")- append("notification, which ends every Termux session. If you cannot reach it, ask the user to tap ")- append("Exit on the Termux notification.")+ append("Note it keeps running either way — a run_termux_command cannot stop it — so check Termux ")+ append("before starting again. To stop a stuck one, open the notifications shade (global_action or ")+ append("press_key 'notifications') and tap the Exit action on the Termux notification, which ends ")+ append("every Termux session. You have tap/globalAction tools to do this yourself; if you cannot ")+ append("reach it, ask the user to tap Exit on the Termux notification. Otherwise retry with a ")+ append("larger timeout or wait with the sleep tool.")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.")