@aarwitz/tapp 0.24.1 → 0.25.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/bin/tapp.js +74 -1
- package/browser/app.css +12 -0
- package/browser/app.js +72 -2
- package/browser/index.html +8 -0
- package/docs/BROWSER-PRODUCT.md +27 -0
- package/mcp-server/src/account-store.js +58 -0
- package/mcp-server/src/browser-product.js +75 -14
- package/mcp-server/src/index.js +64 -1
- package/mcp-server/src/studio-client.js +78 -0
- package/package.json +2 -2
|
@@ -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.25.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.25.0",
|
|
28
28
|
"mcp"
|
|
29
29
|
],
|
|
30
30
|
"cwd": "${CLAUDE_PROJECT_DIR}"
|
package/bin/tapp.js
CHANGED
|
@@ -410,7 +410,7 @@ function safeCommandUsage(verb) {
|
|
|
410
410
|
ci: "tapp ci ...\ntapp ci install [repo] [--out FILE] [--manifest FILE] [--dry-run] [--replace]\ntapp ci baseline [repo] [--platform PLATFORM] [--target NAME] [--from GATE.json] [--replace]",
|
|
411
411
|
actor: "tapp plan actor set NAME --email-env ENV --password-env ENV [--replace] [--project-dir DIR]\ntapp plan actor list [repo]",
|
|
412
412
|
app: "tapp app [repo] [--no-open] [--port PORT]",
|
|
413
|
-
report: "tapp report [captureId|latest]",
|
|
413
|
+
report: "tapp report [captureId|latest]\n --journeys: list the journeys you own and how each one's last check went (exit 1 if any is failing)\n Add --studio https://app.runtapp.com (or $TAPP_STUDIO) with a token from the Studio's “Your coding agent” card ($TAPP_TOKEN) to ask your hosted Studio.",
|
|
414
414
|
feedback: "tapp feedback \"short title\" [--body TEXT|--body-file FILE] [--type bug|idea|question] [--capture ID|latest|none] [--as human] [--submit] [--json]\n Drafts a public GitHub issue on aarwitz/tapp about tapp itself; --submit files it with the authenticated gh CLI.\n Exit codes: 0 drafted or filed · 1 gh submission failed · 2 usage error",
|
|
415
415
|
audit: "tapp explore --read-only <url> [<url>...] [--urls FILE] [--pages N] [--delay MS] [--links N] [--json [FILE]] [--no-capture] [--device NAME] [--viewport WxH]\n Read-only: renders each page and reads it, never clicks — safe to point at production or a site you do not own.\n Finds dead controls, broken images/assets/links, 5xx/failed requests, JS exceptions, mixed content, horizontal overflow.\n --pages N crawls same-origin links (robots.txt honoured, --delay between pages). Writes a capture with screenshots, evidence and report.html.\n Exit codes: 0 nothing broken · 1 defects found · 2 usage/infrastructure",
|
|
416
416
|
doctor: "tapp doctor [--json] [--install]\n --install prebuilds the iOS exploration harness (~2 min; otherwise it builds on first use)\n Exit codes: 0 environment healthy · 1 blocked (fix ❌ items)",
|
|
@@ -442,6 +442,10 @@ if (!knownCommands.has(command)) {
|
|
|
442
442
|
console.error("Run `npx -y @aarwitz/tapp@latest --help` for the command reference.");
|
|
443
443
|
process.exit(2);
|
|
444
444
|
}
|
|
445
|
+
// The verb the person actually typed, before aliasing rewrites it — `run` becomes `flow`, and a
|
|
446
|
+
// journey on a hosted Studio is not a file in this directory.
|
|
447
|
+
const typedCommand = command;
|
|
448
|
+
const typedRest = [...rest];
|
|
445
449
|
{
|
|
446
450
|
const helpRequested = rest.includes("--help") || rest.includes("-h");
|
|
447
451
|
const resolved = resolveCommand(command, rest);
|
|
@@ -463,6 +467,75 @@ if (!["help", "version", "--version", "-v"].includes(command)) {
|
|
|
463
467
|
fs.mkdirSync(tappHome, { recursive: true });
|
|
464
468
|
}
|
|
465
469
|
|
|
470
|
+
// Journeys, locally or on a hosted Studio. This is how the owner's coding agent asks "is
|
|
471
|
+
// everything still passing?" and runs one — no new verb, just somewhere else to look (ADR-0007).
|
|
472
|
+
if (typedCommand === "report" && typedRest.includes("--journeys")) {
|
|
473
|
+
const { flags } = parseVerbArgs(typedRest.filter((a) => a !== "--journeys"));
|
|
474
|
+
const { studioConfig, listStudioJourneys, formatJourneyStatus } = await import(path.join(packageRoot, "mcp-server", "src", "studio-client.js"));
|
|
475
|
+
let journeys = [];
|
|
476
|
+
let where = "";
|
|
477
|
+
try {
|
|
478
|
+
const config = studioConfig({ studio: flags.studio, token: flags.token });
|
|
479
|
+
if (config) {
|
|
480
|
+
journeys = await listStudioJourneys(config);
|
|
481
|
+
where = config.origin;
|
|
482
|
+
} else {
|
|
483
|
+
const { JourneyStore } = await import(path.join(packageRoot, "mcp-server", "src", "journeys.js"));
|
|
484
|
+
const root = process.cwd();
|
|
485
|
+
if (fs.existsSync(path.join(root, ".tapp", "flows"))) {
|
|
486
|
+
// A repository's journeys are its committed Flows, subfolders and all — the same list the
|
|
487
|
+
// Studio shows — with whatever the last Studio replay recorded beside each.
|
|
488
|
+
const { readProductProject } = await import(path.join(packageRoot, "mcp-server", "src", "product-operations.js"));
|
|
489
|
+
const store = JourneyStore.forRepository(root);
|
|
490
|
+
journeys = (readProductProject({ projectDir: root }).flows || []).map((flow) => {
|
|
491
|
+
const slug = flow.relativePath.replace(/^\.tapp\/flows\//, "").replace(/\.(?:ya?ml|json)$/i, "");
|
|
492
|
+
return { name: flow.name, slug, platform: flow.platform, steps: flow.steps, source: "repo", status: store.status(slug) };
|
|
493
|
+
});
|
|
494
|
+
where = ".tapp/flows";
|
|
495
|
+
} else {
|
|
496
|
+
journeys = JourneyStore.forMachine().list();
|
|
497
|
+
where = "this machine";
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
} catch (error) {
|
|
501
|
+
console.error(`❌ ${error.message}`);
|
|
502
|
+
process.exit(2);
|
|
503
|
+
}
|
|
504
|
+
if (flags.json) {
|
|
505
|
+
console.log(JSON.stringify({ where, journeys }, null, 2));
|
|
506
|
+
} else if (!journeys.length) {
|
|
507
|
+
console.log(`No journeys yet (${where}). Explore an app — when a run gets somewhere, tapp offers to keep it.`);
|
|
508
|
+
} else {
|
|
509
|
+
console.log(`Journeys · ${where}`);
|
|
510
|
+
for (const journey of journeys) console.log(` ${formatJourneyStatus(journey)}`);
|
|
511
|
+
}
|
|
512
|
+
// A failing journey is the whole point of asking, so it is also the exit code.
|
|
513
|
+
process.exit(journeys.some((j) => j.status && !j.status.passed) ? 1 : 0);
|
|
514
|
+
}
|
|
515
|
+
if (typedCommand === "run" && (typedRest.includes("--studio") || process.env.TAPP_STUDIO)) {
|
|
516
|
+
const { flags, positionals } = parseVerbArgs(typedRest);
|
|
517
|
+
const name = String(positionals[0] || "").replace(/\.ya?ml$/i, "");
|
|
518
|
+
if (!name) {
|
|
519
|
+
console.error("❌ tapp run <journey> --studio https://app.runtapp.com (the journey's name in the Studio)");
|
|
520
|
+
process.exit(2);
|
|
521
|
+
}
|
|
522
|
+
const { studioConfig, runStudioJourney } = await import(path.join(packageRoot, "mcp-server", "src", "studio-client.js"));
|
|
523
|
+
try {
|
|
524
|
+
const config = studioConfig({ studio: flags.studio, token: flags.token });
|
|
525
|
+
console.log(`▶ ${name} · ${config.origin}`);
|
|
526
|
+
const result = await runStudioJourney(config, name, { onProgress: (line) => console.log(` ${line}`) });
|
|
527
|
+
if (result.kind === "self-host") {
|
|
528
|
+
console.log(`ℹ️ ${result.message}`);
|
|
529
|
+
process.exit(2);
|
|
530
|
+
}
|
|
531
|
+
console.log(result.passed ? `✓ ${result.name} — ${result.executed}/${result.total} steps` : `✗ ${result.name} — ${result.executed}/${result.total} steps, ${result.failed} failed`);
|
|
532
|
+
process.exit(result.passed ? 0 : 1);
|
|
533
|
+
} catch (error) {
|
|
534
|
+
console.error(`❌ ${error.message}`);
|
|
535
|
+
process.exit(2);
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
|
|
466
539
|
switch (command) {
|
|
467
540
|
case "workflows": {
|
|
468
541
|
const {flags,positionals}=parseVerbArgs(rest);
|
package/browser/app.css
CHANGED
|
@@ -582,3 +582,15 @@ dialog::backdrop { background:rgba(0,0,0,.6); }
|
|
|
582
582
|
.journey-status.never { background:var(--control); color:var(--muted); }
|
|
583
583
|
.journey-actions { display:flex; gap:6px; }
|
|
584
584
|
.chat-keep .ask-field input { font:inherit; font-size:13px; padding:8px 10px; border-radius:8px; border:1px solid var(--tapp-border); background:rgba(0,0,0,.25); color:var(--tapp-text); }
|
|
585
|
+
|
|
586
|
+
/* Agent access (ADR-0009 slice 4). */
|
|
587
|
+
.token-row { display:grid; grid-template-columns:1fr auto; gap:10px; align-items:center; padding:8px 10px; border-bottom:1px solid var(--tapp-border); font-size:13px; }
|
|
588
|
+
.token-row:last-child { border-bottom:0; }
|
|
589
|
+
.token-row small { color:var(--muted); }
|
|
590
|
+
.token-reveal { margin:10px 0 2px; padding:12px; border-radius:var(--tapp-radius-lg, 12px); border:1px solid var(--tapp-accent, #4f6cf7); background:rgba(15,26,34,.85); display:grid; gap:8px; }
|
|
591
|
+
.token-reveal p { margin:0; font-size:13px; line-height:1.5; }
|
|
592
|
+
.token-reveal code { display:block; overflow-x:auto; white-space:pre; font-size:12px; padding:9px 10px; border-radius:8px; background:rgba(0,0,0,.35); border:1px solid var(--tapp-border); }
|
|
593
|
+
.token-reveal .ask-actions { display:flex; gap:8px; }
|
|
594
|
+
.token-reveal button { font:inherit; font-size:12px; padding:7px 12px; border-radius:8px; cursor:pointer; }
|
|
595
|
+
.owned-link { text-align:center; margin-top:10px; }
|
|
596
|
+
.owned-link button { font:inherit; font-size:13px; padding:7px 14px; border-radius:999px; border:1px solid var(--line); background:var(--control); color:inherit; cursor:pointer; }
|
package/browser/app.js
CHANGED
|
@@ -156,6 +156,7 @@ function applyAccessMode() {
|
|
|
156
156
|
: "Websites are audited read-only in the cloud; nothing is clicked. Sign in to go inside a site. iOS, Android and folders on your own machine need tapp there: npx -y @aarwitz/tapp@latest app";
|
|
157
157
|
$("#actors-panel")?.classList.toggle("hidden", !signedIn);
|
|
158
158
|
$("#journeys-panel")?.classList.toggle("hidden", !signedIn);
|
|
159
|
+
$("#agent-panel")?.classList.toggle("hidden", !signedIn);
|
|
159
160
|
}
|
|
160
161
|
|
|
161
162
|
// The test accounts tapp holds, by application — names and what is held, never a value.
|
|
@@ -172,6 +173,48 @@ function renderActors() {
|
|
|
172
173
|
}).join("")}`).join("");
|
|
173
174
|
}
|
|
174
175
|
|
|
176
|
+
// Tokens are labels and dates here; the value exists once, in the card below, and never again.
|
|
177
|
+
function renderTokens() {
|
|
178
|
+
const node = $("#token-list");
|
|
179
|
+
if (!node) return;
|
|
180
|
+
const tokens = state.tokens || [];
|
|
181
|
+
setCount("#token-count", tokens.length);
|
|
182
|
+
const reveal = state.newToken ? `<div class="token-reveal">
|
|
183
|
+
<p><b>Copy this now — it is not shown again.</b> Give your coding agent these two values:</p>
|
|
184
|
+
<code id="token-value">export TAPP_STUDIO=${esc(location.origin)}
|
|
185
|
+
export TAPP_TOKEN=${esc(state.newToken.token)}</code>
|
|
186
|
+
<p>Then it can ask <code style="display:inline;padding:2px 5px">tapp report --journeys</code> and replay one with <code style="display:inline;padding:2px 5px">tapp run <journey></code>.</p>
|
|
187
|
+
<div class="ask-actions"><button type="button" class="primary" data-copy-token>Copy</button><button type="button" class="quiet" data-dismiss-token>Done</button></div>
|
|
188
|
+
</div>` : "";
|
|
189
|
+
const rows = tokens.length
|
|
190
|
+
? tokens.map((token) => `<div class="token-row"><span><strong>${esc(token.label)}</strong><br><small>created ${esc(compactDate(token.createdAt))}${token.lastUsedAt ? ` · last used ${esc(compactDate(token.lastUsedAt))}` : " · never used"}</small></span><button class="quiet" type="button" data-revoke-token="${esc(token.id)}">Revoke</button></div>`).join("")
|
|
191
|
+
: '<div class="empty">No tokens yet.</div>';
|
|
192
|
+
node.innerHTML = reveal + rows;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async function loadTokens() {
|
|
196
|
+
if (state.session?.access !== "account") { state.tokens = []; return; }
|
|
197
|
+
state.tokens = (await api("/api/tokens").catch(() => ({ tokens: [] }))).tokens || [];
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
async function createToken() {
|
|
201
|
+
const label = (prompt("What is this token for?", "coding agent") || "").trim();
|
|
202
|
+
if (label === "") return;
|
|
203
|
+
try {
|
|
204
|
+
state.newToken = await api("/api/tokens", { method: "POST", body: JSON.stringify({ label }) });
|
|
205
|
+
await loadTokens();
|
|
206
|
+
renderTokens();
|
|
207
|
+
} catch (error) { toast(error.message, true); }
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
async function revokeToken(id) {
|
|
211
|
+
await api(`/api/tokens/${encodeURIComponent(id)}`, { method: "DELETE" });
|
|
212
|
+
state.newToken = null;
|
|
213
|
+
await loadTokens();
|
|
214
|
+
renderTokens();
|
|
215
|
+
toast("Revoked. That agent can no longer act as you.");
|
|
216
|
+
}
|
|
217
|
+
|
|
175
218
|
async function forgetActor(host, actor) {
|
|
176
219
|
await api(`/api/actors/${encodeURIComponent(host)}/${encodeURIComponent(actor)}`, { method:"DELETE" });
|
|
177
220
|
state.actors = (state.actors || []).map((app) => app.host === host ? { ...app, actors: app.actors.filter((a) => a.actor !== actor) } : app).filter((app) => app.actors.length);
|
|
@@ -179,6 +222,17 @@ async function forgetActor(host, actor) {
|
|
|
179
222
|
toast(`Forgot ${actor} on ${host}. tapp will ask again next time.`);
|
|
180
223
|
}
|
|
181
224
|
|
|
225
|
+
// Someone who already owns journeys comes back to check on them, not to start something new —
|
|
226
|
+
// and the prompt screen is the whole page until a run happens. Give them the way in.
|
|
227
|
+
function renderOwnedLink() {
|
|
228
|
+
const slot = $("#owned-link");
|
|
229
|
+
if (!slot) return;
|
|
230
|
+
const journeys = state.journeys?.length || 0;
|
|
231
|
+
const show = state.session?.access === "account" && journeys > 0;
|
|
232
|
+
slot.classList.toggle("hidden", !show);
|
|
233
|
+
if (show) slot.innerHTML = `<button type="button" class="quiet" data-open-owned>You have ${journeys} journey${journeys === 1 ? "" : "s"} — see how they are doing →</button>`;
|
|
234
|
+
}
|
|
235
|
+
|
|
182
236
|
function showPrompt() {
|
|
183
237
|
$("#source-onboarding").classList.remove("hidden");
|
|
184
238
|
$("#product-shell").classList.add("hidden");
|
|
@@ -448,6 +502,7 @@ async function keepJourney(form) {
|
|
|
448
502
|
function renderRuns() {
|
|
449
503
|
renderJourneys();
|
|
450
504
|
renderActors();
|
|
505
|
+
renderTokens();
|
|
451
506
|
const runs = allRuns();
|
|
452
507
|
setCount("#run-count", runs.length);
|
|
453
508
|
$("#runs-list").innerHTML = runs.length ? runs.map((run) => {
|
|
@@ -684,7 +739,8 @@ function renderProject() {
|
|
|
684
739
|
const project = state.project;
|
|
685
740
|
renderRepositoryChrome();
|
|
686
741
|
if (!project?.connected) {
|
|
687
|
-
|
|
742
|
+
renderOwnedLink();
|
|
743
|
+
if ((state.journeys?.length || state.audits.length || state.explores.length) && state.activeView === "runs") { showProduct(); renderRuns(); return; }
|
|
688
744
|
if (state.promptRun) { showProduct(); renderRuns(); renderDeviceChrome(); renderChat(); return; }
|
|
689
745
|
showPrompt();
|
|
690
746
|
renderRuns();
|
|
@@ -727,7 +783,7 @@ async function refresh() {
|
|
|
727
783
|
state.audits = runs.audits || [];
|
|
728
784
|
state.explores = runs.explores || [];
|
|
729
785
|
state.actors = actors.apps || [];
|
|
730
|
-
await loadJourneys();
|
|
786
|
+
await Promise.all([loadJourneys(), loadTokens()]);
|
|
731
787
|
renderProject();
|
|
732
788
|
return;
|
|
733
789
|
}
|
|
@@ -932,6 +988,16 @@ document.addEventListener("click", (event) => {
|
|
|
932
988
|
if (event.target.closest("[data-keep=dismiss]")) { event.preventDefault(); state.pendingKeep = null; renderChat(); }
|
|
933
989
|
const forgetJ = event.target.closest("[data-forget-journey]");
|
|
934
990
|
if (forgetJ) { event.preventDefault(); forgetJourney(forgetJ.dataset.forgetJourney).catch((error) => toast(error.message, true)); }
|
|
991
|
+
if (event.target.closest("[data-open-owned]")) { event.preventDefault(); showProduct(); activateView("runs"); renderRuns(); }
|
|
992
|
+
if (event.target.closest("#create-token")) { event.preventDefault(); createToken(); }
|
|
993
|
+
const revoke = event.target.closest("[data-revoke-token]");
|
|
994
|
+
if (revoke) { event.preventDefault(); revokeToken(revoke.dataset.revokeToken).catch((error) => toast(error.message, true)); }
|
|
995
|
+
if (event.target.closest("[data-dismiss-token]")) { event.preventDefault(); state.newToken = null; renderTokens(); }
|
|
996
|
+
if (event.target.closest("[data-copy-token]")) {
|
|
997
|
+
event.preventDefault();
|
|
998
|
+
const text = $("#token-value")?.textContent || "";
|
|
999
|
+
navigator.clipboard?.writeText(text).then(() => toast("Copied. Paste it where your agent runs."), () => toast("Select the text and copy it.", true));
|
|
1000
|
+
}
|
|
935
1001
|
const forget = event.target.closest("[data-forget-actor]");
|
|
936
1002
|
if (forget) { event.preventDefault(); forgetActor(forget.dataset.forgetHost, forget.dataset.forgetActor).catch((error) => toast(error.message, true)); }
|
|
937
1003
|
});
|
|
@@ -984,6 +1050,10 @@ try {
|
|
|
984
1050
|
await refresh();
|
|
985
1051
|
if (state.project?.connected && !state.project?.state?.inspected) await runOperation("initialize", { write:true });
|
|
986
1052
|
signInOutcome();
|
|
1053
|
+
// A link to /#runs (or a bookmark) opens what you own rather than the empty prompt.
|
|
1054
|
+
if (window.location.hash === "#runs" && (state.journeys?.length || state.audits?.length || state.explores?.length)) {
|
|
1055
|
+
showProduct(); activateView("runs"); renderRuns();
|
|
1056
|
+
}
|
|
987
1057
|
|
|
988
1058
|
const handoff = handoffTarget();
|
|
989
1059
|
if (handoff) {
|
package/browser/index.html
CHANGED
|
@@ -72,6 +72,7 @@
|
|
|
72
72
|
</form>
|
|
73
73
|
<p class="signin-sent hidden" id="signin-sent"></p>
|
|
74
74
|
</section>
|
|
75
|
+
<div class="owned-link hidden" id="owned-link"></div>
|
|
75
76
|
<p class="prompt-note" id="privacy-note-detail">Everything runs on this machine. Exploration, replay and merge decisions are deterministic and need no API key.</p>
|
|
76
77
|
<span class="sr-only" id="privacy-note-title">Your code stays on this machine.</span>
|
|
77
78
|
</section>
|
|
@@ -176,6 +177,13 @@
|
|
|
176
177
|
<div class="section-heading compact"><div><p class="eyebrow">Test accounts</p><h2>What tapp can sign in as <i id="actor-count" class="zero">0</i></h2><p>Kept encrypted. Shown here is only the name and whether a password or a signed-in session is held — never the values. Forget one and tapp will ask again next time.</p></div></div>
|
|
177
178
|
<div id="actors-list"><div class="empty">None yet. Explore a site with a sign-in and tapp will ask.</div></div>
|
|
178
179
|
</section>
|
|
180
|
+
<section class="panel section hidden" id="agent-panel">
|
|
181
|
+
<div class="section-heading compact">
|
|
182
|
+
<div><p class="eyebrow">Your coding agent</p><h2>Let your agent check these journeys <i id="token-count" class="zero">0</i></h2><p>A token lets your coding agent ask “is everything still passing?” and replay a journey — as you, without a browser. It is shown once and can be revoked at any time.</p></div>
|
|
183
|
+
<button class="quiet" id="create-token" type="button">+ New token</button>
|
|
184
|
+
</div>
|
|
185
|
+
<div id="token-list"><div class="empty">No tokens yet.</div></div>
|
|
186
|
+
</section>
|
|
179
187
|
<section class="panel section" id="journeys-panel">
|
|
180
188
|
<div class="section-heading compact"><div><p class="eyebrow">Journeys</p><h2>What this app has proven <i id="journey-count" class="zero">0</i></h2><p id="journeys-note">Each replays exactly as written — no model, no key. Keep one from any run that got somewhere; run it any time to prove it still works.</p></div></div>
|
|
181
189
|
<div id="journeys-list"><div class="empty">No journeys yet.</div></div>
|
package/docs/BROWSER-PRODUCT.md
CHANGED
|
@@ -137,3 +137,30 @@ Endpoints: `POST /api/captures/:id/keep` (`{ name, actor, replace, preview }`
|
|
|
137
137
|
the journey and lists its screens without keeping it), `GET /api/journeys`,
|
|
138
138
|
`DELETE /api/journeys/:slug` (kept journeys only; committed flows are the repository's),
|
|
139
139
|
`POST /api/operations/run-flow` (`{ name }`).
|
|
140
|
+
|
|
141
|
+
## Agent access: the owner's coding agent acting as them
|
|
142
|
+
|
|
143
|
+
"Make sure this always works" needs an answer that does not require a person to open a page. The
|
|
144
|
+
owner creates a **personal access token** in the Studio (Runs → *Your coding agent*): it is shown
|
|
145
|
+
once, stored only as a SHA-256, and revoked by name. The agent sends it as `Authorization: Bearer
|
|
146
|
+
tapp_…` and is that account — same journeys, same test accounts, same evidence, same lane. It is
|
|
147
|
+
deliberately *less* than the person: an agent cannot issue or revoke tokens, so a leaked token
|
|
148
|
+
cannot mint its own successor, and this machine's repositories and release gate stay the
|
|
149
|
+
operator's whoever is asking. CSRF does not apply to a bearer token (a browser never sends one
|
|
150
|
+
ambiently) and is therefore not required on these requests.
|
|
151
|
+
|
|
152
|
+
From the terminal or an MCP client:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
export TAPP_STUDIO=https://app.runtapp.com
|
|
156
|
+
export TAPP_TOKEN=tapp_…
|
|
157
|
+
|
|
158
|
+
tapp report --journeys # every journey and its last check; exit 1 if any is FAILING
|
|
159
|
+
tapp run "coach books a session" # replay one there; exit 0 passed, 1 failed, 2 usage/unreachable
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
`tapp report --journeys` without `$TAPP_STUDIO` lists what is here instead: a repository's
|
|
163
|
+
committed Flows (subfolders and all) or this machine's kept journeys. The MCP tools are the same
|
|
164
|
+
two abilities on the existing tools — `tapp_report { journeys: true }` and
|
|
165
|
+
`tapp_run { journey }` — never new tools (ADR-0007). Both are implemented by
|
|
166
|
+
`mcp-server/src/studio-client.js`.
|
|
@@ -13,12 +13,16 @@
|
|
|
13
13
|
// accounts/<id>.json { id, email, createdAt, lastSeenAt }
|
|
14
14
|
// links/<sha256(token)>.json { email, expiresAt } (removed on use)
|
|
15
15
|
// sessions/<sha256(token)>.json { accountId, createdAt, expiresAt }
|
|
16
|
+
// tokens/<sha256(token)>.json { id, accountId, label, createdAt, lastUsedAt }
|
|
16
17
|
// actors/<id>/ that account's ActorStore root
|
|
17
18
|
import crypto from "node:crypto";
|
|
18
19
|
import fs from "node:fs";
|
|
19
20
|
import os from "node:os";
|
|
20
21
|
import path from "node:path";
|
|
21
22
|
|
|
23
|
+
// A personal access token lets the owner's coding agent act as them without a browser. It is
|
|
24
|
+
// shown once, stored only as a hash, and never expires on its own — it is revoked by name.
|
|
25
|
+
export const TOKEN_PREFIX = "tapp_";
|
|
22
26
|
export const LINK_TTL_MS = 15 * 60 * 1000;
|
|
23
27
|
export const SESSION_TTL_MS = 90 * 24 * 60 * 60 * 1000;
|
|
24
28
|
// One address may ask for this many links in a ten-minute window; more is someone else's mailbox
|
|
@@ -113,6 +117,60 @@ export class AccountStore {
|
|
|
113
117
|
try { fs.rmSync(this.#file("sessions", sha(value)), { force: true }); } catch { /* already gone */ }
|
|
114
118
|
}
|
|
115
119
|
|
|
120
|
+
/**
|
|
121
|
+
* Issue a personal access token. The returned `token` is the only time it exists in the clear;
|
|
122
|
+
* what lands on disk is its hash, so a copy of this directory cannot act as anyone.
|
|
123
|
+
*/
|
|
124
|
+
issueToken(accountId, label = "coding agent") {
|
|
125
|
+
if (!/^[a-f0-9]{24}$/.test(String(accountId || ""))) throw new Error("Not an account id");
|
|
126
|
+
const name = String(label || "coding agent").trim().slice(0, 60) || "coding agent";
|
|
127
|
+
const value = `${TOKEN_PREFIX}${token()}`;
|
|
128
|
+
const id = crypto.randomBytes(6).toString("hex");
|
|
129
|
+
writeJson(this.#file("tokens", sha(value)), { id, accountId, label: name, createdAt: new Date(this.now()).toISOString(), lastUsedAt: null });
|
|
130
|
+
return { token: value, id, label: name };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/** The account behind a personal access token, or null. */
|
|
134
|
+
tokenAccount(value) {
|
|
135
|
+
const raw = String(value || "");
|
|
136
|
+
if (!raw.startsWith(TOKEN_PREFIX) || raw.length < TOKEN_PREFIX.length + 20) return null;
|
|
137
|
+
const file = this.#file("tokens", sha(raw));
|
|
138
|
+
const record = readJson(file);
|
|
139
|
+
if (!record) return null;
|
|
140
|
+
const account = readJson(this.#file("accounts", record.accountId));
|
|
141
|
+
if (!account) return null;
|
|
142
|
+
// Coarse on purpose: a day, so "is this token still in use?" is answerable without a log of
|
|
143
|
+
// every request an agent makes.
|
|
144
|
+
const day = new Date(this.now()).toISOString().slice(0, 10);
|
|
145
|
+
if ((record.lastUsedAt || "").slice(0, 10) !== day) { record.lastUsedAt = new Date(this.now()).toISOString(); writeJson(file, record); }
|
|
146
|
+
return account;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/** Tokens this account holds — labels and dates, never a value. */
|
|
150
|
+
listTokens(accountId) {
|
|
151
|
+
let names = [];
|
|
152
|
+
try { names = fs.readdirSync(path.join(this.root, "tokens")); } catch { return []; }
|
|
153
|
+
const out = [];
|
|
154
|
+
for (const name of names) {
|
|
155
|
+
const record = readJson(path.join(this.root, "tokens", name));
|
|
156
|
+
if (record?.accountId !== accountId) continue;
|
|
157
|
+
out.push({ id: record.id, label: record.label, createdAt: record.createdAt, lastUsedAt: record.lastUsedAt || null });
|
|
158
|
+
}
|
|
159
|
+
return out.sort((a, b) => String(a.createdAt).localeCompare(String(b.createdAt)));
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
revokeToken(accountId, id) {
|
|
163
|
+
let names = [];
|
|
164
|
+
try { names = fs.readdirSync(path.join(this.root, "tokens")); } catch { return false; }
|
|
165
|
+
for (const name of names) {
|
|
166
|
+
const file = path.join(this.root, "tokens", name);
|
|
167
|
+
const record = readJson(file);
|
|
168
|
+
if (record?.accountId !== accountId || record?.id !== String(id)) continue;
|
|
169
|
+
try { fs.rmSync(file, { force: true }); return true; } catch { return false; }
|
|
170
|
+
}
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
|
|
116
174
|
/** Where this account's encrypted test accounts live. */
|
|
117
175
|
actorRoot(accountId) {
|
|
118
176
|
if (!/^[a-f0-9]{24}$/.test(String(accountId || ""))) throw new Error("Not an account id");
|
|
@@ -154,7 +154,10 @@ function anonymousAllows(method, pathname) {
|
|
|
154
154
|
function accountAllows(method, pathname) {
|
|
155
155
|
if (anonymousAllows(method, pathname)) return true;
|
|
156
156
|
if (method === "POST" && (pathname === "/api/auth/signout" || /^\/api\/jobs\/[a-f0-9]{20}\/input$/.test(pathname))) return true;
|
|
157
|
-
if (method === "GET" && (pathname === "/api/actors" || pathname === "/api/journeys")) return true;
|
|
157
|
+
if (method === "GET" && (pathname === "/api/actors" || pathname === "/api/journeys" || pathname === "/api/tokens")) return true;
|
|
158
|
+
// Personal access tokens: the owner's coding agent acting as them (ADR-0009 slice 4).
|
|
159
|
+
if (method === "POST" && pathname === "/api/tokens") return true;
|
|
160
|
+
if (method === "DELETE" && /^\/api\/tokens\/[a-f0-9]{12}$/.test(pathname)) return true;
|
|
158
161
|
if (method === "DELETE" && /^\/api\/actors\/[A-Za-z0-9.:-]{1,253}\/[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(pathname)) return true;
|
|
159
162
|
// Journeys: keep a proven run, replay it, forget it (ADR-0009 slice 3).
|
|
160
163
|
if (method === "POST" && (/^\/api\/captures\/[A-Za-z0-9._-]{1,128}\/keep$/.test(pathname) || pathname === "/api/operations/run-flow")) return true;
|
|
@@ -259,6 +262,16 @@ function markPromptStarted(structured) {
|
|
|
259
262
|
} catch { /* listing is a convenience; the capture is the evidence */ }
|
|
260
263
|
}
|
|
261
264
|
|
|
265
|
+
// How a journey gets inside. A journey either types the credentials (it has a `login` step, so it
|
|
266
|
+
// was kept from a run that met the sign-in form and must start signed OUT) or it resumes the
|
|
267
|
+
// actor's saved session (no `login` step: the run it came from already began inside). Doing both
|
|
268
|
+
// breaks the first kind — the browser starts inside and the journey's own first step, waiting for
|
|
269
|
+
// the sign-in screen, never matches.
|
|
270
|
+
export function journeySignInPlan(flow = {}) {
|
|
271
|
+
const signsIn = (flow.steps || []).some((step) => step && typeof step === "object" && "login" in step);
|
|
272
|
+
return { signsIn, usesSession: !!flow.actor && !signsIn };
|
|
273
|
+
}
|
|
274
|
+
|
|
262
275
|
// Replay one web journey and record how it went. Shared by the Studio's Run button and the
|
|
263
276
|
// daily check, so both leave the same status and the same evidence behind.
|
|
264
277
|
async function replayJourney({ store, slug, flow, actorRoot = "", ownerKey = null, progress = () => {} }) {
|
|
@@ -266,13 +279,24 @@ async function replayJourney({ store, slug, flow, actorRoot = "", ownerKey = nul
|
|
|
266
279
|
// values come from the encrypted actor store at replay and never from the file.
|
|
267
280
|
const variables = {};
|
|
268
281
|
let storageStatePath = "";
|
|
269
|
-
|
|
282
|
+
// A journey signs in one of two ways, and they are mutually exclusive:
|
|
283
|
+
// it has a `login` step → it was kept from a run that met the sign-in form, so it must START
|
|
284
|
+
// SIGNED OUT and type the credentials. Handing it a saved session
|
|
285
|
+
// would drop it inside the app, where its own first step ("wait for
|
|
286
|
+
// the sign-in screen") can never match.
|
|
287
|
+
// it has no `login` step → it was kept from a run that already began inside, so the saved
|
|
288
|
+
// session is the only way back in.
|
|
289
|
+
const { signsIn, usesSession } = journeySignInPlan(flow);
|
|
290
|
+
if (flow.url && (flow.actor || signsIn)) {
|
|
270
291
|
const actors = new ActorStore(actorRoot ? { root: actorRoot } : {});
|
|
271
292
|
const record = actors.read(flow.url, flow.actor || "default");
|
|
272
293
|
if (record?.credentials?.email) variables.TEST_EMAIL = record.credentials.email;
|
|
273
294
|
if (record?.credentials?.password) variables.TEST_PASSWORD = record.credentials.password;
|
|
274
|
-
|
|
275
|
-
|
|
295
|
+
if (usesSession) {
|
|
296
|
+
storageStatePath = actors.sessionFile(flow.url, flow.actor) || "";
|
|
297
|
+
// Say why plainly, rather than letting every step time out looking for a signed-in screen.
|
|
298
|
+
if (!storageStatePath) throw new Error(`This journey starts already signed in, but tapp no longer has a session for '${flow.actor}' on this site. Explore it again and sign in, and the journey will work from the new session.`);
|
|
299
|
+
}
|
|
276
300
|
}
|
|
277
301
|
const captureId = `flow-web-${Date.now().toString(36)}-${crypto.randomBytes(4).toString("hex")}`;
|
|
278
302
|
const evidenceDir = path.join(captureRoot(), captureId);
|
|
@@ -701,7 +725,21 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
701
725
|
let visitorId = null;
|
|
702
726
|
let anonymous = false;
|
|
703
727
|
// A signed-in account sits between the two: more than a visitor, less than the operator.
|
|
704
|
-
|
|
728
|
+
// It arrives either as a browser session cookie or as a personal access token on the
|
|
729
|
+
// Authorization header — the owner's coding agent acting as them.
|
|
730
|
+
let account = null;
|
|
731
|
+
let viaToken = false;
|
|
732
|
+
if (publicAccess && !authenticated) {
|
|
733
|
+
account = accounts.sessionAccount(cookies(request)[ACCOUNT_COOKIE] || "");
|
|
734
|
+
if (!account) {
|
|
735
|
+
const bearer = /^Bearer\s+(\S+)$/i.exec(String(request.headers.authorization || ""))?.[1] || "";
|
|
736
|
+
if (bearer) { account = accounts.tokenAccount(bearer); viaToken = !!account; }
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
// CSRF defends against a browser being made to act with its ambient cookie. A bearer token
|
|
740
|
+
// is never sent ambiently, so the check does not apply to it — and must not, or no agent
|
|
741
|
+
// could ever post anything.
|
|
742
|
+
const guardMutation = (req) => { if (viaToken) return; requireMutationAuth(req, hosted ? publicOrigins : origin, csrfToken); };
|
|
705
743
|
if (account && !accountAllows(request.method, url.pathname)) {
|
|
706
744
|
json(response, 401, { error: "That part of the Studio runs on your own machine: npx -y @aarwitz/tapp@latest app" });
|
|
707
745
|
return;
|
|
@@ -807,7 +845,7 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
807
845
|
// The response to the request is the same whether or not the address was ever seen, so
|
|
808
846
|
// this cannot be used to find out who has an account.
|
|
809
847
|
if (publicAccess && request.method === "POST" && url.pathname === "/api/auth/link") {
|
|
810
|
-
|
|
848
|
+
guardMutation(request);
|
|
811
849
|
const body = await readJsonBody(request);
|
|
812
850
|
let link;
|
|
813
851
|
try { link = accounts.requestLink(body.email); }
|
|
@@ -848,7 +886,7 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
848
886
|
return;
|
|
849
887
|
}
|
|
850
888
|
if (account && request.method === "POST" && url.pathname === "/api/auth/signout") {
|
|
851
|
-
|
|
889
|
+
guardMutation(request);
|
|
852
890
|
accounts.signOut(cookies(request)[ACCOUNT_COOKIE] || "");
|
|
853
891
|
response.writeHead(200, { "content-type": "application/json; charset=utf-8", "set-cookie": `${ACCOUNT_COOKIE}=; HttpOnly; SameSite=Lax;${secureCookies ? " Secure;" : ""} Path=/; Max-Age=0` });
|
|
854
892
|
response.end(JSON.stringify({ ok: true }));
|
|
@@ -867,7 +905,7 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
867
905
|
}
|
|
868
906
|
const actorForgetMatch = !anonymous && request.method === "DELETE" ? url.pathname.match(/^\/api\/actors\/([A-Za-z0-9.:-]{1,253})\/([A-Za-z][A-Za-z0-9_-]{0,63})$/) : null;
|
|
869
907
|
if (actorForgetMatch) {
|
|
870
|
-
|
|
908
|
+
guardMutation(request);
|
|
871
909
|
const store = new ActorStore(actorRootFor() ? { root: actorRootFor() } : {});
|
|
872
910
|
store.forget(`https://${actorForgetMatch[1]}/`, actorForgetMatch[2]);
|
|
873
911
|
json(response, 200, { ok: true });
|
|
@@ -882,7 +920,7 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
882
920
|
};
|
|
883
921
|
const keepMatch = !anonymous && request.method === "POST" ? url.pathname.match(/^\/api\/captures\/([A-Za-z0-9._-]{1,128})\/keep$/) : null;
|
|
884
922
|
if (keepMatch) {
|
|
885
|
-
|
|
923
|
+
guardMutation(request);
|
|
886
924
|
if (!visibleToOwner(keepMatch[1], evidenceOwner)) { response.writeHead(404); response.end("Not found"); return; }
|
|
887
925
|
const captureDir = capturePath(keepMatch[1], ".");
|
|
888
926
|
if (!captureDir || !fs.existsSync(captureDir)) { json(response, 404, { error: "No such capture" }); return; }
|
|
@@ -916,19 +954,42 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
916
954
|
}
|
|
917
955
|
const forgetJourneyMatch = !anonymous && request.method === "DELETE" ? url.pathname.match(/^\/api\/journeys\/([a-z0-9-]{1,60})$/) : null;
|
|
918
956
|
if (forgetJourneyMatch) {
|
|
919
|
-
|
|
957
|
+
guardMutation(request);
|
|
920
958
|
// Committed flows are the repository's; only kept journeys are forgotten from here.
|
|
921
959
|
if (!account && registry.currentRoot()) { json(response, 409, { error: "That journey is committed in the repository; remove the file there." }); return; }
|
|
922
960
|
journeyStore().forget(forgetJourneyMatch[1]);
|
|
923
961
|
json(response, 200, { ok: true });
|
|
924
962
|
return;
|
|
925
963
|
}
|
|
964
|
+
// Agent access. A token is issued only to a person at the keyboard: an agent holding a
|
|
965
|
+
// token cannot mint itself another one, so a leaked token cannot outlive its revocation.
|
|
966
|
+
if (account && url.pathname === "/api/tokens" && request.method === "GET") {
|
|
967
|
+
json(response, 200, { tokens: accounts.listTokens(account.id) });
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
if (account && url.pathname === "/api/tokens" && request.method === "POST") {
|
|
971
|
+
guardMutation(request);
|
|
972
|
+
if (viaToken) { json(response, 403, { error: "An agent cannot issue tokens. Create it in the Studio, signed in." }); return; }
|
|
973
|
+
const body = await readJsonBody(request);
|
|
974
|
+
const issued = accounts.issueToken(account.id, String(body.label || "coding agent"));
|
|
975
|
+
logUsage("token.issued", { account: account.id.slice(0, 8) });
|
|
976
|
+
// The only time the value leaves this process.
|
|
977
|
+
json(response, 200, issued);
|
|
978
|
+
return;
|
|
979
|
+
}
|
|
980
|
+
const revokeTokenMatch = account && request.method === "DELETE" ? url.pathname.match(/^\/api\/tokens\/([a-f0-9]{12})$/) : null;
|
|
981
|
+
if (revokeTokenMatch) {
|
|
982
|
+
guardMutation(request);
|
|
983
|
+
if (viaToken) { json(response, 403, { error: "An agent cannot revoke tokens." }); return; }
|
|
984
|
+
json(response, 200, { ok: accounts.revokeToken(account.id, revokeTokenMatch[1]) });
|
|
985
|
+
return;
|
|
986
|
+
}
|
|
926
987
|
if (request.method === "GET" && url.pathname === "/api/session") {
|
|
927
988
|
if (account) {
|
|
928
989
|
json(response, 200, {
|
|
929
990
|
csrfToken, mode: "public", product: "Tapp", root: null, repository: null, repositories: [],
|
|
930
991
|
contract: customerProductContract, supportedPlatforms: ["web"], runners: [],
|
|
931
|
-
access: "account", email: account.email, signInProvider,
|
|
992
|
+
access: "account", email: account.email, signInProvider, viaToken,
|
|
932
993
|
accepts: ["url"],
|
|
933
994
|
selfHostOnly: ["path", "github", "bundle", "app", "apk"],
|
|
934
995
|
});
|
|
@@ -988,7 +1049,7 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
988
1049
|
const jobInputMatch = url.pathname.match(/^\/api\/jobs\/([a-f0-9]{20})\/input$/);
|
|
989
1050
|
if (request.method === "POST" && jobInputMatch) {
|
|
990
1051
|
if (anonymous) { response.writeHead(401); response.end("Sign in to answer a run"); return; }
|
|
991
|
-
|
|
1052
|
+
guardMutation(request);
|
|
992
1053
|
const job = jobs.get(jobInputMatch[1]);
|
|
993
1054
|
if (job && !jobVisible(job)) { response.writeHead(404); response.end("Not found"); return; }
|
|
994
1055
|
if (!job || !job.input || !job.inputResponsePath) { json(response, 409, { error: "This run is not waiting for anything" }); return; }
|
|
@@ -1035,7 +1096,7 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
1035
1096
|
}
|
|
1036
1097
|
|
|
1037
1098
|
if (request.method === "POST" && url.pathname === "/api/repositories/select") {
|
|
1038
|
-
|
|
1099
|
+
guardMutation(request);
|
|
1039
1100
|
const busy = lanes.running(OPERATOR_LANE);
|
|
1040
1101
|
if (busy) throw Object.assign(new Error(`Operation '${busy.operation}' is still running`), { statusCode: 409 });
|
|
1041
1102
|
if (liveSession?.active) throw Object.assign(new Error("End the active live session before changing repositories"), { statusCode:409 });
|
|
@@ -1046,7 +1107,7 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
1046
1107
|
}
|
|
1047
1108
|
|
|
1048
1109
|
if (request.method !== "POST" || !url.pathname.startsWith("/api/operations/")) { response.writeHead(404); response.end("Not found"); return; }
|
|
1049
|
-
|
|
1110
|
+
guardMutation(request);
|
|
1050
1111
|
const body = await readJsonBody(request);
|
|
1051
1112
|
const operation = url.pathname.slice("/api/operations/".length);
|
|
1052
1113
|
// "What should tapp test?" — a repository on this machine or on GitHub becomes the current
|
package/mcp-server/src/index.js
CHANGED
|
@@ -2797,6 +2797,9 @@ export const TOOLS = [
|
|
|
2797
2797
|
properties: {
|
|
2798
2798
|
...AUTH,
|
|
2799
2799
|
flowPath: { type: "string", description: "Repo-relative Flow (.yml/.json), e.g. .tapp/flows/login.yml" },
|
|
2800
|
+
journey: { type: "string", description: "Name of a journey on a hosted Studio to replay there (with `studio` + `token`, or $TAPP_STUDIO/$TAPP_TOKEN)" },
|
|
2801
|
+
studio: { type: "string", description: "Hosted Studio origin for `journey`, e.g. https://app.runtapp.com (default $TAPP_STUDIO)" },
|
|
2802
|
+
token: { type: "string", description: "Personal access token for `journey` (default $TAPP_TOKEN)" },
|
|
2800
2803
|
flow: { type: "object", description: "Inline Flow instead of flowPath" },
|
|
2801
2804
|
taskPath: { type: "string", description: "Repo-relative .tapp/tasks/*.yml Task" },
|
|
2802
2805
|
inputs: { type: "object", additionalProperties: { type: "string" }, description: "Task inputs; secrets as $ENV placeholders, never plaintext" },
|
|
@@ -2960,7 +2963,9 @@ export const TOOLS = [
|
|
|
2960
2963
|
title: "Evidence: recent runs, or one run's summary",
|
|
2961
2964
|
description:
|
|
2962
2965
|
"Without captureId: list recent capture runs for THIS project (other projects' captures are counted but hidden unless allProjects). " +
|
|
2963
|
-
"With captureId: that run's summary metadata. Cite only the capture a command just returned as evidence."
|
|
2966
|
+
"With captureId: that run's summary metadata. Cite only the capture a command just returned as evidence. " +
|
|
2967
|
+
"With journeys:true: the journeys you own and how each one's last check went — this repository's committed Flows, or, with " +
|
|
2968
|
+
"`studio` + `token` (or $TAPP_STUDIO/$TAPP_TOKEN), the ones on your hosted Studio. That is how to answer \"is everything still working?\".",
|
|
2964
2969
|
inputSchema: {
|
|
2965
2970
|
type: "object",
|
|
2966
2971
|
properties: {
|
|
@@ -2968,6 +2973,9 @@ export const TOOLS = [
|
|
|
2968
2973
|
runPath: { type: "string", description: "Absolute capture path override (must stay under captures/)" },
|
|
2969
2974
|
limit: { type: "integer", minimum: 1, maximum: 100, default: 10 },
|
|
2970
2975
|
allProjects: { type: "boolean", default: false, description: "Include other projects' and pre-provenance captures" },
|
|
2976
|
+
journeys: { type: "boolean", default: false, description: "List journeys and their last result instead of captures" },
|
|
2977
|
+
studio: { type: "string", description: "journeys: a hosted Studio origin, e.g. https://app.runtapp.com (default $TAPP_STUDIO)" },
|
|
2978
|
+
token: { type: "string", description: "journeys: personal access token from the Studio's “Your coding agent” card (default $TAPP_TOKEN)" },
|
|
2971
2979
|
},
|
|
2972
2980
|
},
|
|
2973
2981
|
},
|
|
@@ -3383,6 +3391,59 @@ async function handleTool(name, args = {}) {
|
|
|
3383
3391
|
return richResult(L.join("\n"), parsed);
|
|
3384
3392
|
}
|
|
3385
3393
|
|
|
3394
|
+
// The journeys this agent's owner owns, and how each one's last check went. Locally that is
|
|
3395
|
+
// the repository's committed Flows; with a hosted Studio and a token it is the account's.
|
|
3396
|
+
if (name === "tapp_journeys") {
|
|
3397
|
+
const { studioConfig, listStudioJourneys, formatJourneyStatus } = await import("./studio-client.js");
|
|
3398
|
+
let config = null;
|
|
3399
|
+
try { config = studioConfig({ studio: args.studio, token: args.token }); }
|
|
3400
|
+
catch (error) { return errorResult(error.message); }
|
|
3401
|
+
let journeys = [];
|
|
3402
|
+
let where = "";
|
|
3403
|
+
if (config) {
|
|
3404
|
+
try { journeys = await listStudioJourneys(config); } catch (error) { return errorResult(error.message); }
|
|
3405
|
+
where = config.origin;
|
|
3406
|
+
} else {
|
|
3407
|
+
const { JourneyStore } = await import("./journeys.js");
|
|
3408
|
+
const root = workspaceRoot;
|
|
3409
|
+
if (fs.existsSync(path.join(root, ".tapp", "flows"))) {
|
|
3410
|
+
const { readProductProject } = await import("./product-operations.js");
|
|
3411
|
+
const store = JourneyStore.forRepository(root);
|
|
3412
|
+
journeys = (readProductProject({ projectDir: root }).flows || []).map((flow) => {
|
|
3413
|
+
const slug = flow.relativePath.replace(/^\.tapp\/flows\//, "").replace(/\.(?:ya?ml|json)$/i, "");
|
|
3414
|
+
return { name: flow.name, slug, platform: flow.platform, steps: flow.steps, source: "repo", status: store.status(slug) };
|
|
3415
|
+
});
|
|
3416
|
+
where = ".tapp/flows";
|
|
3417
|
+
} else {
|
|
3418
|
+
journeys = JourneyStore.forMachine().list();
|
|
3419
|
+
where = "this machine";
|
|
3420
|
+
}
|
|
3421
|
+
}
|
|
3422
|
+
const failing = journeys.filter((j) => j.status && !j.status.passed);
|
|
3423
|
+
const header = journeys.length
|
|
3424
|
+
? `${journeys.length} journey(s) · ${where}${failing.length ? ` — ${failing.length} FAILING` : ""}`
|
|
3425
|
+
: `No journeys yet (${where}). Explore an app; when a run gets somewhere, tapp offers to keep it.`;
|
|
3426
|
+
return richResult([header, ...journeys.map((j) => ` ${formatJourneyStatus(j)}`)].join("\n"), { where, journeys, failing: failing.length });
|
|
3427
|
+
}
|
|
3428
|
+
|
|
3429
|
+
// Replay one journey on a hosted Studio, as the owner, and report the verdict.
|
|
3430
|
+
if (name === "tapp_journey_run") {
|
|
3431
|
+
const { studioConfig, runStudioJourney } = await import("./studio-client.js");
|
|
3432
|
+
let config = null;
|
|
3433
|
+
try { config = studioConfig({ studio: args.studio, token: args.token }); }
|
|
3434
|
+
catch (error) { return errorResult(error.message); }
|
|
3435
|
+
if (!config) return errorResult("`journey` replays on a hosted Studio: pass `studio` + `token` (or set $TAPP_STUDIO/$TAPP_TOKEN). To replay a committed Flow here, use flowPath.");
|
|
3436
|
+
const lines = [];
|
|
3437
|
+
let result;
|
|
3438
|
+
try { result = await runStudioJourney(config, String(args.journey).replace(/\.ya?ml$/i, ""), { onProgress: (line) => lines.push(line) }); }
|
|
3439
|
+
catch (error) { return errorResult(error.message); }
|
|
3440
|
+
if (result.kind === "self-host") return richResult(`${result.message}`, result);
|
|
3441
|
+
const headline = result.passed
|
|
3442
|
+
? `✓ ${result.name} — ${result.executed}/${result.total} steps on ${config.origin}`
|
|
3443
|
+
: `✗ ${result.name} — ${result.executed}/${result.total} steps, ${result.failed} failed, on ${config.origin}`;
|
|
3444
|
+
return richResult([headline, ...lines.map((line) => ` ${line}`)].join("\n"), result);
|
|
3445
|
+
}
|
|
3446
|
+
|
|
3386
3447
|
if (name === "tapp_list_captures") {
|
|
3387
3448
|
const limit = asInteger(args.limit, 10);
|
|
3388
3449
|
if (limit < 1 || limit > 100) {
|
|
@@ -4608,6 +4669,7 @@ export async function routePublicTool(name, args = {}) {
|
|
|
4608
4669
|
return handleTool(tree === true ? "tapp_ui_tree" : "tapp_screenshot", rest);
|
|
4609
4670
|
}
|
|
4610
4671
|
case "tapp_run": {
|
|
4672
|
+
if (isNonEmptyString(rest.journey)) return handleTool("tapp_journey_run", rest);
|
|
4611
4673
|
if (rest.flow || isNonEmptyString(rest.flowPath)) return handleTool("tapp_flow_run", rest);
|
|
4612
4674
|
if (rest.scenario || isNonEmptyString(rest.scenarioPath)) return handleTool("tapp_scenario_run", rest);
|
|
4613
4675
|
if (isNonEmptyString(rest.contractPath)) return handleTool("tapp_release_contract", { ...rest, operation: "run" });
|
|
@@ -4632,6 +4694,7 @@ export async function routePublicTool(name, args = {}) {
|
|
|
4632
4694
|
case "tapp_ci":
|
|
4633
4695
|
return handleTool("tapp_ci_setup", { ...rest, operation: action || rest.operation || "inspect" });
|
|
4634
4696
|
case "tapp_report":
|
|
4697
|
+
if (rest.journeys === true) return handleTool("tapp_journeys", rest);
|
|
4635
4698
|
if (isNonEmptyString(rest.captureId) || isNonEmptyString(rest.runPath)) return handleTool("tapp_capture_summary", { runId: rest.captureId, runPath: rest.runPath });
|
|
4636
4699
|
return handleTool("tapp_list_captures", rest);
|
|
4637
4700
|
case "tapp_session": {
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
// Talking to a hosted Studio as the owner's coding agent.
|
|
2
|
+
//
|
|
3
|
+
// The agent holds a personal access token (created in the Studio, shown once) and sends it as a
|
|
4
|
+
// bearer token. That is the whole protocol: list the journeys with their last result, and run
|
|
5
|
+
// one. It exists so "make sure this always works" has an answer that does not require a person
|
|
6
|
+
// to open a page — the agent asks, and acts on what it is told.
|
|
7
|
+
//
|
|
8
|
+
// Configuration is two values, from flags or the environment:
|
|
9
|
+
// TAPP_STUDIO https://app.runtapp.com
|
|
10
|
+
// TAPP_TOKEN tapp_…
|
|
11
|
+
const POLL_MS = 1500;
|
|
12
|
+
const DEFAULT_TIMEOUT_MS = 10 * 60 * 1000;
|
|
13
|
+
|
|
14
|
+
export function studioConfig({ studio = "", token = "" } = {}, env = process.env) {
|
|
15
|
+
const origin = String(studio || env.TAPP_STUDIO || "").trim().replace(/\/$/, "");
|
|
16
|
+
const value = String(token || env.TAPP_TOKEN || "").trim();
|
|
17
|
+
if (!origin) return null;
|
|
18
|
+
if (!/^https?:\/\/[^\s/]+$/.test(origin)) throw new Error(`'${origin}' is not a Studio URL (expected https://host)`);
|
|
19
|
+
if (!value) throw new Error("A Studio needs a token: create one in the Studio under “Your coding agent”, then set TAPP_TOKEN (or pass --token).");
|
|
20
|
+
if (!value.startsWith("tapp_")) throw new Error("That does not look like a tapp token (they start with tapp_).");
|
|
21
|
+
return { origin, token: value };
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async function call({ origin, token }, path, { method = "GET", body } = {}) {
|
|
25
|
+
let response;
|
|
26
|
+
try {
|
|
27
|
+
response = await fetch(`${origin}${path}`, {
|
|
28
|
+
method,
|
|
29
|
+
headers: { authorization: `Bearer ${token}`, ...(body !== undefined ? { "content-type": "application/json" } : {}) },
|
|
30
|
+
...(body !== undefined ? { body: JSON.stringify(body) } : {}),
|
|
31
|
+
});
|
|
32
|
+
} catch (error) {
|
|
33
|
+
throw new Error(`Could not reach the Studio at ${origin}: ${error.message}`);
|
|
34
|
+
}
|
|
35
|
+
const text = await response.text();
|
|
36
|
+
let data = {};
|
|
37
|
+
try { data = text ? JSON.parse(text) : {}; } catch { /* a proxy's error page */ }
|
|
38
|
+
if (response.status === 401) throw new Error("The Studio refused that token. It may have been revoked; create a new one under “Your coding agent”.");
|
|
39
|
+
if (!response.ok) throw new Error(data.error || `The Studio answered ${response.status}`);
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** Every journey this account owns, with how its last check went. */
|
|
44
|
+
export async function listStudioJourneys(config) {
|
|
45
|
+
const { journeys = [] } = await call(config, "/api/journeys");
|
|
46
|
+
return journeys;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Replay one journey and wait for the verdict. */
|
|
50
|
+
export async function runStudioJourney(config, name, { onProgress = () => {}, timeoutMs = DEFAULT_TIMEOUT_MS, sleep = (ms) => new Promise((r) => setTimeout(r, ms)) } = {}) {
|
|
51
|
+
const started = await call(config, "/api/operations/run-flow", { method: "POST", body: { name } });
|
|
52
|
+
// An iOS or Android journey needs a device the Studio does not have; it says so instead of
|
|
53
|
+
// pretending to run, and that answer is the result.
|
|
54
|
+
if (started.kind === "self-host") return { kind: "self-host", message: started.message, command: started.command };
|
|
55
|
+
const jobId = started.job?.id;
|
|
56
|
+
if (!jobId) throw new Error("The Studio did not start the journey");
|
|
57
|
+
const deadline = Date.now() + timeoutMs;
|
|
58
|
+
let seen = 0;
|
|
59
|
+
for (;;) {
|
|
60
|
+
const job = await call(config, `/api/jobs/${jobId}`);
|
|
61
|
+
for (const entry of (job.progress || []).slice(seen)) onProgress(entry.text || "");
|
|
62
|
+
seen = (job.progress || []).length;
|
|
63
|
+
if (job.status !== "running") {
|
|
64
|
+
if (job.error) throw new Error(job.error);
|
|
65
|
+
return job.result || { kind: "journey", name, passed: false };
|
|
66
|
+
}
|
|
67
|
+
if (Date.now() > deadline) throw new Error(`The journey was still running after ${Math.round(timeoutMs / 1000)}s`);
|
|
68
|
+
await sleep(POLL_MS);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** One line per journey, for a terminal or an agent's transcript. */
|
|
73
|
+
export function formatJourneyStatus(journey) {
|
|
74
|
+
const status = journey.status;
|
|
75
|
+
const state = !status ? "never run" : status.passed ? "passing" : "FAILING";
|
|
76
|
+
const when = status?.at ? ` · ${new Date(status.at).toISOString().replace("T", " ").slice(0, 16)}` : "";
|
|
77
|
+
return `${state === "FAILING" ? "✗" : state === "passing" ? "✓" : "·"} ${journey.name} — ${journey.steps || 0} steps · ${state}${when}`;
|
|
78
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aarwitz/tapp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.25.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",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"mobile"
|
|
97
97
|
],
|
|
98
98
|
"scripts": {
|
|
99
|
-
"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/web-explorer.test.js tests/web-session.test.js tests/web-link-audit.test.js tests/web-audit.test.js tests/capture-provenance.test.js tests/capture-frames.test.js tests/actor-store.test.js tests/account-store.test.js tests/access-jwt.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/scenario-runtime.test.js tests/android-driver.test.js tests/android-explorer.test.js tests/android-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-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/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",
|
|
99
|
+
"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/web-explorer.test.js tests/web-session.test.js tests/web-link-audit.test.js tests/web-audit.test.js tests/capture-provenance.test.js tests/capture-frames.test.js tests/actor-store.test.js tests/account-store.test.js tests/access-jwt.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/scenario-runtime.test.js tests/android-driver.test.js tests/android-explorer.test.js tests/android-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-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/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",
|
|
100
100
|
"test:browser-journey": "node --test tests/browser-journey.test.js",
|
|
101
101
|
"test:browser-native": "TAPP_RUN_NATIVE_BROWSER=1 node --test tests/browser-native-journey.test.js"
|
|
102
102
|
}
|