software-factory
MAmattpocock/skills336k4,217 new stars in the last 7 days
Use a phone (a cloud Android or an iPhone) through computer_observe, computer_act, computer_screenshot and a codemode script's `computer`. It covers reading the screen's elements, acting on them by ref, running known steps as one script, checking what happened, recovering, and what a phone cannot do. Use when a run has a phone and the task needs its screen or apps.
The run has a phone, a real one, rented while the run lives. Where it lists its elements (the ui group, an Android's
today), you read the screen as lines of elements and act on them by their refs. Where it doesn't (an iPhone today), you
see it through screenshots and act with one finger at their pixels. The tools say which one you have.
computer_observe {app?, image?, full?} shows the app in front as compact lines, one per element:
state s2 · com.android.settings "Settings" · window 360×800 pt
@e1 generic
@e3 searchbox "Search settings"
@e5 button "Network & internet"
@e9 button "About phone"
Each line is a ref (@e5), a role, a name, a value after =, what else the element says in parentheses (a row's
second line: ("Mobile, Wi-Fi, hotspot")) and flags in brackets. A child is indented under its parent. The head line names the state. image: true adds a screenshot, for what the elements can't tell you:
layout, images, colours. Without the ui group, observe is the screenshot.
computer_act {steps, state?, expect?, observe?} runs steps in order:
| Step | What it does |
|---|---|
{press: "@e9"} | The element's own tap. The surest step. |
{set: "@e3", value: "wifi"} | Sets a field's text, or a switch's "on" or "off". |
{click: "@e9"} or {click: [x, y]} | A tap; button: "right" is a long press. |
{type: "text", into?: "@e3"} | Types, into the element when named, else into the field in focus. |
{nav: "back"}, {nav: "home"}, {nav: "app_switch"} | The system's own navigation. |
{scroll: [180, 420], dy: 600}, with foreground: true on the call | Swipes from that point: dy above 0 shows what is below. A swipe is the phone's own input, refused unless the call passes foreground: true. |
{drag: [[x1, y1], [x2, y2]], ms?} | One finger along the path. |
{key: "enter"} | A key, where the phone has keys. |
Each step answers its route and whether a readback verified it; the answer ends with whether the screen changed and its
new state. expect: {text: "Device name"} waits after the steps until that text shows (gone: true: until it is
gone). observe: true adds the new outline: one call instead of two. The first refused step stops the rest.
Prefer refs. A step at a point is read against a state and refused as stale once the screen moved under it:
observe again and use the new state. Without the ui group, points are screenshot pixels and there are no refs,
states or expects.
computer_screenshot {region?} is the whole screen, or region: [x, y, w, h] of it, in pixels.
Scripts: codemode. A codemode script has the phone as computer, and codemode's description gives its types
for this phone. The body is an async function: await the calls and return what you need. Each call is a call of its
own, asked about and recorded like the tools'.
await computer.apps.open("com.android.settings");
const settings = computer.app("com.android.settings");
await settings.observe();
for (let i = 0; i < 4 && !settings.find({ text: "About phone" })[0]; i++) {
await settings.scroll([180, 420], { dy: 600 }, { foreground: true });
await settings.observe();
}
const about = settings.find({ text: "About phone" })[0];
const page = await settings.press(about.ref, { expect: { text: "Device name" }, observe: true });
return { met: page.expect, lines: page.after.outline.split("\n").filter((line) => /name/i.test(line)) };
An expect is met only by what shows on the screen: a row below the fold is not there until you scroll to it.
App ids come from computer.apps.list(): call it before computer.apps.open. The tools are there too, as
tools.computer_observe(...) and tools.computer_act(...).
On Codex there is no codemode and no computer: Codex runs scripts in its own code mode, which calls the tools in
your list. Codex's exec has no top-level return (it is a SyntaxError there, and nothing runs): a script's output goes
through text(...). The phone's apps are computer_op there, one call per op with its arguments, named as computer's methods
are: computer_op({op: "apps.open", args: {id: "com.android.settings"}}). Every answer is text, and a failed op never
throws: an op that ran answers JSON, so JSON.parse it. A refused op answers the gate's words, which open with
Permission denied: or The user denied this, or give the tool's name then is read-only for this agent, so this call was refused: or can't be called:. A failed op answers its error's words. Neither is JSON: check before you parse.
The screen itself. Prefer an app's steps. A script's computer.input.act([...]) is the screen-level way out, at
screenshot pixels, for what the app's window can't reach: a swipe from the screen's top edge opens the notification
shade ({ type: "swipe", path: [[540, 5], [540, 1200]] }), and anything outside the app.
Only what you were given. An agent's computer setting may leave some out: a code-only agent drives the phone from
codemode alone, with no computer_observe, computer_act or computer_screenshot in its tool list; an agent whose
exec is off has no shell of any kind. Use what your tool list and codemode's types show.
expect
on it for what the next screen shows.changed and the expect. When it doesn't settle it, observe again.stale: observe again. Nothing changed: a dialog, the keyboard or a banner may cover the target.
{nav: "back"} closes what covers it; computer.apps.open(id) in a script starts an app afresh on its first
screen, the surest way back to a known place.A codemode script is one call of yours where tools would be many.
expect on each page.find() inside the script and return only those, never whole observations.
find({ role, text, id }): a role is the same name on every phone, a text matches the name, the value or what the
parentheses say, and an id is the app's own (an Android resource-id).When you are unsure what is on the screen, observe before you act, and decide from what it shows.
{nav: "back"} closes it.Say in your answer what the task needed that the phone could not do.
Errors come in words, and they say what was wrong. Read them, act on what they say, and don't repeat the same call.
unsupported names what this phone can't do (an element step without the ui group, a key
on a phone with no keys). Use another step.The phone may be billed by the minute and lives only for the run's lifetime. Plan first (which app, which screens, what will show success), script what is certain, and stop once the task is done or can't be done.
Before you call the task done, check the result with an observe (or a screenshot when it is visual). Say what it shows in your answer, and name anything you could not finish or check.
MAmattpocock/skills336k4,217 new stars in the last 7 days
MAmattpocock/skills336k4,217 new stars in the last 7 days
AFaffaan-m/ECC314k3,503 new stars in the last 7 days
AFaffaan-m/ECC314k3,503 new stars in the last 7 days
AFaffaan-m/ECC314k3,503 new stars in the last 7 days
DIDietrichGebert/ponytail202k4,226 new stars in the last 7 days