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(skills): add termux_background skill

Gotcha Contributor092845269e8e
diff --git a/app/src/main/assets/skills/termux_background.json b/app/src/main/assets/skills/termux_background.json
new file mode 100644
index 0000000..c03fa8d
--- /dev/null
+++ b/app/src/main/assets/skills/termux_background.json
@@ -0,0 +1,9 @@
+{
+ "id": "termux_background",
+ "targetPackageNames": ["com.termux"],
+ "name": "Termux Background Processes",
+ "description": "How to keep a Termux process alive across calls and past Doze / battery savers.",
+ "requiresTools": ["run_termux_command"],
+ "keywords": ["background", "nohup", "wake", "sleep", "doze", "long", "running", "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 — 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. The model cannot kill a process after timeout, but a new run_termux_command call can.\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."
+}