@aarwitz/tapp 0.32.0 → 0.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +2 -2
- package/mcp-server/src/android-flow.js +13 -1
- package/mcp-server/src/index.js +4 -3
- package/mcp-server/src/journeys.js +16 -4
- package/mcp-server/src/sign-in.js +91 -0
- package/mcp-server/src/web-explorer.js +41 -15
- package/mcp-server/src/web-flow.js +13 -5
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tapp",
|
|
3
3
|
"description": "Give Claude hands and eyes on iOS, Android, and web apps, with exploration, replayable flows, evidence, and deterministic CI gates.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.33.0",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "Aaron Horowitz",
|
|
7
7
|
"url": "https://github.com/aarwitz"
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"command": "npx",
|
|
25
25
|
"args": [
|
|
26
26
|
"-y",
|
|
27
|
-
"@aarwitz/tapp@0.
|
|
27
|
+
"@aarwitz/tapp@0.33.0",
|
|
28
28
|
"mcp"
|
|
29
29
|
],
|
|
30
30
|
"cwd": "${CLAUDE_PROJECT_DIR}"
|
|
@@ -2,6 +2,7 @@ import fs from "node:fs";
|
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { AndroidDriver, findAndroidElement, isAndroidAppSnapshot } from "./android-driver.js";
|
|
4
4
|
import { FlowLog, flowVariables, normalizeFlowStep, substituteFlowValue } from "./flow-runtime.js";
|
|
5
|
+
import { chooseSignInSubmit } from "./sign-in.js";
|
|
5
6
|
|
|
6
7
|
const DEFAULT_TIMEOUT = 6000;
|
|
7
8
|
|
|
@@ -56,7 +57,18 @@ export async function runAndroidFlow({ flow, appId, apkPath, serial, logPath, sc
|
|
|
56
57
|
const passwordResult = await d.type(passwordField.id || passwordField.label, passwordValue, snap);
|
|
57
58
|
if (passwordResult.status !== "ok") throw new Error(passwordResult.detail || "could not fill the password field");
|
|
58
59
|
snap = await d.settle();
|
|
59
|
-
|
|
60
|
+
// Same rule as the web runner: rule out "Forgot password" and "Continue with Google" by
|
|
61
|
+
// name, prefer a sign-in name, and otherwise take the first clickable control after the
|
|
62
|
+
// password field — Android apps name that button after the product too.
|
|
63
|
+
const passwordIndex = snap.elements.indexOf(passwordField);
|
|
64
|
+
const choice = chooseSignInSubmit(snap.elements.map((element, index) => ({
|
|
65
|
+
index,
|
|
66
|
+
name: `${element.text || ""} ${element.label || ""}`.replace(/\s+/g, " ").trim() || String(element.id || ""),
|
|
67
|
+
visible: Boolean(element.clickable),
|
|
68
|
+
disabled: element.enabled === false,
|
|
69
|
+
after: index > passwordIndex,
|
|
70
|
+
})));
|
|
71
|
+
const submit = choice ? snap.elements[choice.index] : null;
|
|
60
72
|
if (!submit) throw new Error("could not identify a sign-in control");
|
|
61
73
|
const submitResult = await d.tap(submit.id || submit.description || submit.text, snap);
|
|
62
74
|
if (submitResult.status !== "ok") throw new Error(submitResult.detail || "could not submit the login form");
|
package/mcp-server/src/index.js
CHANGED
|
@@ -30,6 +30,7 @@ const workspaceRoot = (() => {
|
|
|
30
30
|
})();
|
|
31
31
|
const scriptsDir = path.join(repoRoot, "scripts");
|
|
32
32
|
import { writeCaptureProvenance, readCaptureProvenance, captureBelongsToProject, provenanceLabel } from "./capture-provenance.js";
|
|
33
|
+
import { findSignInSubmit } from "./sign-in.js";
|
|
33
34
|
// TAPP_HOME (set by the `tapp` CLI when installed) redirects writable output to a user directory.
|
|
34
35
|
// The old alias remains a read-only fallback; unset repository development stays local.
|
|
35
36
|
const tappHome = (process.env.TAPP_HOME || "").trim();
|
|
@@ -1145,10 +1146,10 @@ async function sessionAct(cmd) {
|
|
|
1145
1146
|
} else {
|
|
1146
1147
|
await email.fill(emailValue);
|
|
1147
1148
|
await password.fill(passwordValue);
|
|
1148
|
-
const submit = session.page
|
|
1149
|
-
if (!
|
|
1149
|
+
const submit = await findSignInSubmit(session.page);
|
|
1150
|
+
if (!submit) { status = "not_found"; detail = "Could not identify a sign-in control"; }
|
|
1150
1151
|
else {
|
|
1151
|
-
await submit.click();
|
|
1152
|
+
await submit.locator.click();
|
|
1152
1153
|
await session.page.waitForTimeout(500);
|
|
1153
1154
|
if (await password.isVisible().catch(() => false)) { status = "still_on_login"; detail = "Submit left the app on the login screen"; }
|
|
1154
1155
|
}
|
|
@@ -35,7 +35,13 @@ function readMarkers(captureDir) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// tapp names a revisited screen "Orders (refreshed)"; the page itself still says "Orders".
|
|
38
|
-
|
|
38
|
+
// A screen name is one line. A headline that wraps in the page's source arrives with its
|
|
39
|
+
// newlines and indentation attached, and a journey step that pins that string can never match
|
|
40
|
+
// again — the browser reports the heading with its whitespace collapsed.
|
|
41
|
+
/** A route, not something a person pressed: "/", "/orders", "https://…", "#pricing". */
|
|
42
|
+
const isAddress = (via) => /^([/#]|https?:)/i.test(String(via || "").trim());
|
|
43
|
+
|
|
44
|
+
const pageName = (screen) => String(screen || "").replace(/\s*\((?:refreshed|again|\d+)\)\s*$/i, "").replace(/\s+/g, " ").trim();
|
|
39
45
|
|
|
40
46
|
/**
|
|
41
47
|
* Build a Flow from an exploration capture. Returns null when the run did nothing worth
|
|
@@ -59,13 +65,19 @@ export function journeyFromCapture(captureDir, { name = "", actor = "default" }
|
|
|
59
65
|
};
|
|
60
66
|
let acted = false;
|
|
61
67
|
let signedIn = false;
|
|
62
|
-
|
|
68
|
+
let stop = false;
|
|
69
|
+
for (let i = 0; i < markers.length && steps.length < MAX_STEPS && !stop; i += 1) {
|
|
63
70
|
const marker = markers[i];
|
|
64
71
|
if (marker.kind === "OCQA_STATE") { waitFor(marker.screen); continue; }
|
|
65
72
|
switch (marker.type) {
|
|
66
73
|
case "open":
|
|
67
|
-
// The first open is the journey's URL
|
|
68
|
-
|
|
74
|
+
// The first open is the journey's URL. A later one is either a link somebody pressed —
|
|
75
|
+
// which a person can repeat — or the crawler jumping to a route by address, which nobody
|
|
76
|
+
// can. A journey is the path a user could walk, so it ends at the first jump rather than
|
|
77
|
+
// pretending the previous tap led there. (Found by filming: a kept journey had "tap Area"
|
|
78
|
+
// followed by the marketing home page, and the replay rightly refused to believe it.)
|
|
79
|
+
if (!marker.via || marker.via === marker.target || isAddress(marker.via)) { if (acted) stop = true; break; }
|
|
80
|
+
steps.push({ tap: marker.via }); acted = true;
|
|
69
81
|
break;
|
|
70
82
|
case "login":
|
|
71
83
|
steps.push({ login: { email: "$TEST_EMAIL", password: "$TEST_PASSWORD" } });
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Pressing the button that signs you in.
|
|
2
|
+
//
|
|
3
|
+
// This used to be a word list — `sign in|log in|login|continue|submit` — in three separate
|
|
4
|
+
// places, and a CSS selector that looked for `button[type=submit]` or a button inside a `<form>`.
|
|
5
|
+
// Measured against a real customer's sign-in page, every one of those assumptions was wrong:
|
|
6
|
+
//
|
|
7
|
+
// • the page has no <form> at all (a React component with an onClick handler);
|
|
8
|
+
// • the buttons carry no `type` ATTRIBUTE, so `button[type=submit]` never matches, even though
|
|
9
|
+
// the DOM *property* reads "submit" — which is what made this look fine when probed by hand;
|
|
10
|
+
// • the button is called "Open My Profile", because products name their buttons after what the
|
|
11
|
+
// product does, not after the verb a test author had in mind.
|
|
12
|
+
//
|
|
13
|
+
// So the page offered a perfectly ordinary sign-in form and tapp could not press it. It said so
|
|
14
|
+
// honestly — a high-severity "the sign-in attempt did not leave the login form" — but honest and
|
|
15
|
+
// useless is still useless: the whole promise is that tapp gets *inside* the application.
|
|
16
|
+
//
|
|
17
|
+
// What is actually reliable is not the button's name but its position: the control that signs you
|
|
18
|
+
// in comes after the password field, and the controls that must never be pressed (forgot password,
|
|
19
|
+
// create an account, continue with Google) say so in their own words. So: rule out the dangerous
|
|
20
|
+
// ones by name, then prefer by name, then fall back to position.
|
|
21
|
+
|
|
22
|
+
/** Names that mean "this is the sign-in button". Deliberately short — structure does the rest. */
|
|
23
|
+
export const SIGN_IN_NAME = /\b(sign ?in|log ?in|login|submit|continue)\b/i;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Names that mean "never press this to sign in". Some are merely wrong (forgot password); some
|
|
27
|
+
* are actively harmful — "Continue with Google" would hand a third-party identity provider a
|
|
28
|
+
* session, which a machine must never do on someone's behalf.
|
|
29
|
+
*/
|
|
30
|
+
export const NOT_SIGN_IN = /forgot|reset|recover|remember|show password|hide password|cancel|go back|back to|sign ?up|create (an |your |a )?account|register|get started free|privacy|terms|need help|help\?|continue with|with google|with apple|with facebook|with github|with microsoft|single sign|\bsso\b|close|dismiss|skip/i;
|
|
31
|
+
|
|
32
|
+
/** Every control that can plausibly be clicked, in document order. */
|
|
33
|
+
export const SUBMIT_CANDIDATE_SELECTOR = "button, input[type=submit], input[type=button], input[type=image], [role=button]";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Pick the sign-in control out of the page's clickable controls. Pure, so the ordering rules are
|
|
37
|
+
* testable without a browser.
|
|
38
|
+
*
|
|
39
|
+
* @param {Array<{index:number,name:string,visible:boolean,disabled:boolean,after:boolean}>} candidates
|
|
40
|
+
* `after` means the control follows the visible password field in document order.
|
|
41
|
+
*/
|
|
42
|
+
export function chooseSignInSubmit(candidates = []) {
|
|
43
|
+
const usable = candidates.filter((c) => c && c.visible && !c.disabled && String(c.name || "").trim() && !NOT_SIGN_IN.test(c.name));
|
|
44
|
+
const pick = usable.find((c) => c.after && SIGN_IN_NAME.test(c.name))
|
|
45
|
+
|| usable.find((c) => SIGN_IN_NAME.test(c.name))
|
|
46
|
+
// Named for what the product does, not for the verb: position is what is left to go on.
|
|
47
|
+
|| usable.find((c) => c.after)
|
|
48
|
+
|| usable[0]
|
|
49
|
+
|| null;
|
|
50
|
+
if (!pick) return null;
|
|
51
|
+
return { ...pick, reason: SIGN_IN_NAME.test(pick.name) ? "name" : "position" };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Read the page's clickable controls and say which one signs you in. */
|
|
55
|
+
export async function findSignInSubmit(page) {
|
|
56
|
+
let candidates;
|
|
57
|
+
try {
|
|
58
|
+
candidates = await page.evaluate((selector) => {
|
|
59
|
+
const visible = (el) => {
|
|
60
|
+
if (!el.getClientRects().length) return false;
|
|
61
|
+
const style = getComputedStyle(el);
|
|
62
|
+
return style.visibility !== "hidden" && style.display !== "none" && Number(style.opacity ?? 1) > 0.05;
|
|
63
|
+
};
|
|
64
|
+
const password = Array.from(document.querySelectorAll("input[type=password]")).find(visible) || null;
|
|
65
|
+
return Array.from(document.querySelectorAll(selector)).map((el, index) => ({
|
|
66
|
+
index,
|
|
67
|
+
name: (el.innerText || el.value || el.getAttribute("aria-label") || el.getAttribute("title") || "").replace(/\s+/g, " ").trim().slice(0, 80),
|
|
68
|
+
visible: visible(el),
|
|
69
|
+
disabled: el.disabled === true || el.getAttribute("aria-disabled") === "true",
|
|
70
|
+
// DOCUMENT_POSITION_FOLLOWING (4): the control comes after the password field.
|
|
71
|
+
after: password ? Boolean(password.compareDocumentPosition(el) & 4) : false,
|
|
72
|
+
}));
|
|
73
|
+
}, SUBMIT_CANDIDATE_SELECTOR);
|
|
74
|
+
} catch { return null; }
|
|
75
|
+
const pick = chooseSignInSubmit(candidates);
|
|
76
|
+
if (!pick) return null;
|
|
77
|
+
// querySelectorAll and Playwright's locator both resolve in document order, so the index carries.
|
|
78
|
+
return { locator: page.locator(SUBMIT_CANDIDATE_SELECTOR).nth(pick.index), name: pick.name, reason: pick.reason };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Fill nothing, press once. Returns what was pressed so a caller can say so in a report, or null
|
|
83
|
+
* when the page offers no sign-in control at all.
|
|
84
|
+
*/
|
|
85
|
+
export async function submitSignIn(page, beforeClick = null) {
|
|
86
|
+
const found = await findSignInSubmit(page);
|
|
87
|
+
if (!found) return null;
|
|
88
|
+
if (beforeClick) await beforeClick(found.locator);
|
|
89
|
+
await found.locator.click({ timeout: 3000 });
|
|
90
|
+
return { name: found.name, reason: found.reason };
|
|
91
|
+
}
|
|
@@ -19,6 +19,7 @@ import fs from "fs";
|
|
|
19
19
|
import path from "path";
|
|
20
20
|
import { createRequire } from "module";
|
|
21
21
|
import { execFileSync } from "child_process";
|
|
22
|
+
import { submitSignIn } from "./sign-in.js";
|
|
22
23
|
|
|
23
24
|
const CLICK_SETTLE_MS = 700;
|
|
24
25
|
export const NAV_TIMEOUT_MS = 15_000;
|
|
@@ -194,7 +195,18 @@ async function captureWebControlState(page, locator) {
|
|
|
194
195
|
.sort();
|
|
195
196
|
return {
|
|
196
197
|
title: document.title,
|
|
197
|
-
heading:
|
|
198
|
+
heading: (() => {
|
|
199
|
+
// The same definition the flow runner uses when it checks a screen: the first h1 a
|
|
200
|
+
// person can actually see. A sign-in headline left hidden in the DOM used to go on
|
|
201
|
+
// naming every later screen, and the replay could never agree.
|
|
202
|
+
const shown = (el) => {
|
|
203
|
+
if (!el.getClientRects().length) return false;
|
|
204
|
+
const style = getComputedStyle(el);
|
|
205
|
+
return style.visibility !== "hidden" && style.display !== "none";
|
|
206
|
+
};
|
|
207
|
+
const h1 = Array.from(document.querySelectorAll("h1")).find(shown);
|
|
208
|
+
return (h1 ? h1.innerText || h1.textContent || "" : "").replace(/\s+/g, " ").trim();
|
|
209
|
+
})(),
|
|
198
210
|
dialogs: JSON.stringify(dialogs),
|
|
199
211
|
};
|
|
200
212
|
}).catch(() => ({ title: "", heading: "", dialogs: "" }));
|
|
@@ -333,18 +345,10 @@ export async function loadPlaywright() {
|
|
|
333
345
|
}
|
|
334
346
|
|
|
335
347
|
export async function submitWebLogin(page, beforeClick = null) {
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
for (const candidate of candidates) {
|
|
341
|
-
if (await candidate.isVisible().catch(() => false)) {
|
|
342
|
-
if (beforeClick) await beforeClick(candidate);
|
|
343
|
-
await candidate.click({ timeout: 3000 });
|
|
344
|
-
return true;
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
return false;
|
|
348
|
+
// One implementation, shared with the flow runner and the MCP login command, so a page that can
|
|
349
|
+
// be signed into by one of them can be signed into by all three. See mcp-server/src/sign-in.js
|
|
350
|
+
// for why a name-only rule was not enough.
|
|
351
|
+
return Boolean(await submitSignIn(page, beforeClick).catch(() => null));
|
|
348
352
|
}
|
|
349
353
|
|
|
350
354
|
// How many distinct in-page states one URL may contribute before we stop splitting it. A
|
|
@@ -751,7 +755,18 @@ export async function inspectWebPage({ url, timeoutMs = NAV_TIMEOUT_MS, screensh
|
|
|
751
755
|
})
|
|
752
756
|
.filter((control) => control.label || control.identifier);
|
|
753
757
|
return {
|
|
754
|
-
heading:
|
|
758
|
+
heading: (() => {
|
|
759
|
+
// The same definition the flow runner uses when it checks a screen: the first h1 a
|
|
760
|
+
// person can actually see. A sign-in headline left hidden in the DOM used to go on
|
|
761
|
+
// naming every later screen, and the replay could never agree.
|
|
762
|
+
const shown = (el) => {
|
|
763
|
+
if (!el.getClientRects().length) return false;
|
|
764
|
+
const style = getComputedStyle(el);
|
|
765
|
+
return style.visibility !== "hidden" && style.display !== "none";
|
|
766
|
+
};
|
|
767
|
+
const h1 = Array.from(document.querySelectorAll("h1")).find(shown);
|
|
768
|
+
return (h1 ? h1.innerText || h1.textContent || "" : "").replace(/\s+/g, " ").trim();
|
|
769
|
+
})(),
|
|
755
770
|
title: document.title.trim(),
|
|
756
771
|
controls,
|
|
757
772
|
};
|
|
@@ -986,7 +1001,18 @@ export async function exploreWeb({ url, maxActions = 40, timeoutSec = 300, outDi
|
|
|
986
1001
|
})
|
|
987
1002
|
.filter((control) => control.label || control.id || control.testId);
|
|
988
1003
|
return {
|
|
989
|
-
heading:
|
|
1004
|
+
heading: (() => {
|
|
1005
|
+
// The same definition the flow runner uses when it checks a screen: the first h1 a
|
|
1006
|
+
// person can actually see. A sign-in headline left hidden in the DOM used to go on
|
|
1007
|
+
// naming every later screen, and the replay could never agree.
|
|
1008
|
+
const shown = (el) => {
|
|
1009
|
+
if (!el.getClientRects().length) return false;
|
|
1010
|
+
const style = getComputedStyle(el);
|
|
1011
|
+
return style.visibility !== "hidden" && style.display !== "none";
|
|
1012
|
+
};
|
|
1013
|
+
const h1 = Array.from(document.querySelectorAll("h1")).find(shown);
|
|
1014
|
+
return (h1 ? h1.innerText || h1.textContent || "" : "").replace(/\s+/g, " ").trim();
|
|
1015
|
+
})(),
|
|
990
1016
|
title: document.title.trim(),
|
|
991
1017
|
controlCount: document.querySelectorAll("a[href], button, [role=button], input, select, textarea").length,
|
|
992
1018
|
textLen: (document.body?.innerText || "").trim().length,
|
|
@@ -4,6 +4,7 @@ import fs from "node:fs";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { FlowLog, flowVariables, normalizeFlowStep, substituteFlowValue } from "./flow-runtime.js";
|
|
6
6
|
import { loadPlaywright, webContextOptions } from "./web-explorer.js";
|
|
7
|
+
import { findSignInSubmit } from "./sign-in.js";
|
|
7
8
|
|
|
8
9
|
const DEFAULT_TIMEOUT = 6000;
|
|
9
10
|
|
|
@@ -91,12 +92,19 @@ async function screenCandidates(page) {
|
|
|
91
92
|
const url = new URL(page.url());
|
|
92
93
|
values.push(url.pathname, url.pathname.split("/").filter(Boolean).at(-1) || "Home");
|
|
93
94
|
} catch {}
|
|
94
|
-
return values.map(
|
|
95
|
+
return values.map(normalizeScreenName).filter(Boolean);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// Compare screen names with their whitespace collapsed on both sides: a journey kept before
|
|
99
|
+
// tapp normalized headings holds "Find the right coach.\n Any goal." where the browser
|
|
100
|
+
// now reports "Find the right coach. Any goal." Those are the same screen.
|
|
101
|
+
export function normalizeScreenName(value) {
|
|
102
|
+
return String(value || "").replace(/\s+/g, " ").trim();
|
|
95
103
|
}
|
|
96
104
|
|
|
97
105
|
async function waitForScreen(page, target, timeout) {
|
|
98
106
|
const deadline = Date.now() + timeout;
|
|
99
|
-
const wanted = target.toLowerCase();
|
|
107
|
+
const wanted = normalizeScreenName(target).toLowerCase();
|
|
100
108
|
while (Date.now() < deadline) {
|
|
101
109
|
if ((await screenCandidates(page)).some((v) => v.toLowerCase() === wanted)) return true;
|
|
102
110
|
const el = await locateWebElement(page, target);
|
|
@@ -108,7 +116,7 @@ async function waitForScreen(page, target, timeout) {
|
|
|
108
116
|
|
|
109
117
|
async function waitForExactScreen(page, target, timeout) {
|
|
110
118
|
const deadline = Date.now() + timeout;
|
|
111
|
-
const wanted = target.toLowerCase();
|
|
119
|
+
const wanted = normalizeScreenName(target).toLowerCase();
|
|
112
120
|
while (Date.now() < deadline) {
|
|
113
121
|
if ((await screenCandidates(page)).some((v) => v.toLowerCase() === wanted)) return true;
|
|
114
122
|
await page.waitForTimeout(150);
|
|
@@ -223,9 +231,9 @@ export async function executeWebFlowStep({ page, step, vars = {}, defaultTimeout
|
|
|
223
231
|
if (!email || !password) throw new Error("could not identify email and password fields");
|
|
224
232
|
await email.fill(emailValue);
|
|
225
233
|
await password.fill(passwordValue);
|
|
226
|
-
const submit = await
|
|
234
|
+
const submit = await findSignInSubmit(page);
|
|
227
235
|
if (!submit) throw new Error("could not identify a sign-in control");
|
|
228
|
-
await submit.click();
|
|
236
|
+
await submit.locator.click();
|
|
229
237
|
await page.waitForTimeout(400);
|
|
230
238
|
if (await password.isVisible().catch(() => false)) throw new Error("submit left the app on the login screen");
|
|
231
239
|
} else if (action === "swipe") {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aarwitz/tapp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.33.0",
|
|
4
4
|
"mcpName": "io.github.aarwitz/tapp",
|
|
5
5
|
"description": "Let coding agents verify UI changes on real iOS, Android, and web surfaces, then enforce reviewed proof in deterministic CI.",
|
|
6
6
|
"license": "MIT",
|