@aarwitz/tapp 0.35.8 → 0.35.9
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/bin/tapp.js +15 -2
- package/browser/app.css +39 -0
- package/browser/app.js +322 -27
- package/browser/index.html +36 -3
- package/browser/product-contract.js +1 -1
- package/browser/view-model.js +24 -0
- package/docs/BROWSER-PRODUCT.md +61 -1
- package/mcp-server/src/app-store-discovery.js +42 -0
- package/mcp-server/src/browser-product.js +349 -18
- package/mcp-server/src/engines.js +212 -0
- package/mcp-server/src/flow-runtime.js +9 -1
- package/mcp-server/src/platforms.js +18 -3
- package/mcp-server/src/web-explorer.js +24 -1
- package/mcp-server/src/web-flow.js +51 -2
- package/package.json +2 -2
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
// The agent is the person's own, on their own plan; tapp is its hands (ADR-0012).
|
|
2
|
+
//
|
|
3
|
+
// tapp signs nobody in to Claude or ChatGPT and holds no token for either. Anthropic's consumer
|
|
4
|
+
// terms (2026-02-19) forbid using a Claude Free/Pro/Max OAuth token in any product but Claude
|
|
5
|
+
// Code and claude.ai — the Agent SDK included — so the only honest way to put a person's Claude
|
|
6
|
+
// plan behind the Studio chat is the one Gideon uses: find the `claude` they already signed in
|
|
7
|
+
// to, and drive it. Codex and Gemini are found the same way. This module knows which of those are
|
|
8
|
+
// on this machine, whether each is signed in with a plan (or an API key, which bills per use),
|
|
9
|
+
// and how to run one with tapp's tools attached and nothing else — no shell, no file edits.
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import os from "node:os";
|
|
12
|
+
import path from "node:path";
|
|
13
|
+
import readline from "node:readline";
|
|
14
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
15
|
+
|
|
16
|
+
export const ENGINES = Object.freeze([
|
|
17
|
+
{ id: "claude", label: "Claude Code", binary: "claude", plan: "Claude", drives: true,
|
|
18
|
+
install: "Install Claude Code from claude.com/code, then run `claude` in a terminal and sign in with your Claude account." },
|
|
19
|
+
{ id: "codex", label: "Codex", binary: "codex", plan: "ChatGPT", drives: false,
|
|
20
|
+
install: "Install Codex (npm i -g @openai/codex), then run `codex login` and sign in with your ChatGPT account." },
|
|
21
|
+
{ id: "gemini", label: "Gemini CLI", binary: "gemini", plan: "Google", drives: false,
|
|
22
|
+
install: "Install Gemini CLI (npm i -g @google/gemini-cli), then run `gemini` and sign in with Google." },
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
// What the Studio chat lets the agent do: tapp's own tools, and reading the project. Never a
|
|
26
|
+
// shell, never an edit — the agent drives the application under test, not this machine.
|
|
27
|
+
export const AGENT_ALLOWED_TOOLS = "mcp__tapp,Read,Glob,Grep";
|
|
28
|
+
export const AGENT_DISALLOWED_TOOLS = "Bash,Edit,Write,MultiEdit,NotebookEdit,WebFetch,WebSearch,Agent";
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* A GUI-launched process often has a lean PATH, and these CLIs install into a handful of
|
|
32
|
+
* well-known places; look there too, so "not installed" is only said when it is true.
|
|
33
|
+
*/
|
|
34
|
+
export function findBinary(name, { env = process.env, home = os.homedir() } = {}) {
|
|
35
|
+
const dirs = [...String(env.PATH || "").split(path.delimiter), path.join(home, ".local", "bin"), path.join(home, ".npm-global", "bin"), "/opt/homebrew/bin", "/usr/local/bin"];
|
|
36
|
+
for (const dir of dirs) {
|
|
37
|
+
if (!dir) continue;
|
|
38
|
+
const file = path.join(dir, name);
|
|
39
|
+
try { if (fs.statSync(file).isFile()) return file; } catch { /* not here */ }
|
|
40
|
+
}
|
|
41
|
+
return "";
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export function execStatus(binary, args, { env = process.env, timeoutMs = 15_000 } = {}) {
|
|
45
|
+
const run = spawnSync(binary, args, { encoding: "utf8", timeout: timeoutMs, env });
|
|
46
|
+
return { code: run.status, out: String(run.stdout || ""), err: String(run.stderr || "") };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const base = (engine, binary) => ({ id: engine.id, label: engine.label, plan: engine.plan, binary, drives: engine.drives, account: null, billing: null });
|
|
50
|
+
const missing = (engine) => ({ ...base(engine, ""), state: "missing", usable: false, detail: "Not installed on this machine.", fix: engine.install });
|
|
51
|
+
|
|
52
|
+
/** Claude Code: `claude auth status` says how it is signed in. A plan is what makes this free to use. */
|
|
53
|
+
export function claudeStatus({ env = process.env, home = os.homedir(), exec = execStatus } = {}) {
|
|
54
|
+
const engine = ENGINES[0];
|
|
55
|
+
const binary = findBinary(engine.binary, { env, home });
|
|
56
|
+
if (!binary) return missing(engine);
|
|
57
|
+
let info = null;
|
|
58
|
+
try { info = JSON.parse(exec(binary, ["auth", "status"], { env }).out); } catch { /* not JSON: an old build, or not signed in */ }
|
|
59
|
+
if (!info || info.loggedIn !== true) {
|
|
60
|
+
return { ...base(engine, binary), state: "warning", usable: false, detail: "Not signed in.", fix: "Run `claude` in a terminal and sign in with your Claude account." };
|
|
61
|
+
}
|
|
62
|
+
const account = { email: String(info.email || ""), plan: String(info.subscriptionType || "") };
|
|
63
|
+
if (info.authMethod === "claude.ai") {
|
|
64
|
+
const plan = account.plan ? `Claude ${account.plan[0].toUpperCase()}${account.plan.slice(1)}` : "Claude";
|
|
65
|
+
return { ...base(engine, binary), state: "ok", usable: true, billing: "plan", account, detail: `${plan} plan${account.email ? ` · ${account.email}` : ""}`, fix: "" };
|
|
66
|
+
}
|
|
67
|
+
return { ...base(engine, binary), state: "warning", usable: true, billing: "api-key", account, detail: "Signed in with an API key, which bills per use.", fix: "Sign in with your Claude account instead: run `claude`, then /login." };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// The ChatGPT account Codex is signed in with, from its saved sign-in: the id token's payload
|
|
71
|
+
// carries the address. Read for display only; nothing here is verified or sent anywhere.
|
|
72
|
+
function codexEmail(home) {
|
|
73
|
+
try {
|
|
74
|
+
const saved = JSON.parse(fs.readFileSync(path.join(home, ".codex", "auth.json"), "utf8"));
|
|
75
|
+
const token = String(saved?.tokens?.id_token || "");
|
|
76
|
+
const payload = token.split(".")[1];
|
|
77
|
+
if (!payload) return "";
|
|
78
|
+
const claims = JSON.parse(Buffer.from(payload.replace(/-/g, "+").replace(/_/g, "/"), "base64").toString("utf8"));
|
|
79
|
+
return String(claims.email || "");
|
|
80
|
+
} catch { return ""; }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** Codex: `codex login status` says "Logged in using ChatGPT", or an API key, or nothing. */
|
|
84
|
+
export function codexStatus({ env = process.env, home = os.homedir(), exec = execStatus } = {}) {
|
|
85
|
+
const engine = ENGINES[1];
|
|
86
|
+
const binary = findBinary(engine.binary, { env, home });
|
|
87
|
+
if (!binary) return missing(engine);
|
|
88
|
+
const { out, err } = exec(binary, ["login", "status"], { env });
|
|
89
|
+
const text = `${out}\n${err}`;
|
|
90
|
+
if (/logged in using chatgpt/i.test(text)) {
|
|
91
|
+
const email = codexEmail(home);
|
|
92
|
+
return { ...base(engine, binary), state: "ok", usable: true, billing: "plan", account: { email, plan: "ChatGPT" }, detail: `ChatGPT plan${email ? ` · ${email}` : ""}`, fix: "" };
|
|
93
|
+
}
|
|
94
|
+
if (/api key/i.test(text)) return { ...base(engine, binary), state: "warning", usable: true, billing: "api-key", detail: "Signed in with an API key, which bills per use.", fix: "Sign in with your ChatGPT account instead: run `codex logout`, then `codex login`." };
|
|
95
|
+
return { ...base(engine, binary), state: "warning", usable: false, detail: "Not signed in.", fix: "Run `codex login` in a terminal; you get a link and a code to finish on any device." };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Gemini CLI keeps its Google sign-in in a credentials file; present means signed in. */
|
|
99
|
+
export function geminiStatus({ env = process.env, home = os.homedir() } = {}) {
|
|
100
|
+
const engine = ENGINES[2];
|
|
101
|
+
const binary = findBinary(engine.binary, { env, home });
|
|
102
|
+
if (!binary) return missing(engine);
|
|
103
|
+
if (fs.existsSync(path.join(home, ".gemini", "oauth_creds.json"))) return { ...base(engine, binary), state: "ok", usable: true, billing: "plan", account: { email: "", plan: "Google" }, detail: "Google account", fix: "" };
|
|
104
|
+
return { ...base(engine, binary), state: "warning", usable: false, detail: "Not signed in.", fix: "Run `gemini` in a terminal and sign in with Google." };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Every engine tapp knows, as found on this machine. */
|
|
108
|
+
export function detectEngines(options = {}) {
|
|
109
|
+
return [claudeStatus(options), codexStatus(options), geminiStatus(options)];
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The MCP server the agent gets: this very package, on this machine, sharing TAPP_HOME. */
|
|
113
|
+
export function tappMcpConfig({ packageRoot, env = process.env, node = process.execPath }) {
|
|
114
|
+
const serverEnv = {};
|
|
115
|
+
if (env.TAPP_HOME) serverEnv.TAPP_HOME = env.TAPP_HOME;
|
|
116
|
+
return JSON.stringify({ mcpServers: { tapp: { command: node, args: [path.join(packageRoot, "bin", "tapp.js"), "mcp"], ...(Object.keys(serverEnv).length ? { env: serverEnv } : {}) } } });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* How Claude Code is run for one chat turn. Non-interactive, streaming its events as JSON lines,
|
|
121
|
+
* with tapp's tools and the project to read — and the tools that would touch this machine ruled
|
|
122
|
+
* out by name, not only left unlisted. A thread continues with `--resume`.
|
|
123
|
+
*/
|
|
124
|
+
export function claudeArguments({ prompt, resume = "", mcpConfig, systemPromptFile = "", model = "" }) {
|
|
125
|
+
const args = ["-p", String(prompt), "--output-format", "stream-json", "--verbose", "--permission-mode", "default",
|
|
126
|
+
"--allowedTools", AGENT_ALLOWED_TOOLS, "--disallowedTools", AGENT_DISALLOWED_TOOLS];
|
|
127
|
+
if (mcpConfig) args.push("--mcp-config", mcpConfig);
|
|
128
|
+
if (systemPromptFile) args.push("--append-system-prompt-file", systemPromptFile);
|
|
129
|
+
if (model) args.push("--model", model);
|
|
130
|
+
if (resume) args.push("--resume", resume);
|
|
131
|
+
return args;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
const TOOL_PREFIX = /^mcp__tapp__/;
|
|
135
|
+
const textOf = (content) => Array.isArray(content) ? content.map((b) => (typeof b === "string" ? b : b?.text || "")).join(" ") : String(content ?? "");
|
|
136
|
+
function summarizeInput(input) {
|
|
137
|
+
if (!input || typeof input !== "object") return "";
|
|
138
|
+
for (const key of ["goal", "url", "target", "action", "name", "id", "text", "query", "capture", "platform", "projectDir"]) {
|
|
139
|
+
if (typeof input[key] === "string" && input[key].trim()) return `${key}: ${input[key].trim().slice(0, 80)}`;
|
|
140
|
+
}
|
|
141
|
+
return "";
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* One Claude Code event → the chat lines a person should see. Thinking and partial deltas are
|
|
146
|
+
* not shown; tool calls are named in tapp's own words; a tool error is a warning; the final
|
|
147
|
+
* answer is the result. Returns an array, since one assistant message can carry several blocks.
|
|
148
|
+
*/
|
|
149
|
+
export function agentLines(event) {
|
|
150
|
+
if (!event || typeof event !== "object") return [];
|
|
151
|
+
if (event.type === "system" && event.subtype === "init") return [{ phase: "agent", text: "Claude Code is on it." }];
|
|
152
|
+
if (event.type === "assistant") {
|
|
153
|
+
const blocks = event.message?.content;
|
|
154
|
+
if (!Array.isArray(blocks)) return [];
|
|
155
|
+
const lines = [];
|
|
156
|
+
for (const block of blocks) {
|
|
157
|
+
if (block?.type === "text" && String(block.text || "").trim()) lines.push({ phase: "agent", text: String(block.text).trim().slice(0, 1200) });
|
|
158
|
+
if (block?.type === "tool_use") {
|
|
159
|
+
const name = String(block.name || "tool").replace(TOOL_PREFIX, "");
|
|
160
|
+
const summary = summarizeInput(block.input);
|
|
161
|
+
lines.push({ phase: "agent-tool", text: `${name}${summary ? ` — ${summary}` : ""}` });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
return lines;
|
|
165
|
+
}
|
|
166
|
+
if (event.type === "user") {
|
|
167
|
+
const blocks = event.message?.content;
|
|
168
|
+
if (!Array.isArray(blocks)) return [];
|
|
169
|
+
return blocks.filter((b) => b?.type === "tool_result" && b.is_error).map((b) => ({ phase: "agent-warning", text: `Tool error: ${textOf(b.content).trim().slice(0, 300)}` }));
|
|
170
|
+
}
|
|
171
|
+
if (event.type === "result") {
|
|
172
|
+
const text = String(event.result || "").trim().slice(0, 1200);
|
|
173
|
+
if (event.is_error) return [{ phase: "agent-warning", text: text || "Claude Code stopped with an error." }];
|
|
174
|
+
return text ? [{ phase: "agent-done", text }] : [];
|
|
175
|
+
}
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Run Claude Code for one turn. Resolves with the result event's facts once the process ends;
|
|
181
|
+
* rejects when it ends with no result. `stop()` ends the turn the way Ctrl-C would.
|
|
182
|
+
*/
|
|
183
|
+
export function runClaude({ binary, args, cwd, env = process.env, onEvent = () => {} }) {
|
|
184
|
+
const child = spawn(binary, args, { cwd, env, stdio: ["ignore", "pipe", "pipe"] });
|
|
185
|
+
let result = null;
|
|
186
|
+
let stderrTail = "";
|
|
187
|
+
let stdoutTail = "";
|
|
188
|
+
child.stderr.on("data", (chunk) => { stderrTail = (stderrTail + chunk).slice(-2000); });
|
|
189
|
+
const lines = readline.createInterface({ input: child.stdout });
|
|
190
|
+
lines.on("line", (line) => {
|
|
191
|
+
if (!line.trim()) return;
|
|
192
|
+
let event;
|
|
193
|
+
try { event = JSON.parse(line); } catch { stdoutTail = (stdoutTail + line).slice(-2000); return; }
|
|
194
|
+
if (event?.type === "result") result = event;
|
|
195
|
+
try { onEvent(event); } catch { /* a listener's problem is not the run's */ }
|
|
196
|
+
});
|
|
197
|
+
const done = new Promise((resolve, reject) => {
|
|
198
|
+
child.on("error", (error) => reject(new Error(`Could not start Claude Code: ${error.message}`)));
|
|
199
|
+
child.on("close", (code, signal) => {
|
|
200
|
+
// The stream can still be draining when the process closes; let it finish.
|
|
201
|
+
setImmediate(() => {
|
|
202
|
+
if (result) {
|
|
203
|
+
resolve({ sessionId: String(result.session_id || ""), text: String(result.result || ""), turns: Number(result.num_turns) || 0, costUsd: Number(result.total_cost_usd) || 0, isError: result.is_error === true, stopped: signal === "SIGINT" });
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
const reason = (stderrTail || stdoutTail).trim().split("\n").filter(Boolean).slice(-3).join(" · ");
|
|
207
|
+
reject(new Error(signal ? `Claude Code was stopped (${signal})` : `Claude Code ended (exit ${code}) without a result${reason ? `: ${reason}` : ""}`));
|
|
208
|
+
});
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
return { child, done, stop: () => { try { child.kill("SIGINT"); } catch { /* already gone */ } } };
|
|
212
|
+
}
|
|
@@ -50,6 +50,7 @@ export const FLOW_ACTIONS = Object.freeze([
|
|
|
50
50
|
{ action: "screenshot", target: "a name for the picture", passes: "a viewport-sized picture was saved beside the run's evidence; web only" },
|
|
51
51
|
{ action: "back", target: "(none)", passes: "the platform back navigation was performed" },
|
|
52
52
|
{ action: "open_url", target: "a URL or deep link (myapp://claim?t=$TOKEN; $NAME substitutes like any other step)", passes: "the link was opened and the app under test came to the front (iOS/Android); on web, the page navigated there. Not supported on macOS" },
|
|
53
|
+
{ action: "upload", target: "{field, file} — file is a local path, resolved relative to the Flow file", passes: "the file was chosen for that <input type=file>, including one hidden behind a styled label, and the page's change handler ran; web only" },
|
|
53
54
|
{ action: "wait", target: "milliseconds (fixed pause; prefer wait_for)", passes: "always" },
|
|
54
55
|
{ action: "wait_for", target: "label / text (+ per-step timeoutMs/timeout; flow-level timeoutMs sets the default)", passes: "the element appeared before the timeout" },
|
|
55
56
|
{ action: "assert_screen", target: "the detected SCREEN TITLE (navigation bar / heading), not arbitrary text", passes: "the current screen's title equals the target" },
|
|
@@ -110,6 +111,9 @@ export function validateFlowSteps(flow, platform = inferFlowPlatform(flow)) {
|
|
|
110
111
|
if (step.action === "type" && (!step.target.trim() || !("value" in (step.params || {})))) {
|
|
111
112
|
errors.push(`step ${n}: type needs {field, value}`);
|
|
112
113
|
}
|
|
114
|
+
if (step.action === "upload" && (!step.target.trim() || !String(step.params.file ?? "").trim())) {
|
|
115
|
+
errors.push(`step ${n}: upload needs {field, file}`);
|
|
116
|
+
}
|
|
113
117
|
if (step.action === "assert_text" && (!step.target.trim() || !step.value)) {
|
|
114
118
|
errors.push(`step ${n}: assert_text needs {of, contains}`);
|
|
115
119
|
}
|
|
@@ -175,7 +179,11 @@ export function loadFlowFile(flowPath, options = {}) {
|
|
|
175
179
|
if (parsed.status !== 0) {
|
|
176
180
|
throw new Error((parsed.stderr || parsed.stdout || "Could not parse Flow").trim());
|
|
177
181
|
}
|
|
178
|
-
|
|
182
|
+
const compiled = compileFlowTasksFromRepository({ flow: JSON.parse(parsed.stdout), sourcePath: flowPath, ...options });
|
|
183
|
+
// TM-1077: an `upload:` step's file path is relative to the Flow file, not the
|
|
184
|
+
// process's cwd — carried on the flow object itself so every runner (web today;
|
|
185
|
+
// the vocabulary is shared) can resolve it without its own sourcePath parameter.
|
|
186
|
+
return { ...compiled, sourcePath: flowPath };
|
|
179
187
|
}
|
|
180
188
|
|
|
181
189
|
export class FlowLog {
|
|
@@ -84,6 +84,18 @@ export function hostToolchain({ env = process.env, platform = process.platform }
|
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
+
// What to install on THIS machine when it is the right kind and lacks the one thing. Returns
|
|
88
|
+
// null when the machine is the wrong kind, so the general "needs a Mac" answer stands.
|
|
89
|
+
const MISSING_ON_THIS_MACHINE = {
|
|
90
|
+
ios: (platform) => platform === "darwin"
|
|
91
|
+
? { summary: "This Mac has no Xcode yet.", how: "Install Xcode from the App Store and open it once to finish its setup. tapp then builds and boots a simulator itself; give it a repository, a simulator .app or a bundle id." }
|
|
92
|
+
: null,
|
|
93
|
+
macos: (platform) => platform === "darwin"
|
|
94
|
+
? { summary: "This Mac has not given tapp the Accessibility permission.", how: "System Settings → Privacy & Security → Accessibility: allow the app that runs tapp (your terminal, or Node). Then give it a .app." }
|
|
95
|
+
: null,
|
|
96
|
+
android: () => ({ summary: "The Android SDK is not on this machine, or adb cannot be found.", how: "Install Android Studio (or the command-line tools) so adb exists — set ANDROID_HOME if tapp still cannot find it — then plug in a phone with USB debugging allowed, or start an emulator, and give it an .apk." }),
|
|
97
|
+
};
|
|
98
|
+
|
|
87
99
|
/** The command that opens this same Studio on a machine that can do the work. */
|
|
88
100
|
export const SELF_HOST_COMMAND = "npx -y @aarwitz/tapp@latest app";
|
|
89
101
|
|
|
@@ -122,16 +134,19 @@ export function platformStates({ hosted = false, env = process.env, platform = p
|
|
|
122
134
|
};
|
|
123
135
|
}
|
|
124
136
|
const because = has[target.id] && !exposed ? "not-exposed" : "no-toolchain";
|
|
137
|
+
// The right machine, missing one thing, is a different sentence from the wrong machine: a
|
|
138
|
+
// Mac without Xcode is told to install Xcode, not to find a Mac (ADR-0012's setup flow).
|
|
139
|
+
const missing = because === "no-toolchain" && !hosted ? MISSING_ON_THIS_MACHINE[target.id]?.(platform) : null;
|
|
125
140
|
return {
|
|
126
141
|
...target,
|
|
127
142
|
state: "needs-machine", because,
|
|
128
143
|
summary: because === "not-exposed"
|
|
129
144
|
? `tapp drives ${target.subject}, and this machine could — but a public Studio only starts website runs.`
|
|
130
|
-
: `tapp drives ${target.subject}, but this Studio is not on ${target.machine}.`,
|
|
145
|
+
: missing ? missing.summary : `tapp drives ${target.subject}, but this Studio is not on ${target.machine}.`,
|
|
131
146
|
// Two ways out, always both: self-host is the same product without the hosting (ADR-0006),
|
|
132
147
|
// and not everyone has the machine or wants to keep it awake.
|
|
133
|
-
how: `Run this Studio on ${target.machine} and give it ${lower(target.give)} there — or have tapp run it for you.`,
|
|
134
|
-
command: SELF_HOST_COMMAND,
|
|
148
|
+
how: missing ? missing.how : `Run this Studio on ${target.machine} and give it ${lower(target.give)} there — or have tapp run it for you.`,
|
|
149
|
+
command: missing ? "" : SELF_HOST_COMMAND,
|
|
135
150
|
};
|
|
136
151
|
});
|
|
137
152
|
}
|
|
@@ -552,7 +552,28 @@ export function browserStartupReason(lines) {
|
|
|
552
552
|
return reasons.slice(0, 5);
|
|
553
553
|
}
|
|
554
554
|
|
|
555
|
-
|
|
555
|
+
// An approved browser environment for runs where the browser tapp would start itself is not allowed
|
|
556
|
+
// to start (a restricted macOS runner kills Chromium with SIGTRAP at its Mach-port check-in).
|
|
557
|
+
// TAPP_BROWSER_ENDPOINT http(s)/ws URL on this machine of a Chromium that something outside the
|
|
558
|
+
// restriction already started with --remote-debugging-port; tapp attaches.
|
|
559
|
+
// TAPP_BROWSER_EXECUTABLE path of an approved Chromium/Chrome binary tapp starts instead of its own.
|
|
560
|
+
export function approvedBrowserEndpoint(environment = process.env) {
|
|
561
|
+
const raw = String(environment.TAPP_BROWSER_ENDPOINT || "").trim();
|
|
562
|
+
if (!raw) return null;
|
|
563
|
+
let url;
|
|
564
|
+
try { url = new URL(raw); } catch { throw new Error("TAPP_BROWSER_ENDPOINT is not a URL"); }
|
|
565
|
+
if (!/^(https?|wss?):$/.test(url.protocol) || !["127.0.0.1", "localhost", "[::1]"].includes(url.hostname)) {
|
|
566
|
+
throw new Error("TAPP_BROWSER_ENDPOINT must be a http or ws URL on this machine (127.0.0.1 or localhost)");
|
|
567
|
+
}
|
|
568
|
+
if (environment.TAPP_ENFORCE_PUBLIC_EGRESS === "1") {
|
|
569
|
+
throw new Error("TAPP_BROWSER_ENDPOINT cannot be used under the public egress policy: tapp cannot enforce the proxy on a browser it did not start");
|
|
570
|
+
}
|
|
571
|
+
return raw;
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
export async function launchWebBrowser(chromium, options, environment = process.env) {
|
|
575
|
+
const endpoint = approvedBrowserEndpoint(environment);
|
|
576
|
+
if (endpoint) return await chromium.connectOverCDP(endpoint);
|
|
556
577
|
const lines = [];
|
|
557
578
|
const logger = {
|
|
558
579
|
isEnabled: (name) => name === "browser",
|
|
@@ -577,8 +598,10 @@ export function webBrowserLaunchOptions(environment = process.env, { watch = fal
|
|
|
577
598
|
if (environment.TAPP_ENFORCE_PUBLIC_EGRESS === "1" && !/^http:\/\/127\.0\.0\.1:\d+$/.test(browserProxy)) {
|
|
578
599
|
throw new Error("public egress policy proxy is required");
|
|
579
600
|
}
|
|
601
|
+
const executable = String(environment.TAPP_BROWSER_EXECUTABLE || "").trim();
|
|
580
602
|
return {
|
|
581
603
|
headless: !watch,
|
|
604
|
+
...(executable ? { executablePath: executable } : {}),
|
|
582
605
|
...(watch ? { slowMo: 200 } : {}),
|
|
583
606
|
...(browserProxy ? { proxy: { server: browserProxy, bypass: "<-loopback>" } } : {}),
|
|
584
607
|
args: browserProxy ? [
|
|
@@ -66,6 +66,40 @@ function targetCandidates(scope, target) {
|
|
|
66
66
|
];
|
|
67
67
|
}
|
|
68
68
|
|
|
69
|
+
// TM-1077: a file input for `upload:`. Visibility-agnostic on purpose — a file
|
|
70
|
+
// picker is routinely a real <input type=file> hidden behind a styled label or
|
|
71
|
+
// button (opacity/position, never display:none, which browsers refuse to let
|
|
72
|
+
// choose a file at all), and Playwright's setInputFiles works on it either way.
|
|
73
|
+
// locateWebElement's firstVisible() would skip it, so this never calls it.
|
|
74
|
+
async function locateFileInput(page, target) {
|
|
75
|
+
const candidates = [
|
|
76
|
+
page.getByTestId(target),
|
|
77
|
+
page.locator(cssId(target)),
|
|
78
|
+
page.getByLabel(target, { exact: true }),
|
|
79
|
+
page.getByLabel(target),
|
|
80
|
+
];
|
|
81
|
+
for (const locator of candidates) {
|
|
82
|
+
try {
|
|
83
|
+
const first = locator.first();
|
|
84
|
+
if ((await first.count()) === 0) continue;
|
|
85
|
+
const tag = await first.evaluate((el) => el.tagName).catch(() => "");
|
|
86
|
+
if (tag === "INPUT") {
|
|
87
|
+
const type = (await first.getAttribute("type").catch(() => "")) || "";
|
|
88
|
+
if (!type || type.toLowerCase() === "file") return first;
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
// A styled label/button that wraps the real input rather than being it.
|
|
92
|
+
const inner = first.locator("input[type=file]").first();
|
|
93
|
+
if ((await inner.count()) > 0) return inner;
|
|
94
|
+
} catch { /* try the next candidate */ }
|
|
95
|
+
}
|
|
96
|
+
// Last resort: the page's one file input, when the target names it (id, name,
|
|
97
|
+
// aria-label, nearby text) in a way none of the semantic locators matched.
|
|
98
|
+
const only = page.locator("input[type=file]");
|
|
99
|
+
if ((await only.count().catch(() => 0)) === 1) return only.first();
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
|
|
69
103
|
export async function locateWebElement(page, target) {
|
|
70
104
|
const top = await firstVisible(targetCandidates(page, target));
|
|
71
105
|
if (top) return top;
|
|
@@ -203,7 +237,7 @@ export function distillPlaywrightFailure(message) {
|
|
|
203
237
|
return `${firstLine} — ${reason}`;
|
|
204
238
|
}
|
|
205
239
|
|
|
206
|
-
export async function executeWebFlowStep({ page, step, vars = {}, defaultTimeout = DEFAULT_TIMEOUT, stepScreenshotDir = "" }) {
|
|
240
|
+
export async function executeWebFlowStep({ page, step, vars = {}, defaultTimeout = DEFAULT_TIMEOUT, stepScreenshotDir = "", flowDir = "" }) {
|
|
207
241
|
const raw = normalizeFlowStep(step);
|
|
208
242
|
const action = raw.action;
|
|
209
243
|
const target = substituteFlowValue(raw.target, vars);
|
|
@@ -353,6 +387,18 @@ export async function executeWebFlowStep({ page, step, vars = {}, defaultTimeout
|
|
|
353
387
|
// A journey starting from an email link ("tap the sign-in link in your receipt") is just a
|
|
354
388
|
// navigation on web — the one-time part of the link substitutes like any other target.
|
|
355
389
|
await page.goto(target, { waitUntil: "domcontentloaded" });
|
|
390
|
+
} else if (action === "upload") {
|
|
391
|
+
// TM-1077: an admin "Import contacts" page (and certificate/newsletter uploads) starts
|
|
392
|
+
// with choosing a local file — the only way to replay that journey as a committed Flow
|
|
393
|
+
// from the start. The path is relative to the Flow file, not wherever `tapp run` happened
|
|
394
|
+
// to be invoked from, so a Flow stays correct wherever it's checked out.
|
|
395
|
+
const filePath = substituteFlowValue(String(raw.params.file ?? ""), vars);
|
|
396
|
+
if (!filePath) throw new Error("upload needs {field, file}");
|
|
397
|
+
const resolved = path.isAbsolute(filePath) ? filePath : path.resolve(flowDir || process.cwd(), filePath);
|
|
398
|
+
if (!fs.existsSync(resolved)) throw new Error(`upload file not found: ${resolved}`);
|
|
399
|
+
const input = await locateFileInput(page, target);
|
|
400
|
+
if (!input) throw new Error(`could not find a file picker for ‘${target}’`);
|
|
401
|
+
await input.setInputFiles(resolved);
|
|
356
402
|
} else if (action === "wait_for") {
|
|
357
403
|
if (!await waitForScreen(page, target, timeout)) throw new Error(`‘${target}’ never appeared within ${timeout}ms${await visibleLabelsHint(page)}`);
|
|
358
404
|
} else if (action === "wait") {
|
|
@@ -422,6 +468,9 @@ export async function runWebFlow({ flow, url, logPath, screenshotDir, recordVide
|
|
|
422
468
|
const declaredUrl = flow.url || (/^https?:\/\//i.test(flow.app || "") ? flow.app : "");
|
|
423
469
|
const startUrl = urlIsFallback ? resolveGateFlowUrl(declaredUrl, url) : (url || declaredUrl);
|
|
424
470
|
if (!startUrl) throw new Error("Web Flow needs `url:` (or an http(s) `app:` value)");
|
|
471
|
+
// TM-1077: an `upload:` step's file path is relative to the Flow file (stamped
|
|
472
|
+
// on it by loadFlowFile), not the directory `tapp run` happened to be invoked from.
|
|
473
|
+
const flowDir = flow.sourcePath ? path.dirname(flow.sourcePath) : process.cwd();
|
|
425
474
|
if (logPath) fs.rmSync(logPath, { force: true });
|
|
426
475
|
const setup = flow.setup || [];
|
|
427
476
|
const teardown = flow.teardown || [];
|
|
@@ -474,7 +523,7 @@ export async function runWebFlow({ flow, url, logPath, screenshotDir, recordVide
|
|
|
474
523
|
emit({action:"origin",target:"connected app",status:"fail",detail:"The workflow left the connected app origin. Authorize a supported sign-in route before continuing."});
|
|
475
524
|
break;
|
|
476
525
|
}
|
|
477
|
-
const outcome = await executeWebFlowStep({ page, step, vars, defaultTimeout: timeout, stepScreenshotDir: screenshotDir });
|
|
526
|
+
const outcome = await executeWebFlowStep({ page, step, vars, defaultTimeout: timeout, stepScreenshotDir: screenshotDir, flowDir });
|
|
478
527
|
emit(outcome);
|
|
479
528
|
if (outcome.status === "fail" && screenshotDir) {
|
|
480
529
|
fs.mkdirSync(screenshotDir, { recursive: true });
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aarwitz/tapp",
|
|
3
|
-
"version": "0.35.
|
|
3
|
+
"version": "0.35.9",
|
|
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",
|
|
@@ -98,7 +98,7 @@
|
|
|
98
98
|
"mobile"
|
|
99
99
|
],
|
|
100
100
|
"scripts": {
|
|
101
|
-
"test": "node --test tests/report.test.js tests/regression.test.js tests/engine.test.js tests/project-config.test.js tests/application-model.test.js tests/ui-map.test.js tests/focused-navigation.test.js tests/task-runtime.test.js tests/release-contract.test.js tests/pr-selection.test.js tests/flow-runtime.test.js tests/flow-variables.test.js tests/flow-recording.test.js tests/sim-recorder.test.js tests/feedback.test.js tests/web-explorer.test.js tests/web-session.test.js tests/web-link-audit.test.js tests/web-overlay.test.js tests/web-audit.test.js tests/page-observations.test.js tests/capture-provenance.test.js tests/capture-frames.test.js tests/actor-store.test.js tests/account-store.test.js tests/alerts.test.js tests/access-jwt.test.js tests/oauth.test.js tests/studio-client.test.js tests/journeys.test.js tests/ios-crash-attribution.test.js tests/ios-simulator-selection.test.js tests/ios-recording-stop.test.js tests/web-flow.test.js tests/sign-in.test.js tests/signin-honesty.test.js tests/scenario-runtime.test.js tests/android-driver.test.js tests/android-explorer.test.js tests/evidence-retention.test.js tests/android-flow.test.js tests/macos-driver.test.js tests/macos-flow.test.js tests/android-primitives-protocol.test.js tests/managed-web.test.js tests/product-operations.test.js tests/job-lanes.test.js tests/browser-product.test.js tests/browser-chat-narration.test.js tests/browser-run-reading.test.js tests/browser-onboarding.test.js tests/managed-operation.test.js tests/ci-setup.test.js tests/ci-install.test.js tests/cli.test.js tests/mcp-workspace.test.js tests/action.test.js tests/package-surface.test.js tests/agent-surface.test.js tests/platforms.test.js tests/presentation-contract.test.js tests/landing-brand.test.js tests/ci-gate.test.js tests/ci-report.test.js tests/desktop-protocol.test.js tests/ios-flow-protocol.test.js tests/feedback-triage-0919.test.js vscode-extension/test/bridge.test.js",
|
|
101
|
+
"test": "node --test tests/report.test.js tests/regression.test.js tests/engine.test.js tests/project-config.test.js tests/application-model.test.js tests/ui-map.test.js tests/focused-navigation.test.js tests/task-runtime.test.js tests/release-contract.test.js tests/pr-selection.test.js tests/flow-runtime.test.js tests/flow-variables.test.js tests/flow-recording.test.js tests/sim-recorder.test.js tests/feedback.test.js tests/web-explorer.test.js tests/web-session.test.js tests/web-link-audit.test.js tests/web-overlay.test.js tests/web-audit.test.js tests/page-observations.test.js tests/capture-provenance.test.js tests/capture-frames.test.js tests/actor-store.test.js tests/account-store.test.js tests/alerts.test.js tests/access-jwt.test.js tests/oauth.test.js tests/studio-client.test.js tests/engines.test.js tests/journeys.test.js tests/ios-crash-attribution.test.js tests/ios-simulator-selection.test.js tests/ios-recording-stop.test.js tests/web-flow.test.js tests/sign-in.test.js tests/signin-honesty.test.js tests/scenario-runtime.test.js tests/android-driver.test.js tests/android-explorer.test.js tests/evidence-retention.test.js tests/android-flow.test.js tests/macos-driver.test.js tests/macos-flow.test.js tests/android-primitives-protocol.test.js tests/managed-web.test.js tests/product-operations.test.js tests/job-lanes.test.js tests/browser-product.test.js tests/browser-chat-narration.test.js tests/browser-run-reading.test.js tests/browser-onboarding.test.js tests/managed-operation.test.js tests/ci-setup.test.js tests/ci-install.test.js tests/cli.test.js tests/mcp-workspace.test.js tests/action.test.js tests/package-surface.test.js tests/agent-surface.test.js tests/platforms.test.js tests/presentation-contract.test.js tests/landing-brand.test.js tests/ci-gate.test.js tests/ci-report.test.js tests/desktop-protocol.test.js tests/ios-flow-protocol.test.js tests/feedback-triage-0919.test.js vscode-extension/test/bridge.test.js",
|
|
102
102
|
"test:browser-journey": "node --test tests/browser-journey.test.js",
|
|
103
103
|
"test:browser-native": "TAPP_RUN_NATIVE_BROWSER=1 node --test tests/browser-native-journey.test.js"
|
|
104
104
|
}
|