let your agent control your phone
OpenClaw plugin 0.1.2: confirm a Windows stop before freeing the phone (PHO-99) (#175)
shawn pana792632fb23a8
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex 69772c6..7802ff6 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -11,7 +11,11 @@ env:jobs:openclaw-plugin:- runs-on: ubuntu-latest+ strategy:+ fail-fast: false+ matrix:+ os: [ubuntu-latest, windows-latest]+ runs-on: ${{ matrix.os }}defaults:run:working-directory: integrations/openclawdiff --git a/integrations/openclaw/README.md b/integrations/openclaw/README.mdindex d45023b..c1e9783 100644--- a/integrations/openclaw/README.md+++ b/integrations/openclaw/README.md@@ -37,13 +37,13 @@ To install from a checkout instead:git clone https://github.com/phone-harness/phone-harnesscd phone-harness/integrations/openclawnpm install --ignore-scripts && npm pack-openclaw plugins install npm-pack:./phone-harness-0.1.1.tgz+openclaw plugins install npm-pack:./phone-harness-0.1.2.tgz```To use a cloud phone, sign in once on the Gateway machine:```bash-uvx phone-harness cloud login+uvx --from phone-harness==0.3.3 phone-harness cloud login```Phone Harness chooses the phone: an attached cloud phone, otherwise its default.@@ -124,10 +124,14 @@ prompts, so a sender it knows is not the owner is refused before any prompt.script's process tree, including processes in their own session or processgroup, every process that carries the tag or was noted, even after its parentexits, and their process groups, and repeats until none is left, for up to five- seconds. The phone is free again only then. On Windows, the process tree is- killed. A process that detaches before the plugin notes it can outlive the call- if it drops the tag, or on macOS if it is one of Apple's own programs, whose- environment macOS hides.+ seconds. The phone is free again only then. On Windows, the plugin lists the+ script's process tree, runs `taskkill` on it, waits for it to finish, and checks+ that the script and every process that was under it are gone. If a stop cannot+ be confirmed, the result says so and the phone stays reserved until it can be.+ A process that detaches before the plugin notes it can outlive the call if it+ drops the tag, or on macOS if it is one of Apple's own programs, whose+ environment macOS hides. On Windows, a process whose parent has already exited+ is no longer in the tree.## What it touches@@ -156,9 +160,11 @@ npm test```The Phone Harness release is pinned on one line: `PHONE_HARNESS_VERSION` at the-top of `src/phone-exec.ts`. `classifier.py` is the Hermes plugin's classifier, and-`tests/test_openclaw_plugin.py` keeps the two identical.+top of `src/phone-exec.ts`. The `uvx` commands in this README name the same+release, and `tests/test_openclaw_plugin.py` checks that they do. `classifier.py`+is the Hermes plugin's classifier, and the same tests keep the two identical.Phone Harness sends usage data, including scripts and what they print, to PostHog.To turn it off, set `DO_NOT_TRACK=1` in the Gateway's environment, or run-`uvx phone-harness config set telemetry false` as the user the Gateway runs as.+`uvx --from phone-harness==0.3.3 phone-harness config set telemetry false` as the+user the Gateway runs as.diff --git a/integrations/openclaw/package-lock.json b/integrations/openclaw/package-lock.jsonindex f8da4e8..cc6ea64 100644--- a/integrations/openclaw/package-lock.json+++ b/integrations/openclaw/package-lock.json@@ -1,12 +1,12 @@{"name": "phone-harness",- "version": "0.1.1",+ "version": "0.1.2","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "phone-harness",- "version": "0.1.1",+ "version": "0.1.2","license": "MIT","dependencies": {"typebox": "1.3.37"diff --git a/integrations/openclaw/package.json b/integrations/openclaw/package.jsonindex 58b83e2..7ffe283 100644--- a/integrations/openclaw/package.json+++ b/integrations/openclaw/package.json@@ -1,6 +1,6 @@{"name": "phone-harness",- "version": "0.1.1",+ "version": "0.1.2","description": "Lets OpenClaw use a real phone: scroll, tap, type, and read the screen, with no jailbreak and nothing installed on the phone.","type": "module","license": "MIT",diff --git a/integrations/openclaw/scripts/build-skill.mjs b/integrations/openclaw/scripts/build-skill.mjsindex b9eb0c0..0985dfd 100644--- a/integrations/openclaw/scripts/build-skill.mjs+++ b/integrations/openclaw/scripts/build-skill.mjs@@ -6,7 +6,8 @@ import { dirname, join } from "node:path";import { fileURLToPath } from "node:url";const here = dirname(fileURLToPath(import.meta.url));-const guide = readFileSync(join(here, "..", "..", "..", "SKILL.md"), "utf8");+// A Windows checkout can turn line endings into CRLF; the built skill is the same everywhere.+const guide = readFileSync(join(here, "..", "..", "..", "SKILL.md"), "utf8").replace(/\r\n/g, "\n");const body = guide.replace(/^---\n[\s\S]*?\n---\n+/, "");if (body === guide) throw new Error("SKILL.md has no frontmatter to replace");diff --git a/integrations/openclaw/src/phone-exec.test.ts b/integrations/openclaw/src/phone-exec.test.tsindex 4754c2b..dcdcde4 100644--- a/integrations/openclaw/src/phone-exec.test.ts+++ b/integrations/openclaw/src/phone-exec.test.ts@@ -14,8 +14,13 @@ import {PHONE_HARNESS_VERSION,PhoneLock,pinnedCommand,+ stopRun,+ stopTreeWindows,+ windowsTree,type Env,+ type RunRecord,type ToolResult,+ type WindowsStopDeps,} from "./phone-exec.ts";const NODE = { file: process.execPath, args: ["-"] };@@ -48,6 +53,7 @@ function alive(pid: number): boolean {} catch {return false;}+ if (process.platform === "win32") return true;// A killed process can sit as a zombie until its new parent reaps it. It is not running.try {return !execFileSync("ps", ["-o", "stat=", "-p", String(pid)], { encoding: "utf8" }).trim().startsWith("Z");@@ -207,7 +213,8 @@ describe("a script past its timeout", () => {const result = await run("setInterval(() => {}, 1000)", { signal: controller.signal });assert.equal(result.details.ok, false);assert.match(String(result.details.error), /cancelled/);- assert.ok(Date.now() - started < 5000);+ // Windows lists processes through PowerShell before and after taskkill, which takes longer.+ assert.ok(Date.now() - started < (process.platform === "win32" ? 15_000 : 5000));});});@@ -255,6 +262,162 @@ describe("a cancelled call", () => {});});+describe("an unconfirmed stop", () => {+ it("keeps the phone reserved until every process is confirmed gone", { timeout: 60_000 }, async () => {+ const lock = new PhoneLock();+ let calls = 0;+ // The real stop runs, but the first two report that something may be left.+ const stop = async (record: RunRecord) => {+ await stopRun(record);+ calls += 1;+ return calls > 2;+ };+ const controller = new AbortController();+ setTimeout(() => controller.abort(), 200);+ const result = await phoneExec(+ { code: "setInterval(() => {}, 1000)" },+ { env: { PATH: process.env.PATH }, workspace, command: NODE, lock, signal: controller.signal, stop, confirmEveryMs: 50 },+ );+ assert.match(String(result.details.error), /could be confirmed stopped, so the phone stays reserved/);+ assert.equal(result.details.stopConfirmed, false);+ assert.equal(await lock.acquire(0), false, "the phone was freed before the stop was confirmed");+ let freed = false;+ for (let i = 0; i < 100 && !freed; i++) {+ freed = await lock.acquire(0);+ if (!freed) await new Promise((resolve) => setTimeout(resolve, 50));+ }+ assert.equal(freed, true, "the phone was not freed once the stop was confirmed");+ assert.ok(calls >= 3);+ });+});++describe("stopping on Windows", () => {+ // The logic, with a stand-in for Windows, so it is tested on every platform.+ type Fake = { procs: Map<number, { ppid: number; created: number }>; calls: string[]; deps: WindowsStopDeps };++ function fake(options: { dies?: (pid: number) => boolean; taskkillCode?: number | null; list?: boolean } = {}): Fake {+ const procs = new Map([+ [100, { ppid: 1, created: 10 }], // the runner+ [101, { ppid: 100, created: 20 }],+ [102, { ppid: 101, created: 30 }],+ [200, { ppid: 1, created: 5 }], // not part of the run+ ]);+ const calls: string[] = [];+ const dies = options.dies ?? (() => true);+ const deps: WindowsStopDeps = {+ snapshot: async () => {+ calls.push("snapshot");+ return options.list === false ? null : new Map(procs);+ },+ taskkill: async (args) => {+ await new Promise((resolve) => setTimeout(resolve, 20));+ const pid = Number(args.at(-1));+ calls.push(`taskkill ${args.join(" ")}`);+ const tree = args.includes("/T") ? [...windowsTree(pid, procs).keys()] : [pid];+ for (const each of tree) if (dies(each)) procs.delete(each);+ return options.taskkillCode === undefined ? 0 : options.taskkillCode;+ },+ terminate: (pid) => {+ calls.push(`terminate ${pid}`);+ if (dies(pid)) procs.delete(pid);+ },+ rootRunning: () => procs.has(100),+ deadlineMs: 300,+ pauseMs: 10,+ };+ return { procs, calls, deps };+ }++ it("waits for taskkill, then confirms the tree is gone", async () => {+ const { procs, calls, deps } = fake();+ assert.equal(await stopTreeWindows(100, deps), true);+ assert.deepEqual(calls, ["snapshot", "taskkill /T /F /PID 100", "snapshot"]);+ assert.deepEqual([...procs.keys()], [200], "only the process outside the run is left");+ });++ it("goes after a process left under the runner, and fails closed if it will not go", async () => {+ const stubborn = fake({ dies: (pid) => pid !== 102 });+ assert.equal(await stopTreeWindows(100, stubborn.deps), false);+ assert.ok(stubborn.calls.includes("taskkill /T /F /PID 102"));+ let hits = 0;+ const late = fake({ dies: (pid) => pid !== 102 || ++hits > 1 }); // 102 survives the first taskkill only+ assert.equal(await stopTreeWindows(100, late.deps), true);+ assert.ok(late.calls.includes("taskkill /T /F /PID 102"));+ });++ it("never targets a pid that now belongs to a different process", async () => {+ const { procs, calls, deps } = fake({ dies: (pid) => pid !== 102 });+ deps.taskkill = async (args) => {+ calls.push(`taskkill ${args.join(" ")}`);+ for (const pid of [100, 101, 102]) procs.delete(pid);+ procs.set(102, { ppid: 1, created: 99 }); // 102 ended and was reused by a stranger+ return 0;+ };+ assert.equal(await stopTreeWindows(100, deps), true);+ assert.deepEqual(calls.filter((call) => call.startsWith("taskkill")), ["taskkill /T /F /PID 100"]);+ });++ it("ends a process directly when taskkill cannot start", async () => {+ const { procs, calls, deps } = fake({ taskkillCode: null, dies: (pid) => pid === 100 });+ deps.terminate = (pid) => {+ calls.push(`terminate ${pid}`);+ procs.delete(pid);+ };+ assert.equal(await stopTreeWindows(100, deps), true);+ assert.ok(calls.includes("terminate 101") && calls.includes("terminate 102"));+ });++ it("without a process list, needs taskkill to report the runner done", async () => {+ assert.equal(await stopTreeWindows(100, fake({ list: false }).deps), true);+ assert.equal(await stopTreeWindows(100, fake({ list: false, taskkillCode: 1 }).deps), false);+ });++ it("does not adopt a stranger whose parent pid was reused", () => {+ const table = new Map([+ [100, { ppid: 1, created: 10 }],+ [300, { ppid: 100, created: 3 }], // older than 100, so its parent was an earlier holder of the pid+ [301, { ppid: 100, created: 11 }],+ ]);+ assert.deepEqual([...windowsTree(100, table).keys()].sort(), [100, 301]);+ });++ it("on Windows, waits for taskkill and checks the tree is gone before freeing the phone", {+ skip: process.platform !== "win32" && "a real Windows run",+ timeout: 60_000,+ }, async () => {+ const pids = join(dir, "pids");+ const forever = join(dir, "forever.js");+ const middle = join(dir, "middle.js");+ writeFileSync(forever, "setInterval(() => {}, 1000);\n");+ writeFileSync(middle, `+ const child = require("node:child_process").spawn(process.execPath, [${JSON.stringify(forever)}], { stdio: "ignore" });+ require("node:fs").appendFileSync(${JSON.stringify(pids)}, "grandchild " + child.pid + "\\n");+ setInterval(() => {}, 1000);+ `);+ const script = `+ const child = require("node:child_process").spawn(process.execPath, [${JSON.stringify(middle)}], { stdio: "ignore" });+ require("node:fs").appendFileSync(${JSON.stringify(pids)}, "child " + child.pid + "\\n");+ setInterval(() => {}, 1000);+ `;+ const read = () => (existsSync(pids) ? readFileSync(pids, "utf8").trim().split("\n").filter(Boolean) : []);+ const lock = new PhoneLock();+ const controller = new AbortController();+ const running = phoneExec(+ { code: script },+ { env: { ...process.env }, workspace, command: NODE, lock, signal: controller.signal },+ );+ assert.ok(await waitFor(() => read().length === 2, 20_000), "the script started its processes");+ controller.abort();+ const result = await running;+ assert.match(String(result.details.error), /cancelled\. The script was stopped/);+ for (const line of read()) {+ const [name, pid] = line.split(" ");+ assert.equal(alive(Number(pid)), false, `${name} survived`);+ }+ assert.equal(await lock.acquire(0), true, "the phone was not freed");+ });+});+describe("one script at a time", () => {it("runs a second script only after the first", async () => {const lock = new PhoneLock();diff --git a/integrations/openclaw/src/phone-exec.ts b/integrations/openclaw/src/phone-exec.tsindex 254c9e2..4c713ec 100644--- a/integrations/openclaw/src/phone-exec.ts+++ b/integrations/openclaw/src/phone-exec.ts@@ -236,6 +236,8 @@ export class RunRecord {readonly seen = new Map<number, string>();readonly rootPid: number;readonly marker: string;+ /** Whether the runner itself is still running. Its pid is only safe to target until it exits. */+ running: () => boolean = () => true;constructor(rootPid: number, marker: string) {this.rootPid = rootPid;@@ -261,13 +263,12 @@ export class RunRecord {}}-/** Stop every process the run started. Resolves once none is left, or when the rounds run out. */-export async function stopRun(record: RunRecord): Promise<void> {- if (process.platform === "win32") {- // Windows has no process groups or sessions to leave; taskkill /T takes the whole tree.- spawn("taskkill", ["/T", "/F", "/PID", String(record.rootPid)], { stdio: "ignore" }).on("error", () => {});- return;- }+/** Stops a run. True only once every process it started is confirmed gone. */+export type Stopper = (record: RunRecord) => Promise<boolean>;++/** Stop every process the run started. True once none is left; false if some remain when time runs out. */+export async function stopRun(record: RunRecord): Promise<boolean> {+ if (process.platform === "win32") return stopTreeWindows(record.rootPid, { ...windowsStopDeps, rootRunning: record.running });const deadline = Date.now() + KILL_WAIT_MS / 2;for (let round = 0; round < KILL_ROUNDS && Date.now() < deadline; round++) {const table = await processTable();@@ -291,9 +292,112 @@ export async function stopRun(record: RunRecord): Promise<void> {// Already gone.}}- if (targets.size === 0 && round > 0) return;+ if (targets.size === 0 && round > 0) return true;await new Promise((resolve) => setTimeout(resolve, KILL_ROUND_MS));}+ return false;+}++// Windows has no process groups or sessions to leave, and no environment of other processes to read.+// taskkill /T ends a process and the tree under it, found through parent pids.++type WinProc = { ppid: number; created: number };++/** What stopping on Windows needs from the system, so the logic can be tested anywhere. */+export type WindowsStopDeps = {+ /** pid -> parent pid and creation time for every process, or null when Windows cannot list them. */+ snapshot: () => Promise<Map<number, WinProc> | null>;+ /** Run taskkill and wait for it to finish. Its exit code, or null when it could not start. */+ taskkill: (args: string[]) => Promise<number | null>;+ /** End one process directly, the fallback when taskkill cannot. */+ terminate: (pid: number) => void;+ /** Whether the runner is still running. Its pid is never targeted after it exits. */+ rootRunning: () => boolean;+ deadlineMs: number;+ pauseMs: number;+};++/** taskkill exit codes that mean the process is gone: ended now, or not found. */+const TASKKILL_DONE = new Set([0, 128]);++async function windowsSnapshot(): Promise<Map<number, WinProc> | null> {+ const script =+ "Get-CimInstance Win32_Process | ForEach-Object { '{0} {1} {2}' -f $_.ProcessId, $_.ParentProcessId, " ++ "$(if ($_.CreationDate) { $_.CreationDate.ToFileTimeUtc() } else { 0 }) }";+ const out = await run("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", script]);+ const table = new Map<number, WinProc>();+ for (const line of out.split(/\r?\n/)) {+ const match = /^\s*(\d+)\s+(\d+)\s+(\d+)\s*$/.exec(line);+ if (match) table.set(Number(match[1]), { ppid: Number(match[2]), created: Number(match[3]) });+ }+ return table.size > 0 ? table : null;+}++/** The runner and every process under it, each with its creation time. A child must be no older than its parent, so a reused pid adopts no strangers. */+export function windowsTree(rootPid: number, table: Map<number, WinProc>): Map<number, number> {+ const tree = new Map<number, number>([[rootPid, table.get(rootPid)?.created ?? 0]]);+ const stack = [rootPid];+ while (stack.length > 0) {+ const parent = stack.pop() as number;+ const parentCreated = tree.get(parent) ?? 0;+ for (const [pid, proc] of table) {+ if (proc.ppid !== parent || tree.has(pid) || proc.created < parentCreated) continue;+ tree.set(pid, proc.created);+ stack.push(pid);+ }+ }+ return tree;+}++const windowsStopDeps: WindowsStopDeps = {+ snapshot: windowsSnapshot,+ taskkill: (args) =>+ new Promise((resolve) => {+ const child = spawn("taskkill", args, { stdio: "ignore", windowsHide: true });+ child.on("error", () => resolve(null));+ child.on("close", (code) => resolve(code));+ }),+ terminate: (pid) => process.kill(pid),+ rootRunning: () => true,+ deadlineMs: KILL_WAIT_MS / 2,+ pauseMs: 200,+};++/**+ * Stop a run on Windows. List the tree first, run taskkill /T on the runner and wait for it, then+ * check that the runner and every process that was under it are gone, retrying what is left. A pid+ * is only targeted while it still belongs to the same process. True only once all are gone.+ */+export async function stopTreeWindows(rootPid: number, deps: WindowsStopDeps): Promise<boolean> {+ const before = await deps.snapshot();+ const tree = before ? windowsTree(rootPid, before) : new Map<number, number>();+ tree.delete(rootPid); // the runner is checked through its own process handle+ tree.delete(process.pid);+ const deadline = Date.now() + deps.deadlineMs;+ let code: number | null = null;+ let first = true;+ for (;;) {+ if (first || deps.rootRunning()) code = await deps.taskkill(["/T", "/F", "/PID", String(rootPid)]);+ first = false;+ const now = tree.size > 0 ? await deps.snapshot() : null;+ const left = now ? [...tree].filter(([pid, created]) => now.get(pid)?.created === created).map(([pid]) => pid) : [];+ const listed = tree.size === 0 || now !== null;+ // With no list of the tree, only the runner can be checked, so taskkill must also report it done.+ const treeGone = listed && left.length === 0 && (before !== null || (code !== null && TASKKILL_DONE.has(code)));+ if (!deps.rootRunning() && treeGone) return true;+ if (Date.now() >= deadline) return false;+ for (const pid of left) {+ const ended = await deps.taskkill(["/T", "/F", "/PID", String(pid)]);+ if (ended === null) {+ try {+ deps.terminate(pid);+ } catch {+ // Gone, or not ours to end; the next check tells.+ }+ }+ }+ await new Promise((resolve) => setTimeout(resolve, deps.pauseMs));+ }}type ScriptExit = {@@ -303,6 +407,9 @@ type ScriptExit = {timedOut: boolean;aborted: boolean;spawnError?: NodeJS.ErrnoException;+ /** Set when the run was stopped: whether every process it started is confirmed gone. */+ stopConfirmed?: boolean;+ record?: RunRecord;};/** The last `cap` characters of a stream, without holding the rest in memory. */@@ -322,6 +429,7 @@ function runChild(command: Command, code: string, options: {cwd: string;env: Env;signal?: AbortSignal;+ stop: Stopper;}): Promise<ScriptExit> {return new Promise((resolve) => {const out = tailCollector(OUTPUT_CAP);@@ -334,6 +442,7 @@ function runChild(command: Command, code: string, options: {detached: process.platform !== "win32",});const record = child.pid === undefined ? undefined : new RunRecord(child.pid, marker);+ if (record) record.running = () => child.exitCode === null && child.signalCode === null;let timedOut = false;let aborted = false;let settled = false;@@ -347,7 +456,7 @@ function runChild(command: Command, code: string, options: {}, SAMPLE_MS): undefined;- let stopped: Promise<void> = Promise.resolve();+ let stopped: Promise<boolean> = Promise.resolve(true);const settle = (exitCode: number | null, spawnError?: NodeJS.ErrnoException) => {if (settled) return;@@ -356,9 +465,9 @@ function runChild(command: Command, code: string, options: {clearTimeout(killWait);clearInterval(sampler);options.signal?.removeEventListener("abort", onAbort);- const result = { exitCode, stdout: out.read(), stderr: err.read(), timedOut, aborted, spawnError };- // A stopped run frees the phone only once its last process is gone.- void stopped.then(() => resolve(result));+ const result = { exitCode, stdout: out.read(), stderr: err.read(), timedOut, aborted, spawnError, record };+ // A stopped run reports back only once its stop has finished, confirmed or not.+ void stopped.then((confirmed) => resolve(stopping ? { ...result, stopConfirmed: confirmed } : result));};const stop = () => {if (stopping) return;@@ -366,7 +475,7 @@ function runChild(command: Command, code: string, options: {clearInterval(sampler);// Close follows the kill. Do not hang if a pipe stays open anyway.killWait = setTimeout(() => settle(null), KILL_WAIT_MS);- if (record) stopped = stopRun(record).catch(() => {});+ if (record) stopped = options.stop(record).catch(() => false);};const onAbort = () => {aborted = true;@@ -477,8 +586,22 @@ export type PhoneExecOptions = {lock?: PhoneLock;lockWaitMs?: number;signal?: AbortSignal;+ stop?: Stopper;+ confirmEveryMs?: number;};+const CONFIRM_EVERY_MS = 2_000;+const UNCONFIRMED =+ "Not every process the script started could be confirmed stopped, so the phone stays reserved until they are.";++/** Keep stopping a run until every process it started is confirmed gone. */+async function keepStopping(record: RunRecord, stop: Stopper, everyMs: number): Promise<void> {+ for (;;) {+ await new Promise((resolve) => setTimeout(resolve, everyMs));+ if (await stop(record).catch(() => false)) return;+ }+}+export async function phoneExec(params: PhoneExecParams, options: PhoneExecOptions): Promise<ToolResult> {const code = typeof params.code === "string" ? params.code : "";if (!code.trim()) return failure("No code provided. Start with: ensure_device(); print(screen_info())");@@ -491,6 +614,7 @@ export async function phoneExec(params: PhoneExecParams, options: PhoneExecOptioreturn failure("The phone is busy with another phone_exec script. Try again when it finishes.");}const startedMs = Date.now();+ const stop = options.stop ?? stopRun;let exit: ScriptExit;try {// A missing workspace is seeded by Phone Harness on its first run, so it must not be created@@ -502,10 +626,17 @@ export async function phoneExec(params: PhoneExecParams, options: PhoneExecOptiocwd,env: childEnv(options.env, workspace),signal: options.signal,+ stop,});} catch (error) {+ lock.release();return failure(`Failed to launch phone-harness: ${(error as Error).message}`);- } finally {+ }+ const unconfirmed = exit.stopConfirmed === false;+ if (unconfirmed && exit.record) {+ // Fail closed: the phone is free again only once every process the script started is gone.+ void keepStopping(exit.record, stop, options.confirmEveryMs ?? CONFIRM_EVERY_MS).then(() => lock.release());+ } else {lock.release();}@@ -513,12 +644,14 @@ export async function phoneExec(params: PhoneExecParams, options: PhoneExecOptioconst missing = exit.spawnError.code === "ENOENT";return failure(missing ? UV_MISSING : `Failed to launch phone-harness: ${exit.spawnError.message}`);}- if (exit.aborted) return failure("phone_exec was cancelled. The script was stopped.");+ if (exit.aborted) {+ return failure(`phone_exec was cancelled. ${unconfirmed ? UNCONFIRMED : "The script was stopped."}`, compact({ stopConfirmed: !unconfirmed }));+ }if (exit.timedOut) {return failure(`phone_exec timed out after ${timeoutS}s. Split the work into smaller scripts or raise timeout_s ` +- `(max ${MAX_TIMEOUT_S}).`,- { timedOut: true, timeoutMs: timeoutS * 1000 },+ `(max ${MAX_TIMEOUT_S}).${unconfirmed ? ` ${UNCONFIRMED}` : ""}`,+ { timedOut: true, timeoutMs: timeoutS * 1000, stopConfirmed: !unconfirmed },);}diff --git a/tests/test_openclaw_plugin.py b/tests/test_openclaw_plugin.pyindex 0823f49..108d0e5 100644--- a/tests/test_openclaw_plugin.py+++ b/tests/test_openclaw_plugin.py@@ -123,7 +123,10 @@ class Pin(unittest.TestCase):for path in [PLUGIN / "README.md", PLUGIN / "src" / "index.ts", PLUGIN / "src" / "approval.ts",PLUGIN / "scripts" / "build-skill.mjs", PLUGIN / "package.json",PLUGIN / "openclaw.plugin.json"]:- self.assertIsNone(pattern.search(path.read_text(encoding="utf-8")), path.name)+ text = path.read_text(encoding="utf-8")+ # The README's uvx commands name the release on purpose; Readme checks they match it.+ text = text.replace(f"--from phone-harness=={version} phone-harness", "")+ self.assertIsNone(pattern.search(text), path.name)class Classifier(unittest.TestCase):@@ -216,9 +219,18 @@ class Readme(unittest.TestCase):def test_says_what_telemetry_sends_and_how_to_turn_it_off(self):text = (PLUGIN / "README.md").read_text(encoding="utf-8")for phrase in ("PostHog", "scripts and what they print", "`DO_NOT_TRACK=1`",- "`uvx phone-harness config set telemetry false`"):+ "phone-harness config set telemetry false`"):self.assertIn(phrase, text)+ def test_readme_commands_pin_the_release_the_plugin_runs(self):+ text = (PLUGIN / "README.md").read_text(encoding="utf-8")+ source = (PLUGIN / "src" / "phone-exec.ts").read_text(encoding="utf-8")+ version = re.search(r'PHONE_HARNESS_VERSION = "([^"]+)"', source).group(1)+ commands = re.findall(r"uvx\s[^`\n]*", text)+ self.assertTrue(commands)+ for command in commands:+ self.assertIn(f"--from phone-harness=={version} phone-harness", command)+def test_no_posthog_key_ships_in_the_plugin(self):for path in PLUGIN.rglob("*"):if path.is_file() and "node_modules" not in path.parts: