Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Phone tools: wake and sleep keys, any-language text, and a package-name hint

Xiaolei Shi7f4876c3b303
diff --git a/apps/docs/content/docs/mobile/android-control.mdx b/apps/docs/content/docs/mobile/android-control.mdx
index 9a9b46264d..ae1929d837 100644
--- a/apps/docs/content/docs/mobile/android-control.mdx
+++ b/apps/docs/content/docs/mobile/android-control.mdx
@@ -14,3 +14,11 @@ OpenMausBot can expose a USB-connected Android device through its Phone Harness
- The packaged Android platform tools or a compatible local ADB installation
Phone access is a separate capability from desktop computer use. Keep the device unlocked and visible while testing, and review actions that may send messages, change accounts, or expose private content.
+
+## Screen and lock
+
+A bot can turn the screen on and off and swipe past a lock screen that has no PIN, pattern, or password. It never unlocks a secured lock screen: it asks you to unlock the phone.
+
+## Typing other languages
+
+The bot types letters, digits, spaces, and `_.,@-` through Android's own input. For other text, such as Chinese, emoji, or `+`, install [ADBKeyBoard](https://github.com/senzhk/ADBKeyBoard) on the phone and choose it as the keyboard. ADBKeyBoard shows no on-screen keyboard, so switch back to your usual keyboard when you type on the phone yourself.
diff --git a/server/drivers/phone-proxy.test.ts b/server/drivers/phone-proxy.test.ts
index 1572d0d627..900692037a 100644
--- a/server/drivers/phone-proxy.test.ts
+++ b/server/drivers/phone-proxy.test.ts
@@ -1,6 +1,6 @@
import { describe, expect, it } from "vitest";
-import { createPhoneClaim, findPackages, parseDevices, parseLaunchablePackages, parseUiNodes } from "./phone-proxy.ts";
+import { TOOLS, createPhoneClaim, findPackages, launchTarget, parseDevices, parseLaunchablePackages, parseUiNodes, typePhoneText } from "./phone-proxy.ts";
describe("phone MCP parsing", () => {
it("keeps physical USB devices distinguishable from network and emulator transports", () => {
@@ -29,6 +29,17 @@ emulator-5554 device product:sdk model:Emulator transport_id:6
expect(findPackages("Skyscanner", packages)).toEqual(["net.skyscanner.android.main"]);
});
+ it("tells the bot to pass a package name when no app name matches", () => {
+ const packages = ["com.taobao.idlefish", "com.ubercab"];
+ expect(() => launchTarget("闲鱼", packages)).toThrow("call list_apps without a query and pass the package name");
+ expect(launchTarget("com.taobao.idlefish", packages)).toBe("com.taobao.idlefish");
+ });
+
+ it("offers keys that turn the screen on and off", () => {
+ const press = TOOLS.find((tool) => tool.name === "press") as { inputSchema: { properties: { key: { enum: string[] } } } } | undefined;
+ expect(press?.inputSchema.properties.key.enum).toEqual(expect.arrayContaining(["wakeup", "sleep"]));
+ });
+
it("turns Android UI XML into tap-ready visible nodes", () => {
expect(parseUiNodes(`<?xml version="1.0"?><hierarchy><node text="Where to?" resource-id="com.ubercab:id/input" class="android.widget.TextView" content-desc="Destination" bounds="[12,100][400,180]" /></hierarchy>`)).toEqual([
{ text: "Where to?", description: "Destination", id: "com.ubercab:id/input", className: "android.widget.TextView", bounds: [12, 100, 400, 180] },
@@ -36,6 +47,46 @@ emulator-5554 device product:sdk model:Emulator transport_id:6
});
});
+describe("phone MCP text input", () => {
+ const ADB_KEYBOARD = "com.android.adbkeyboard/.AdbIME";
+ const VENDOR_KEYBOARD = "com.baidu.input_huawei/.ImeService";
+ const device = (keyboard: string) => {
+ const commands: string[][] = [];
+ const shell = async (...command: string[]) => {
+ commands.push(command);
+ return command[0] === "settings" ? `${keyboard}\n` : "";
+ };
+ return { commands, shell };
+ };
+
+ it.each([ADB_KEYBOARD, VENDOR_KEYBOARD])("types basic ASCII with Android input whatever the keyboard (%s)", async (keyboard) => {
+ const phone = device(keyboard);
+ await expect(typePhoneText(phone.shell, "iPad mini_6")).resolves.toBe("Typed text into the focused Android field");
+ expect(phone.commands).toEqual([["input", "text", "iPad%smini_6"]]);
+ });
+
+ it("types any other text through ADBKeyBoard as Base64 UTF-8", async () => {
+ const phone = device(ADB_KEYBOARD);
+ await expect(typePhoneText(phone.shell, "二手 iPad +86 😀")).resolves.toBe("Typed text into the focused Android field");
+ expect(phone.commands).toEqual([
+ ["settings", "get", "secure", "default_input_method"],
+ ["am", "broadcast", "-a", "ADB_INPUT_B64", "--es", "msg", "5LqM5omLIGlQYWQgKzg2IPCfmIA="],
+ ]);
+ });
+
+ it("asks for ADBKeyBoard and types nothing when another keyboard is chosen", async () => {
+ const phone = device(VENDOR_KEYBOARD);
+ await expect(typePhoneText(phone.shell, "二手 iPad")).rejects.toThrow("ADBKeyBoard (https://github.com/senzhk/ADBKeyBoard) is installed and chosen as the phone's keyboard");
+ expect(phone.commands).toEqual([["settings", "get", "secure", "default_input_method"]]);
+ });
+
+ it.each(["", "a".repeat(257)])("refuses empty or over-long text without touching the phone", async (text) => {
+ const phone = device(ADB_KEYBOARD);
+ await expect(typePhoneText(phone.shell, text)).rejects.toThrow("Android text must be 1 to 256 characters");
+ expect(phone.commands).toEqual([]);
+ });
+});
+
describe("phone MCP lazy claim gate", () => {
const harnessEnv = { OMB_HARNESS_URL: "http://127.0.0.1:8799", OMB_PHONE_TOKEN: "tok" };
const stub = (handler: (request: Request) => Promise<{ ok: boolean; status: number }>) => {
diff --git a/server/drivers/phone-proxy.ts b/server/drivers/phone-proxy.ts
index e131c1353e..821c23607a 100644
--- a/server/drivers/phone-proxy.ts
+++ b/server/drivers/phone-proxy.ts
@@ -15,6 +15,7 @@ const PHONE_BUSY_TEXT = "Another thread is using the phone. This call was not pe
const PACKAGE = /^[A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)+$/;
const COMPONENT = /^([A-Za-z0-9_]+(?:\.[A-Za-z0-9_]+)+)\/\S+$/;
const SAFE_TEXT = /^[A-Za-z0-9 _.,@-]+$/;
+const ADB_KEYBOARD = "com.android.adbkeyboard/.AdbIME";
const KEYCODES: Record<string, string> = {
back: "KEYCODE_BACK",
delete: "KEYCODE_DEL",
@@ -26,9 +27,11 @@ const KEYCODES: Record<string, string> = {
recent: "KEYCODE_APP_SWITCH",
return: "KEYCODE_ENTER",
right: "KEYCODE_DPAD_RIGHT",
+ sleep: "KEYCODE_SLEEP",
space: "KEYCODE_SPACE",
tab: "KEYCODE_TAB",
up: "KEYCODE_DPAD_UP",
+ wakeup: "KEYCODE_WAKEUP",
};
const KNOWN_PACKAGES: Record<string, string> = {
skyscanner: "net.skyscanner.android.main",
@@ -138,6 +141,23 @@ async function onDevice(serial: string, args: string[], binary = false) {
return runAdb(["-s", serial, ...args], { binary });
}
+type Shell = (...command: string[]) => Promise<string>;
+const deviceShell = (serial: string): Shell => async (...command) => (await onDevice(serial, ["shell", ...command])).toString("utf8");
+
+export async function typePhoneText(shell: Shell, text: string): Promise<string> {
+ if (!text || text.length > 256) throw new Error("Android text must be 1 to 256 characters");
+ if (SAFE_TEXT.test(text)) {
+ await shell("input", "text", text.replaceAll(" ", "%s"));
+ } else {
+ if ((await shell("settings", "get", "secure", "default_input_method")).trim() !== ADB_KEYBOARD) {
+ throw new Error("Only letters, digits, spaces and _.,@- can be typed until ADBKeyBoard (https://github.com/senzhk/ADBKeyBoard) is installed and chosen as the phone's keyboard. Ask the person to set it up, or type only those characters.");
+ }
+ // ADBKeyBoard reads msg as Base64 UTF-8; Base64 also keeps the text out of the device shell's syntax.
+ await shell("am", "broadcast", "-a", "ADB_INPUT_B64", "--es", "msg", Buffer.from(text, "utf8").toString("base64"));
+ }
+ return "Typed text into the focused Android field";
+}
+
function normalize(value: string) {
return value.toLowerCase().replace(/[^a-z0-9]/g, "");
}
@@ -169,6 +189,14 @@ export function findPackages(name: string, packages: string[]) {
return [];
}
+export function launchTarget(name: string, packages: string[]) {
+ const matches = findPackages(name, packages);
+ if (matches.length === 1) return matches[0];
+ throw new Error(matches.length
+ ? `App name is ambiguous: ${matches.join(", ")}`
+ : `No installed launchable app matches ${JSON.stringify(name)}. open_app knows English names and package names; call list_apps without a query and pass the package name.`);
+}
+
async function launchablePackages(serial: string) {
const output = await onDevice(serial, [
"shell", "cmd", "package", "query-activities", "--brief",
@@ -229,7 +257,7 @@ function nodeLines(nodes: UiNode[]) {
}).join("\n") || "No accessible Android UI text is visible.";
}
-const TOOLS = [
+export const TOOLS = [
{ name: "status", description: "Check physical USB Android devices and USB-debugging authorization before any Android phone task.", inputSchema: { type: "object", properties: {} } },
{ name: "read_screen", description: "Read visible text, accessibility labels, resource ids, and pixel bounds from the connected Android screen. Use after every action to verify the result.", inputSchema: { type: "object", properties: { serial: { type: "string" } } } },
{ name: "screenshot", description: "Capture the connected Android screen when accessibility text is insufficient. Returns a PNG image.", inputSchema: { type: "object", properties: { serial: { type: "string" } } } },
@@ -238,8 +266,8 @@ const TOOLS = [
{ name: "tap_text", description: "Tap visible Android text or an accessibility label, then use read_screen to verify.", inputSchema: { type: "object", properties: { text: { type: "string" }, exact: { type: "boolean" }, index: { type: "integer", minimum: 0 }, serial: { type: "string" } }, required: ["text"] } },
{ name: "tap", description: "Tap Android screen pixel coordinates obtained from read_screen or screenshot.", inputSchema: { type: "object", properties: { x: { type: "number" }, y: { type: "number" }, serial: { type: "string" } }, required: ["x", "y"] } },
{ name: "swipe", description: "Swipe the Android screen in a direction, then use read_screen to verify.", inputSchema: { type: "object", properties: { direction: { type: "string", enum: ["up", "down", "left", "right"] }, serial: { type: "string" } }, required: ["direction"] } },
- { name: "type_text", description: "Type basic ASCII text into the focused Android field. Never enter passwords or payment details. A one-time code only for a sign-in the person asked for, into the app it was sent for.", inputSchema: { type: "object", properties: { text: { type: "string", maxLength: 256 }, serial: { type: "string" } }, required: ["text"] } },
- { name: "press", description: "Press an Android navigation or keyboard key.", inputSchema: { type: "object", properties: { key: { type: "string", enum: Object.keys(KEYCODES) }, serial: { type: "string" } }, required: ["key"] } },
+ { name: "type_text", description: "Type text into the focused Android field. Letters, digits, spaces and _.,@- always work; other text, such as Chinese, emoji or +, needs the ADBKeyBoard keyboard selected on the phone. Never enter passwords or payment details. A one-time code only for a sign-in the person asked for, into the app it was sent for.", inputSchema: { type: "object", properties: { text: { type: "string", maxLength: 256 }, serial: { type: "string" } }, required: ["text"] } },
+ { name: "press", description: "Press an Android navigation or keyboard key. wakeup turns the screen on and sleep turns it off.", inputSchema: { type: "object", properties: { key: { type: "string", enum: Object.keys(KEYCODES) }, serial: { type: "string" } }, required: ["key"] } },
] as const;
type ToolResult = { content: Array<{ type: "text"; text: string } | { type: "image"; data: string; mimeType: string }>; isError?: boolean };
@@ -298,10 +326,9 @@ async function callTool(name: string, args: Json): Promise<ToolResult> {
if (name === "open_app") {
const appName = String(args.name ?? "").trim();
if (!appName) throw new Error("name is required");
- const matches = findPackages(appName, await launchablePackages(serial));
- if (matches.length !== 1) throw new Error(matches.length ? `App name is ambiguous: ${matches.join(", ")}` : `No installed launchable app matches ${JSON.stringify(appName)}`);
- await onDevice(serial, ["shell", "monkey", "-p", matches[0], "-c", "android.intent.category.LAUNCHER", "1"]);
- return textResult(`Opened ${appName} (${matches[0]})`);
+ const target = launchTarget(appName, await launchablePackages(serial));
+ await onDevice(serial, ["shell", "monkey", "-p", target, "-c", "android.intent.category.LAUNCHER", "1"]);
+ return textResult(`Opened ${appName} (${target})`);
}
if (name === "tap_text") {
const query = String(args.text ?? "").trim().toLowerCase();
@@ -341,12 +368,7 @@ async function callTool(name: string, args: Json): Promise<ToolResult> {
await onDevice(serial, ["shell", "input", "swipe", ...point.map((value) => String(Math.round(value))), "260"]);
return textResult(`Swiped ${direction}`);
}
- if (name === "type_text") {
- const value = String(args.text ?? "");
- if (!value || value.length > 256 || !SAFE_TEXT.test(value)) throw new Error("Android text supports only basic ASCII text up to 256 characters");
- await onDevice(serial, ["shell", "input", "text", value.replaceAll(" ", "%s")]);
- return textResult("Typed text into the focused Android field");
- }
+ if (name === "type_text") return textResult(await typePhoneText(deviceShell(serial), String(args.text ?? "")));
if (name === "press") {
const key = String(args.key ?? "").toLowerCase();
if (!KEYCODES[key]) throw new Error("Unsupported Android key");
diff --git a/skills/phone-harness/SKILL.md b/skills/phone-harness/SKILL.md
index e95a2399f0..006ef98fb1 100644
--- a/skills/phone-harness/SKILL.md
+++ b/skills/phone-harness/SKILL.md
@@ -9,13 +9,17 @@ Use the `phone` tools for every requested Android action. Never replace them
with Bash, raw `adb`, `subprocess`, an emulator, network ADB, or Tailscale.
1. Call `status` before the first action. If the device is missing or
- unauthorized, stop and relay the physical setup instruction.
+ unauthorized, stop and relay the physical setup instruction. If the screen
+ is off, press `wakeup`; on a swipe lock screen, swipe up. If it asks for a
+ PIN, pattern, or password, stop and ask the user to unlock the phone.
2. Call `open_app` with the human app name. Do not scan the launcher first.
- Use `list_apps` only when the name is ambiguous.
+ Use `list_apps` only when the name is ambiguous or not found, then pass the
+ package name.
3. Call `read_screen` before choosing a target and after every action. Prefer
`tap_text`; use `screenshot` and pixel `tap` only when accessibility text
cannot identify the target.
4. Use `swipe`, `type_text`, and `press` for interaction, verifying each step.
+ If you woke the screen, press `sleep` when the task is done.
The tools operate the user's real phone. Navigate and read only what the task
needs. Stop before sending, posting, purchasing, booking, deleting, changing