--- name: autofish-control description: Control Android devices with Autofish via the af CLI. Use this skill when you need reliable observe-act-verify loops, ref-based tapping, overlay management, screenshots, and recovery steps. --- # Autofish Control Skill Use deterministic control with evidence at every step. ## When To Use - You need to navigate Android UI through Autofish (`af`). - You need stable replay using refs (`@nK`) instead of coordinates. - You need explicit verification after each action. ## Setup ```bash af config set remote.url "http://:" af config set remote.token "" af config set memory.db "$HOME/.config/af/af.db" af config set output.default "text" af config set artifacts.dir "$HOME/.config/af/artifacts" ``` Copy `IP`, `PORT`, and `token` from the Autofish Android app. For USB port forwarding, use the forwarded local address, for example `http://127.0.0.1:`. If the device is connected with adb and the App is new enough to write a connection hint, prefer: ```bash af connect usb --device ``` `af connect usb` writes the forwarded `remote.url` and `connection.*` USB metadata, verifies `af health`, and does not write `remote.token`. Keep the token copied from the app for `observe`, `act`, `verify`, and `recover`. Environment variables also work: `AF_URL`, `AF_TOKEN`, `AF_DB`, `AF_OUTPUT`, `AF_ARTIFACT_DIR`. - `af health` only requires URL. - `observe`, `act`, `verify`, `recover` require URL + token. - `af memory ...` is local-only and requires memory enabled. - `config list` and `config get remote.token` redact tokens as ``. - Use `--output json` when parsing results in scripts. - Check `af --help` first if the installed CLI may be older than this skill. - If config/env is unavailable, put remote flags after the command group: `af --session observe --url --token page`. Choose one session per task: ```bash SESSION="task-name" af --session "$SESSION" observe page --field screen --field refs --max-rows 80 ``` Do not reuse the default `default` session across unrelated tasks. ## Workflow Memory session rules: - `memory context` and `memory save` use the global `--session`. - `memory log` and `memory stats` filter with `--for-session `. - `memory search` and `memory experience` query cross-session history; do not treat global `--session` as a filter for them. 1. Baseline: - `af --session observe page --field screen --field refs --max-rows 80` - `af --session memory context` - `af memory search --app ` - `af memory experience --app --activity --page-fp ""` 2. One-step execution: - Run exactly one action command. - Run `af --session observe page` (add `--field refs` if needed). - Verify expected state. 3. Continue only from fresh observations. Do not run blind action chains. 4. After solving a non-trivial problem: - `af --session memory save --app --topic "/" --content ""` ### Memory Loop For experience learning, keep this exact order: 1. `observe` the starting page. 2. Run one `act`. 3. `observe` again. 4. Run one `verify`. `act` and `recover` invalidate the cached page fingerprint. A transition is recorded only when a fresh successful observation happens after the action and before verification. ### observe page Always returns: `topActivity`, `mode`, `hasWebView`, `nodeReliability`. | `--field` | What it adds | |---|---| | `screen` (default) | Row counts, fingerprint rows, and a JSON artifact path for full rows | | `refs` | Clickable ref aliases with `refVersion` | Use the returned `screen.artifact` saved path when full page rows are needed. `observe screenshot` and overlay commands are diagnostics only; they do not refresh memory context. `topActivity` is `null` when the service cannot confirm a stable value. Re-observe before acting. ## Tap Priority 1. `af --session act tap --by ref --value @nK` 2. `af --session act tap --by text|desc|resid --value "" [--exact-match]` 3. `af --session act tap --xy X,Y` Other actions exist for non-tap flows: `swipe`, `text`, `launch`, `stop`, `key`, `back`, `home`. ## Refs - Refresh refs on dynamic pages: `af --session observe page --field refs`. - If ref tap fails with stale/unobserved errors, re-observe once and retry once. - Do not assume alias index stability after UI updates. - Do not auto-pick among ambiguous matching candidates. ## Verify Priority 1. `af --session verify top-activity --expected "" --mode contains` 2. `af --session verify text-contains --text ""` 3. `af --session verify node-exists --by text|desc|resource_id|class --value "" [--exact-match]` `top-activity --mode` is `contains` or `equals`. `text-contains` is case-insensitive by default; use `--case-sensitive` only when exact case matters. On WebView-heavy pages (`hasWebView=true` or `nodeReliability=low`), prefer `text-contains`. Do not rely on node/ref structure inside WebView content. ## Recovery When state is uncertain: 1. `af --session observe page --max-rows 120` 2. `af memory experience --app --activity --failure-cause ` 3. Choose one recovery: - `af --session recover back --times 1` for modal/back-stack drift. - `af --session recover home` for lost navigation context. - `af --session recover relaunch --package ` for app reset. 4. `af memory log --for-session --status failed --limit 5` 5. Re-run baseline. ## Diagnostics ```bash af --session observe overlay set --enable --mark-scope all --refresh on --refresh-interval-ms 800 af --session observe screenshot --annotate --hide-overlay --max-marks 120 --mark-scope interactive af --session observe overlay set --disable --mark-scope all --refresh off ``` Artifacts still write to disk when memory is disabled, but DB artifact ids may be absent. ## Memory Topic Conventions | Prefix | Purpose | |---|---| | `nav/` | Navigation paths between screens | | `pitfall/` | Known problems and workarounds | | `selector/` | Reliable selector strategies | | `recovery/` | Recovery strategies that worked | ## Guidelines - Favor refs over coordinates. - Keep `--session` stable and unique per task. - Each action must be followed by observation, then verification. - Use `af memory experience` before acting on unfamiliar pages. - Use `af --session memory context` to inspect the current cached page fingerprint. - Use `af memory log --for-session ` and `af memory stats --for-session ` to inspect failures and session quality.