dsh-phone-buddy
by sunxian-max
README.md
# dsh-phone-buddy
**English** | [简体中文](README.zh-CN.md)
Android device control and a banter knowledge base for DeepSeek Harness, exposed as **14 MCP tools**.
Control a physical device or an emulator from the agent: screenshot, tap, swipe, long-press, key events, CJK text injection, and a one-shot "type → send → verify" flow. Alongside it sits a retrieval layer over four markdown knowledge files (persona card, playbook, principle notes, formula drills).
## Why it exists
Two problems this solves, both found the hard way:
1. **`adb shell input text` cannot type Chinese.** It throws `NullPointerException: Attempt to get length of null array` for any non-ASCII input. The only reliable channel is an ADBKeyboard broadcast with base64 payload — this plugin wraps that.
2. **Chat platforms silently rewrite content.** A blocked message becomes a row of asterisks, and the recall window is often two minutes. The send tool therefore returns a screenshot and tells you to look at it immediately, because the server has no OCR and cannot judge on your behalf.
## Tools
### Device (10)
| Tool | Purpose |
|---|---|
| `phone_status` | Active device, kind (physical/emulator), foreground window, IME, resolution |
| `phone_devices` | List every adb device, flagged emulator or physical |
| `phone_use` | Switch the active device |
| `phone_shot` | Screenshot to a local PNG; returns path, serial, and real resolution |
| `phone_tap` | Tap a coordinate |
| `phone_swipe` | Swipe between two points |
| `phone_long_press` | Long-press (message menus) |
| `phone_key` | Key event (4=back 3=home 26=power 82=unlock) |
| `phone_type` | Inject text into the focused input (any Unicode) |
| `phone_send` | Tap input → inject → tap send → screenshot, in one call |
### Knowledge (4)
| Tool | Purpose |
|---|---|
| `banter_quick` | Cheat sheet: filter-safe patterns, formulas, recall flow, hard rules |
| `banter_personas` | List persona cards |
| `banter_search` | Keyword search across the knowledge files |
| `banter_read` | Read one file, or one persona card |
## Requirements
| Dependency | Required | Note |
|---|---|---|
| Node.js | yes | Bundled with DSH |
| adb | yes | platform-tools |
| ADBKeyboard IME | yes | the only path for CJK input |
| Device or emulator | yes | USB debugging, or `adb connect` |
| root | no | screenshot/tap/type all work with plain shell |
## Physical device vs emulator
Leave `DEVICE_SERIAL` unset and the plugin picks the first online device — both kinds work.
| | Physical | Emulator |
|---|---|---|
| Serial | USB serial | `emulator-5554` or `127.0.0.1:7555` |
| Connect | USB + authorize on device | `adb connect <ip:port>` first |
| Common ports | — | LDPlayer 5555 / MuMu 7555 / Nox 62001 / MEmu 21503 |
| Detection | `emulator: false` | `emulator: true` |
`phone_shot` returns the actual resolution and a conversion hint, because the image preview in most viewers is scaled.
## Install
```bash
npm i -g dsh-phone-buddy
# or inside a DSH profile
dsh plugin add dsh-phone-buddy
```
The `postinstall` step mirrors `server.mjs` and `knowledge/` into `<DSH_HOME>/plugins/phone-buddy/` and **keeps any persona files you already wrote**. Restart DSH afterwards.
Then enable the IME once per device:
```bash
adb install ADBKeyboard.apk
adb shell ime enable com.android.adbkeyboard/.AdbIME
```
## Configuration
| Env | Default | Meaning |
|---|---|---|
| `ADB_PATH` | `adb` | Absolute path to the adb binary |
| `DEVICE_SERIAL` | empty | Pin one device; empty = auto-pick first online |
| `ADB_KB_IME` | `com.android.adbkeyboard/.AdbIME` | ADBKeyboard IME id |
| `PHONE_SHOT_DIR` | `<tmp>/phone-buddy` | Screenshot output directory |
| `PERSONA_NAME` | first non-template | Default persona card |
## Personas
`knowledge/personas/` holds one `.md` per persona; the file name is the id. `TEMPLATE.md` is a fill-in-the-blanks starter. Change accounts by adding a card — nothing in the code assumes a particular in-game name.
## Limitations
- **No OCR.** `phone_send` returns a screenshot path; judging it is the caller's job.
- **Coordinates must be measured.** Every resolution and layout differs.
- **The IME gets switched.** `phone_type` enables ADBKeyboard when needed and does not switch back.
- **Single-device assumption** in each call, though switching is supported.
## License
MIT