Skip to content

Let an AI model use a real iPhone with a $7 ESP32: AirPlay eyes, USB HID hands, any OpenAI-compatible vision model. No Mac, no developer account, no jailbreak.

ui: red tap marker with ripple, motion switch, inline calibration hints

Henry94396fdab219
diff --git a/server/hidagent/static/app.js b/server/hidagent/static/app.js
index b1184b4..c519171 100644
--- a/server/hidagent/static/app.js
+++ b/server/hidagent/static/app.js
@@ -19,6 +19,7 @@ function applyLang() {
return b;
}));
shown = ""; // re-render steps in the new language
+ if (typeof applyMotion === "function") applyMotion();
}
document.querySelectorAll("#lang button").forEach((b) => b.addEventListener("click", () => {
lang = b.dataset.lang;
@@ -26,6 +27,20 @@ document.querySelectorAll("#lang button").forEach((b) => b.addEventListener("cli
applyLang();
}));
+// ---- motion (tap ripples, flowing swipe paths); remembered per browser -------------------
+
+let motion = !matchMedia("(prefers-reduced-motion: reduce)").matches;
+try { motion = (localStorage.getItem("motion") || (motion ? "on" : "off")) === "on"; } catch { /* private mode */ }
+function applyMotion() {
+ document.body.classList.toggle("still", !motion);
+ $("motion").textContent = t(motion ? "motionOn" : "motionOff");
+}
+$("motion").addEventListener("click", () => {
+ motion = !motion;
+ try { localStorage.setItem("motion", motion ? "on" : "off"); } catch { /* private mode */ }
+ applyMotion();
+});
+
const say = (key) => { $("msg").textContent = key ? t(key) : ""; };
async function post(path, body) {
const r = await fetch(path, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify(body || {}) });
@@ -45,11 +60,12 @@ const why = (s) => (lang === "zh" && s.thought_zh) || s.thought || s.answer || s
const planText = (s) => (lang === "zh" && s.plan_zh) || s.plan || "";
const times = (s) => [s.think_s != null && `${t("thinking")} ${fmt(s.think_s)}`, s.act_s != null && `${t("doing")} ${fmt(s.act_s)}`].filter(Boolean).join(" · ");
const where = (s) => ({
- tap: () => ` (${s.x}, ${s.y})`, swipe: () => ` (${s.x1}, ${s.y1}) → (${s.x2}, ${s.y2})`,
+ tap: () => ` (${s.x}, ${s.y})${s.precise ? " · precise" : ""}`, swipe: () => ` (${s.x1}, ${s.y1}) → (${s.x2}, ${s.y2})`,
path: () => ` · ${s.points.length} pts`, circle: () => ` (${s.x}, ${s.y}) r=${s.r}`,
}[s.action] || (() => ""))();
// Draw what the AI did on its screenshot (coordinates are 0-1000): yellow on black, plus a hand for taps.
+// .ripple and .flow shapes are animated in CSS; body.still turns the motion off.
let aspect = 0.461; // frame width / height, from the server
function overlay(s) {
const svg = (inner) => `<svg viewBox="0 0 1000 1000" preserveAspectRatio="none">${inner}</svg>`;
@@ -58,17 +74,22 @@ function overlay(s) {
${shape.replace("/>", ` style="stroke:var(--hl);fill:none" stroke-width="5" vector-effect="non-scaling-stroke" stroke-linecap="round" stroke-linejoin="round"/>`)}`;
const dot = (x, y, r) => `<ellipse cx="${x}" cy="${y}" rx="${r}" ry="${r * aspect}" style="fill:var(--hl);stroke:#000" stroke-width="2" vector-effect="non-scaling-stroke"/>`;
const pts = (list) => list.map(([x, y]) => `${x},${y}`).join(" ");
+ const flow = (list) => // dashes that travel along the stroke, in its direction
+ `<polyline class="flow" points="${pts(list)}" style="stroke:#000;fill:none" stroke-width="2.5" vector-effect="non-scaling-stroke" stroke-linecap="round"/>`;
switch (s.action) {
- case "tap":
- return svg(stroke(`<ellipse cx="${s.x}" cy="${s.y}" rx="70" ry="${70 * aspect}"/>`) + dot(s.x, s.y, 16));
+ case "tap": { // red, so the tap point stands out from the yellow swipe paths
+ const ring = (cls, r, w, color) => `<ellipse class="${cls}" cx="${s.x}" cy="${s.y}" rx="${r}" ry="${r * aspect}" style="stroke:${color};fill:none" stroke-width="${w}" vector-effect="non-scaling-stroke"/>`;
+ return svg(ring("ripple", 100, 7, "var(--tap)") + ring("", 100, 11, "#000") + ring("", 100, 6, "var(--tap)") +
+ `<ellipse cx="${s.x}" cy="${s.y}" rx="22" ry="${22 * aspect}" style="fill:var(--tap);stroke:#fff" stroke-width="3" vector-effect="non-scaling-stroke"/>`);
+ }
case "swipe": {
const a = Math.atan2((s.y2 - s.y1) / aspect, s.x2 - s.x1), l = 45;
const head = (d) => [s.x2 - l * Math.cos(a + d), s.y2 - l * aspect * Math.sin(a + d)];
- return svg(stroke(`<polyline points="${pts([[s.x1, s.y1], [s.x2, s.y2]])}"/>`) +
+ return svg(stroke(`<polyline points="${pts([[s.x1, s.y1], [s.x2, s.y2]])}"/>`) + flow([[s.x1, s.y1], [s.x2, s.y2]]) +
stroke(`<polyline points="${pts([head(0.5), [s.x2, s.y2], head(-0.5)])}"/>`) + dot(s.x1, s.y1, 14));
}
case "path":
- return svg(stroke(`<polyline points="${pts(s.points)}"/>`) + dot(...s.points[0], 12));
+ return svg(stroke(`<polyline points="${pts(s.points)}"/>`) + flow(s.points) + dot(...s.points[0], 12));
case "circle":
return svg(stroke(`<ellipse cx="${s.x}" cy="${s.y}" rx="${s.r}" ry="${s.r * aspect}"/>`));
default:
@@ -154,7 +175,8 @@ live.addEventListener("pointerup", async (e) => {
down = null;
if (calibrating) {
calibrating = false;
- if (await post("/api/calibrate/finish", up)) say("calOk");
+ const ok = await post("/api/calibrate/finish", up);
+ calibrationHint(ok ? "calOk" : null);
} else if (Math.hypot(up.x - from.x, up.y - from.y) < 0.02) {
post("/api/tap", up);
} else {
@@ -189,7 +211,21 @@ async function refreshLive() {
// ---- controls ------------------------------------------------------------------------
document.querySelectorAll("[data-post]").forEach((b) => b.addEventListener("click", () => post(b.dataset.post)));
-$("cal").addEventListener("click", async () => { if (await post("/api/calibrate/start")) { calibrating = true; say("calNow"); } });
+// Calibration instructions show right under the phone, where the user is looking.
+function calibrationHint(key) {
+ $("caption").textContent = t(key || "liveCaption");
+ $("caption").classList.toggle("callout", Boolean(key));
+ live.parentElement.classList.toggle("calibrating", key === "calNow");
+ if (key === "calOk") setTimeout(() => calibrationHint(null), 4000);
+}
+$("cal").addEventListener("click", async () => {
+ calibrationHint("calFinding");
+ const r = await post("/api/calibrate/start");
+ if (!r) return calibrationHint(null);
+ if (r.auto) return calibrationHint("calOk"); // found the pointer by itself
+ calibrating = true;
+ calibrationHint("calNow");
+});
$("type").addEventListener("click", async () => { if (await post("/api/type", { text: $("text").value })) $("text").value = ""; });
$("press").addEventListener("click", () => post("/api/key", { text: $("key").value }));
function start(task) {
@@ -198,7 +234,9 @@ function start(task) {
}
$("run").addEventListener("click", () => start($("task").value.trim()));
$("stop").addEventListener("click", () => post("/api/agent/stop"));
-$("clear").addEventListener("click", () => post("/api/agent/clear"));
+$("clear").addEventListener("click", async () => {
+ if (await post("/api/agent/clear")) { $("task").value = ""; say(null); }
+});
$("estop").addEventListener("click", () => post("/api/agent/stop"));
document.addEventListener("keydown", (e) => { if (e.key === "Escape" && !$("zoom").open) post("/api/agent/stop"); });
@@ -261,5 +299,6 @@ async function poll() {
}
applyLang();
+applyMotion();
refreshLive();
poll();
diff --git a/server/hidagent/static/i18n.js b/server/hidagent/static/i18n.js
index d562ec9..39dba45 100644
--- a/server/hidagent/static/i18n.js
+++ b/server/hidagent/static/i18n.js
@@ -2,7 +2,7 @@
const I18N = {
en: {
waiting: "Waiting for the phone screen…", liveCaption: "Live screen · click to tap, drag to swipe",
- estop: "■ Emergency stop (Esc)", estopHint: "Stops the AI and lets go of the screen",
+ estop: "■ Emergency stop (Esc)", motionOn: "Motion: on", motionOff: "Motion: off", estopHint: "Stops the AI and lets go of the screen",
clear: "Clear history",
manual: "Manual controls", home: "Home", back: "Back", calibrate: "Calibrate", type: "Type", press: "Press",
typePh: "Type text", keyPh: "Key: enter, cmd+a…", log: "Live log",
@@ -13,14 +13,15 @@ const I18N = {
taskPh: "e.g. Open Whiteboard and draw a smiley face", start: "Start", stop: "Stop",
status: "status", actions: "actions", total: "total time", perAction: "per action", plan: "Plan",
idle: "Idle", working: "Working…", done: "Done", gaveUp: "Gave up", stopped: "Stopped", errorState: "Error",
- calNow: "Now click exactly on the round pointer in the live screen.", calOk: "Calibrated. You're ready.",
+ calNow: "Now click exactly on the round pointer in the live screen.", calFinding: "Finding the pointer…", calOk: "Calibrated. You're ready.",
needTask: "Describe what the phone should do first.", thinking: "thinking", doing: "doing",
step: "Step", planner: "Planner", decision: "Decision · planner", executor: "Action · actor", avg: "avg",
- examples: ["Open Settings and go to Wi-Fi", "Open Whiteboard and draw a smiley face", "Open Notes and write \"hello\""],
+ examples: ["Set an alarm for 7:00 AM that repeats every day (check all days under Repeat), then save it", "Open Whiteboard and draw a smiley face",
+ "Open Settings and go to Wi-Fi", "Open Notes and write \"hello\""],
},
zh: {
waiting: "等待手机画面…", liveCaption: "实时画面 · 点击 = 点按,拖动 = 滑动",
- estop: "■ 紧急停止(Esc)", estopHint: "立即停止 AI,并松开屏幕",
+ estop: "■ 紧急停止(Esc)", motionOn: "动效:开", motionOff: "动效:关", estopHint: "立即停止 AI,并松开屏幕",
clear: "清空记录",
manual: "手动操控", home: "主屏幕", back: "返回", calibrate: "校准", type: "输入", press: "按键",
typePh: "输入文字", keyPh: "按键:enter、cmd+a…", log: "实时日志",
@@ -31,10 +32,10 @@ const I18N = {
taskPh: "例如:打开白板画一个笑脸", start: "开始", stop: "停止",
status: "状态", actions: "动作数", total: "总用时", perAction: "每步", plan: "计划",
idle: "空闲", working: "进行中…", done: "完成", gaveUp: "放弃", stopped: "已停止", errorState: "出错",
- calNow: "现在在实时画面里精确点一下圆形指针。", calOk: "校准完成,可以开始了。",
+ calNow: "现在在实时画面里精确点一下圆形指针。", calFinding: "正在找指针…", calOk: "校准完成,可以开始了。",
needTask: "先写一下要让手机做什么。", thinking: "思考", doing: "执行",
step: "第", planner: "规划", decision: "决策 · 规划模型", executor: "执行 · 动作模型", avg: "平均",
- examples: ["打开设置,进入 Wi-Fi", "打开白板画一个笑脸", "打开备忘录写 hello"],
+ examples: ["设置早上 7:00 的闹钟,在「重复」里把每一天都勾上,然后保存", "打开白板画一个笑脸", "打开设置,进入 Wi-Fi", "打开备忘录写 hello"],
},
};
diff --git a/server/hidagent/static/index.html b/server/hidagent/static/index.html
index b337236..87ec997 100644
--- a/server/hidagent/static/index.html
+++ b/server/hidagent/static/index.html
@@ -14,7 +14,7 @@
<img id="live" alt="">
<div class="hint" id="hint" data-i18n="waiting"></div>
</div>
- <p class="caption" data-i18n="liveCaption"></p>
+ <p class="caption" id="caption" data-i18n="liveCaption"></p>
<button class="estop" id="estop" data-i18n="estop"></button>
<p class="caption" data-i18n="estopHint"></p>
<details class="manual">
@@ -39,6 +39,7 @@
<div><span data-i18n="decision"></span><b id="m-planner"></b><small id="m-planner-s"></small></div>
<div><span data-i18n="executor"></span><b id="m-actor"></b><small id="m-actor-s"></small></div>
</div>
+ <button class="motion" id="motion"></button>
<div class="lang" id="lang"><button data-lang="en">EN</button><button data-lang="zh">中文</button></div>
</header>
diff --git a/server/hidagent/static/style.css b/server/hidagent/static/style.css
index ef09346..dfbdb55 100644
--- a/server/hidagent/static/style.css
+++ b/server/hidagent/static/style.css
@@ -1,6 +1,6 @@
:root {
--bg: #fff; --fg: #111; --muted: #777; --line: #e6e6e6; --soft: #f6f6f6;
- --mark: #ff3b30; --ok: #1a7f37; --hl: #ffd400;
+ --mark: #ff3b30; --ok: #1a7f37; --hl: #ffd400; --tap: #ff1f1f;
}
@media (prefers-color-scheme: dark) {
:root { --bg: #0d0d0d; --fg: #eee; --muted: #888; --line: #262626; --soft: #171717; --ok: #3fb950; }
@@ -25,17 +25,20 @@ main { display: grid; grid-template-columns: auto minmax(300px, 1fr) minmax(420p
.col:last-child { border-right: 0; }
/* 1. phone */
-.phone { display: flex; flex-direction: column; align-items: center; gap: 10px; overflow: hidden; }
+.phone { display: flex; flex-direction: column; align-items: center; gap: 10px; overflow-y: auto; }
.screen { position: relative; height: calc(100vh - 165px); aspect-ratio: 498 / 1080; flex: none;
background: var(--soft); border: 9px solid var(--fg); border-radius: 42px; overflow: hidden; touch-action: none; }
.screen img { width: 100%; height: 100%; object-fit: contain; display: block; cursor: crosshair; user-select: none; -webkit-user-drag: none; }
.hint { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--muted); pointer-events: none; }
.caption { color: var(--muted); font-size: 12px; margin: 0; }
+.caption.callout { color: #000; background: var(--hl); font-size: 14px; font-weight: 600; padding: 6px 12px; border-radius: 8px; }
+.screen.calibrating { border-color: var(--hl); }
.estop { width: 100%; background: var(--mark); color: #fff; border-color: var(--mark); font-weight: 600; padding: 10px; }
.estop:hover { border-color: var(--fg); }
.manual { width: 100%; color: var(--muted); }
.manual summary { cursor: pointer; text-align: center; }
.manual .row { margin-top: 8px; }
+.phone:has(.manual[open]) .screen { height: calc(100vh - 330px); } /* make room for the controls */
/* 2. log */
.log { display: flex; flex-direction: column; padding: 0; }
@@ -61,8 +64,20 @@ main { display: grid; grid-template-columns: auto minmax(300px, 1fr) minmax(420p
.models span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.models b { font-size: 13px; white-space: nowrap; }
.models small { font: 11px ui-monospace, monospace; color: var(--muted); }
-.hand { position: absolute; transform: translate(-30%, -8%); font-size: 22px; line-height: 1; filter: drop-shadow(0 1px 1px #000); }
-dialog .hand { font-size: 44px; }
+.hand { position: absolute; transform: translate(-30%, -8%); font-size: 34px; line-height: 1;
+ filter: drop-shadow(0 0 2px #000) drop-shadow(0 2px 2px #000); animation: press 1.4s ease-in-out infinite; }
+dialog .hand { font-size: 72px; }
+.motion { font-size: 12px; padding: 4px 10px; flex: none; }
+
+/* motion: a ripple spreads from each tap, dashes travel along swipes and strokes */
+.ripple { transform-box: fill-box; transform-origin: center; animation: ripple 1.4s ease-out infinite; }
+.flow { stroke-dasharray: 6 10; animation: flow 0.8s linear infinite; }
+@keyframes ripple { from { transform: scale(0.5); opacity: 1; } to { transform: scale(2.6); opacity: 0; } }
+@keyframes flow { to { stroke-dashoffset: -16; } }
+@keyframes press { 0%, 100% { transform: translate(-30%, -8%); } 45% { transform: translate(-30%, -20%) scale(1.06); } }
+body.still .ripple { animation: none; opacity: 0; }
+body.still .flow { animation: none; stroke-dasharray: none; opacity: 0; }
+body.still .hand { animation: none; }
.lang button { border-radius: 0; padding: 4px 10px; font-size: 12px; }
.lang button:first-child { border-radius: 8px 0 0 8px; }
.lang button:last-child { border-radius: 0 8px 8px 0; border-left: 0; }