Skip to content

Mola-maker/mstack / skills/m-cua

Drive a real desktop app, Android device or browser to prove L3/L4 acceptance. Use for 点一下/操作界面/真机验收/computer use.

FileKindSize
SKILL.mdskill md5.9 KB
references/drivers.mdmarkdown7.8 KB
scripts/cua-doctor.mjsscript11.2 KB
scripts/cua-doctor.test.mjsscript12.9 KB

scripts/cua-doctor.test.mjs

View on GitHub
import test from "node:test";
import assert from "node:assert/strict";
import { mkdtempSync, mkdirSync, writeFileSync, chmodSync, rmSync } from "node:fs";
import { spawnSync } from "node:child_process";
import { tmpdir } from "node:os";
import { join, delimiter } from "node:path";
import { fileURLToPath } from "node:url";
import { main } from "./cua-doctor.mjs";

const WIN = process.platform === "win32";
const SCRIPT = fileURLToPath(new URL("./cua-doctor.mjs", import.meta.url));

// A fake tool that prints fixed lines and exits with `code`, as a .cmd on Windows and a shell script elsewhere.
function fake(dir, name, lines, code = 0) {
  mkdirSync(dir, { recursive: true });
  if (WIN) writeFileSync(join(dir, name + ".cmd"), ["@echo off", ...lines.map((l) => "echo " + l), `exit /b ${code}`].join("\r\n") + "\r\n");
  else {
    const p = join(dir, name);
    writeFileSync(p, ["#!/bin/sh", ...lines.map((l) => `printf '%s\\n' '${l.replaceAll("'", "'\\''")}'`), `exit ${code}`].join("\n") + "\n");
    chmodSync(p, 0o755);
  }
}
// Only what a shell needs to start: no HOME, APPDATA or ANDROID_* leaks in from the machine running the tests.
const env = (pathDirs, extra = {}) => ({ PATH: pathDirs.join(delimiter), PATHEXT: ".CMD;.EXE", ComSpec: process.env.ComSpec ?? "", SystemRoot: process.env.SystemRoot ?? "", ...extra });
const STATUS = (acc = "granted") => `{"version":"2.6","ok":true,"command":"status","data":{"permissions":{"accessibility":{"state":"${acc}"},"automation":{"state":"not_required"}},"platform":"test","version":"9.9.9"}}`;
const scratch = (t) => { const d = mkdtempSync(join(tmpdir(), "cua-doctor-")); t.after(() => rmSync(d, { recursive: true, force: true })); return d; };
const drivers = (r) => Object.fromEntries(JSON.parse(r.text).drivers.map((d) => [d.driver, d]));

test("nothing installed: every driver is missing, each with a fix, exit 1", (t) => {
  const d = scratch(t);
  const r = main(["--json"], env([d]), d);
  assert.equal(r.code, 1);
  for (const x of Object.values(drivers(r))) { assert.equal(x.state, "missing"); assert.ok(x.fix.length > 10); }
});

test("agent-desktop on PATH with permissions granted is ready", (t) => {
  const d = scratch(t);
  fake(d, "agent-desktop", ["launcher notice that is not JSON", STATUS()]);
  const r = main(["--need", "desktop", "--json"], env([d]), d);
  assert.equal(r.code, 0);
  assert.equal(drivers(r).desktop.state, "ready");
  assert.equal(drivers(r).desktop.version, "9.9.9");
});

test("agent-desktop installed where npm puts it but not on PATH is not-on-path, usable, and names the file", (t) => {
  const d = scratch(t);
  const off = WIN ? join(d, "appdata", "npm") : join(d, "home", ".npm-global", "bin");
  fake(off, "agent-desktop", [STATUS()]);
  const r = main(["--need", "desktop", "--json"], env([d], WIN ? { APPDATA: join(d, "appdata") } : { HOME: join(d, "home") }), d);
  assert.equal(r.code, 0);
  const x = drivers(r).desktop;
  assert.equal(x.state, "not-on-path");
  assert.ok(x.fix.includes(off), x.fix);
});

test("agent-desktop without the accessibility permission is broken, not ready", (t) => {
  const d = scratch(t);
  fake(d, "agent-desktop", [STATUS("denied")]);
  const r = main(["--need", "desktop", "--json"], env([d]), d);
  assert.equal(r.code, 1);
  assert.equal(drivers(r).desktop.state, "broken");
  assert.match(drivers(r).desktop.detail, /accessibility permission is denied/);
});

test("a denied screen-recording permission alone does not make the desktop driver unusable", (t) => {
  const d = scratch(t);
  fake(d, "agent-desktop", ['{"ok":true,"command":"status","data":{"permissions":{"accessibility":{"state":"granted"},"screen_recording":{"state":"denied"}},"version":"9.9.9"}}']);
  assert.equal(drivers(main(["--need", "desktop", "--json"], env([d]), d)).desktop.state, "ready");
});

test("a status envelope without data is broken, not a crash", (t) => {
  const d = scratch(t);
  fake(d, "agent-desktop", ['{"ok":true,"command":"status"}']);
  const r = main(["--need", "desktop", "--json"], env([d]), d);
  assert.equal(r.code, 1);
  assert.equal(drivers(r).desktop.state, "broken");
});

test("adb with no device, and with only an unauthorized device, is no-device", (t) => {
  const d = scratch(t);
  fake(d, "adb", ["List of devices attached"]);
  let r = main(["--need", "android", "--json"], env([d]), d);
  assert.equal(r.code, 1);
  assert.equal(drivers(r).android.state, "no-device");
  fake(d, "adb", ["List of devices attached", "R58M123\tunauthorized"]);
  r = main(["--need", "android", "--json"], env([d]), d);
  assert.equal(drivers(r).android.state, "no-device");
  assert.match(drivers(r).android.detail, /unauthorized/);
});

test("a Linux `no permissions` row is reported, not dropped; daemon notices are not devices", (t) => {
  const d = scratch(t);
  fake(d, "adb", ["* daemon not running; starting now at tcp:5037", "* daemon started successfully", "List of devices attached", "adb server version (41) doesn't match this client (39); killing...", "0123456789ABCDEF\tno permissions (user in plugdev group)"]);
  const x = drivers(main(["--need", "android", "--json"], env([d]), d)).android;
  assert.equal(x.state, "no-device");
  assert.match(x.detail, /0123456789ABCDEF no permissions/);
  assert.doesNotMatch(x.detail, /daemon|server version/);
});

test("no-device names the emulator by full path when the SDK has one", (t) => {
  const d = scratch(t);
  fake(join(d, "sdk", "platform-tools"), "adb", ["List of devices attached"]);
  fake(join(d, "sdk", "emulator"), "emulator", ["x"]);
  const x = drivers(main(["--need", "android", "--json"], env([d], { ANDROID_HOME: join(d, "sdk") }), d)).android;
  assert.equal(x.state, "no-device");
  assert.ok(x.fix.includes(join(d, "sdk", "emulator")), x.fix);
});

test("a tool whose directory name contains %VAR% still runs", (t) => {
  const d = join(scratch(t), "p%PATH%q");
  fake(d, "adb", ["List of devices attached", "emulator-5554\tdevice"]);
  assert.equal(drivers(main(["--need", "android", "--json"], env([d]), d)).android.state, "ready");
});

test("adb with an online device is ready and lists it", (t) => {
  const d = scratch(t);
  fake(d, "adb", ["List of devices attached", "emulator-5554\tdevice"]);
  const r = main(["--need", "android", "--json"], env([d]), d);
  assert.equal(r.code, 0);
  assert.deepEqual(drivers(r).android.devices, ["emulator-5554"]);
});

test("adb only under ANDROID_HOME/platform-tools with a device is not-on-path and usable", (t) => {
  const d = scratch(t);
  fake(join(d, "sdk", "platform-tools"), "adb", ["List of devices attached", "emulator-5554\tdevice"]);
  const r = main(["--need", "android", "--json"], env([d], { ANDROID_HOME: join(d, "sdk") }), d);
  assert.equal(r.code, 0);
  assert.ok(drivers(r).android.bin.includes("platform-tools"));
  assert.equal(drivers(r).android.state, "not-on-path");
});

test("a project-local playwright is ready; a failing one is broken", (t) => {
  const d = scratch(t);
  fake(join(d, "node_modules", ".bin"), "playwright", ["Version 1.2.3"]);
  let r = main(["--need", "web", "--json"], env([d]), d);
  assert.equal(r.code, 0);
  assert.equal(drivers(r).web.version, "Version 1.2.3");
  fake(join(d, "node_modules", ".bin"), "playwright", ["boom"], 3);
  r = main(["--need", "web", "--json"], env([d]), d);
  assert.equal(drivers(r).web.state, "broken");
});

test("without --need, one ready driver is enough for exit 0", (t) => {
  const d = scratch(t);
  fake(d, "agent-desktop", [STATUS()]);
  assert.equal(main(["--json"], env([d]), d).code, 0);
});

test("an unknown argument or driver name exits 2", () => {
  assert.equal(main(["--need", "ios"]).code, 2);
  assert.equal(main(["--wat"]).code, 2);
  assert.equal(main(["--need"]).code, 2);
  // names that exist on Object.prototype are not drivers
  for (const n of ["constructor", "__proto__", "toString"]) assert.equal(main(["--need", n, "--json"], { PATH: "", SECRET: "s3cr3t" }).code, 2, n);
});

test("run as a command it prints one block per driver with the fix line", (t) => {
  const d = scratch(t);
  const r = spawnSync(process.execPath, [SCRIPT], { cwd: d, env: env([d]), encoding: "utf8" });
  assert.equal(r.status, 1, r.stderr);
  assert.match(r.stdout, /desktop: missing \(agent-desktop\)\n {2}fix: npm install -g agent-desktop/);
  assert.match(r.stdout, /android: missing/);
  assert.match(r.stdout, /web: missing/);
});

// ---------------------------------------------------------------- mola-cua

const MOLA_STATUS = (devices) => `{"version":"2.6","ok":true,"command":"status","data":{"platform":"android","version":"0.1.0","adb":{"path":"/sdk/platform-tools/adb","version":"x"},"devices":${JSON.stringify(devices)},"ready":${devices.some((d) => d.state === "device")}}}`;

test("mola-cua on PATH is the android driver: ready with its devices, and adb is not asked", (t) => {
  const d = scratch(t);
  fake(d, "mola-cua", [MOLA_STATUS([{ serial: "emulator-5554", state: "device" }, { serial: "R58M", state: "unauthorized" }])]);
  fake(d, "adb", ["this adb must not be consulted"], 7);
  const r = main(["--need", "android", "--json"], env([d]), d);
  assert.equal(r.code, 0);
  const a = drivers(r).android;
  assert.equal(a.tool, "mola-cua");
  assert.equal(a.state, "ready");
  assert.deepEqual(a.devices, ["emulator-5554"]);
});

test("mola-cua with no usable device is no-device and says which devices it saw", (t) => {
  const d = scratch(t);
  fake(d, "mola-cua", [MOLA_STATUS([{ serial: "R58M", state: "unauthorized" }])]);
  const a = drivers(main(["--need", "android", "--json"], env([d]), d)).android;
  assert.equal(a.state, "no-device");
  assert.match(a.detail, /R58M unauthorized/);
  fake(d, "mola-cua", [MOLA_STATUS([])]);
  assert.match(drivers(main(["--need", "android", "--json"], env([d]), d)).android.detail, /no device or emulator/);
});

test("mola-cua that reports an error is broken and passes its own suggestion on", (t) => {
  const d = scratch(t);
  fake(d, "mola-cua", ['{"version":"2.6","ok":false,"command":"status","error":{"code":"PLATFORM_NOT_SUPPORTED","message":"adb was not found","suggestion":"Install Android SDK Platform-Tools"}}'], 1);
  const r = main(["--need", "android", "--json"], env([d]), d);
  assert.equal(r.code, 1);
  const a = drivers(r).android;
  assert.equal(a.state, "broken");
  assert.equal(a.fix, "Install Android SDK Platform-Tools");
  fake(d, "mola-cua", ["garbage"], 3);
  assert.equal(drivers(main(["--need", "android", "--json"], env([d]), d)).android.state, "broken");
});

test("without mola-cua, plain adb still counts and the result says how to get mola-cua", (t) => {
  const d = scratch(t);
  fake(d, "adb", ["List of devices attached", "emulator-5554\tdevice"]);
  const r = main(["--need", "android", "--json"], env([d]), d);
  assert.equal(r.code, 0);
  const a = drivers(r).android;
  assert.equal(a.tool, "adb");
  assert.match(a.note, /mola-cua/);
  const text = main(["--need", "android"], env([d]), d).text;
  assert.match(text, /\n {2}note: plain adb only/);
});

test("MOLA_CUA_BIN off PATH is not-on-path (usable by full path), never ready-by-name", (t) => {
  const d = scratch(t);
  const off = join(d, "build");
  fake(off, "mola-cua", [MOLA_STATUS([{ serial: "emulator-5554", state: "device" }])]);
  const bin = join(off, WIN ? "mola-cua.cmd" : "mola-cua");
  const r = main(["--need", "android", "--json"], env([d], { MOLA_CUA_BIN: bin }), d);
  assert.equal(r.code, 0);
  const a = drivers(r).android;
  assert.equal(a.state, "not-on-path");
  assert.ok(a.fix.includes(bin), a.fix);
  assert.deepEqual(a.devices, ["emulator-5554"]);
});

test("MOLA_CUA_BIN pointing at a missing file is broken and names the variable", (t) => {
  const d = scratch(t);
  fake(d, "adb", ["List of devices attached", "emulator-5554\tdevice"]);
  const r = main(["--need", "android", "--json"], env([d], { MOLA_CUA_BIN: join(d, "gone", "mola-cua") }), d);
  assert.equal(r.code, 1);
  const a = drivers(r).android;
  assert.equal(a.state, "broken");
  assert.match(a.fix, /MOLA_CUA_BIN is not a file/);
  // a directory (the build folder instead of the binary) is not run; the variable is named
  fake(join(d, "release"), "mola-cua", [MOLA_STATUS([])]);
  const dirResult = drivers(main(["--need", "android", "--json"], env([d], { MOLA_CUA_BIN: join(d, "release") }), d)).android;
  assert.equal(dirResult.state, "broken");
  assert.match(dirResult.fix, /MOLA_CUA_BIN is not a file/);
});

test("mola-cua in cargo's bin directory but not on PATH is found and reported not-on-path", (t) => {
  const d = scratch(t);
  fake(join(d, "cargo", "bin"), "mola-cua", [MOLA_STATUS([{ serial: "emulator-5554", state: "device" }])]);
  const a = drivers(main(["--need", "android", "--json"], env([d], { CARGO_HOME: join(d, "cargo") }), d)).android;
  assert.equal(a.tool, "mola-cua");
  assert.equal(a.state, "not-on-path");
});

test("the no-device fix line gives the emulator path for both steps", (t) => {
  const d = scratch(t);
  fake(d, "mola-cua", [MOLA_STATUS([])]);
  const a = drivers(main(["--need", "android", "--json"], env([d]), d)).android;
  assert.match(a.fix, /emulator" -list-avds, then ".*emulator" -avd <name>/);
});
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 198kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 196kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 196kUpdated Claude CodeCodexVerifiedInstall