@aarwitz/tapp 0.23.1 → 0.24.1
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/browser/app.css +9 -0
- package/browser/app.js +87 -13
- package/browser/index.html +2 -2
- package/browser/view-model.js +5 -2
- package/docs/BROWSER-PRODUCT.md +23 -0
- package/mcp-server/src/browser-product.js +153 -16
- package/mcp-server/src/journeys.js +189 -0
- package/mcp-server/src/web-explorer.js +3 -1
- package/mcp-server/src/web-flow.js +3 -1
- package/package.json +2 -2
- package/scripts/flow_lib.py +3 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tapp",
|
|
3
3
|
"description": "Give Claude hands and eyes on iOS, Android, and web apps, with exploration, replayable flows, evidence, and deterministic CI gates.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.24.1",
|
|
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.24.1",
|
|
28
28
|
"mcp"
|
|
29
29
|
],
|
|
30
30
|
"cwd": "${CLAUDE_PROJECT_DIR}"
|
package/browser/app.css
CHANGED
|
@@ -573,3 +573,12 @@ dialog::backdrop { background:rgba(0,0,0,.6); }
|
|
|
573
573
|
.actor-row:last-child { border-bottom:0; }
|
|
574
574
|
.actor-row small { color:var(--muted); }
|
|
575
575
|
.actor-app { padding:8px 10px 2px; font-weight:600; font-size:12px; color:var(--muted); border-top:1px solid var(--tapp-border); }
|
|
576
|
+
|
|
577
|
+
/* Journeys with status (ADR-0009 slice 3). */
|
|
578
|
+
.journey-row .journey-name small { color:var(--muted); font-size:11px; }
|
|
579
|
+
.journey-status { display:inline-block; padding:1px 7px; border-radius:999px; font-size:10px; font-weight:600; letter-spacing:.02em; }
|
|
580
|
+
.journey-status.passing { background:rgba(46,160,67,.18); color:#4ade80; }
|
|
581
|
+
.journey-status.failing { background:rgba(220,38,38,.18); color:#f87171; }
|
|
582
|
+
.journey-status.never { background:var(--control); color:var(--muted); }
|
|
583
|
+
.journey-actions { display:flex; gap:6px; }
|
|
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); }
|
package/browser/app.js
CHANGED
|
@@ -155,6 +155,7 @@ function applyAccessMode() {
|
|
|
155
155
|
? "Websites are explored in the cloud. Test accounts you give tapp are kept encrypted, used only to sign in, and never shown again. iOS, Android and folders on your own machine need tapp there: npx -y @aarwitz/tapp@latest app"
|
|
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
|
+
$("#journeys-panel")?.classList.toggle("hidden", !signedIn);
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
// The test accounts tapp holds, by application — names and what is held, never a value.
|
|
@@ -352,17 +353,29 @@ function allRuns() {
|
|
|
352
353
|
|
|
353
354
|
// The journeys the open repository has committed under .tapp/flows/. This is the thing a
|
|
354
355
|
// person owns; the engine has listed them all along and the Studio never showed them.
|
|
356
|
+
// The journeys this person owns, with how the last replay went. A repository's committed flows
|
|
357
|
+
// come grouped by folder; kept journeys (from a run that got somewhere) are flat. Both replay
|
|
358
|
+
// the same way and both show the same status pill.
|
|
359
|
+
function journeyStatus(status) {
|
|
360
|
+
if (!status) return '<span class="journey-status never">never run</span>';
|
|
361
|
+
return `<span class="journey-status ${status.passed ? "passing" : "failing"}">${status.passed ? "passing" : "failing"} · ${esc(compactDate(status.at))}</span>`;
|
|
362
|
+
}
|
|
363
|
+
|
|
355
364
|
function renderJourneys() {
|
|
356
365
|
const node = $("#journeys-list");
|
|
357
366
|
if (!node) return;
|
|
358
|
-
const
|
|
359
|
-
setCount("#journey-count",
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
367
|
+
const journeys = state.journeys || [];
|
|
368
|
+
setCount("#journey-count", journeys.length);
|
|
369
|
+
const note = $("#journeys-note");
|
|
370
|
+
if (note) note.textContent = journeys.some((j) => j.source === "repo")
|
|
371
|
+
? "Committed under .tapp/flows/. Each replays exactly as written — no model, no key — and is what the release gate guards."
|
|
372
|
+
: state.session?.access === "account"
|
|
373
|
+
? "Each replays exactly as written — no model, no key. Keep one from any run that got somewhere. tapp re-runs every kept journey daily and shows the result here."
|
|
374
|
+
: "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.";
|
|
375
|
+
if (!journeys.length) { node.innerHTML = '<div class="empty">No journeys yet. Explore a site — when a run gets somewhere, tapp offers to keep it.</div>'; return; }
|
|
363
376
|
const groups = new Map();
|
|
364
|
-
for (const
|
|
365
|
-
const row = (
|
|
377
|
+
for (const journey of journeys) { const key = journey.group || ""; if (!groups.has(key)) groups.set(key, []); groups.get(key).push(journey); }
|
|
378
|
+
const row = (j) => `<div class="journey-row"><span class="journey-platform ${esc(j.platform || "web")}">${esc(j.platform || "web")}</span><span class="journey-name">${esc(j.name)}<br><small>${j.steps || 0} steps · ${journeyStatus(j.status)}</small></span><span></span><span class="journey-actions"><button class="quiet" data-run-journey="${esc(j.slug)}" title="Replay this journey">▶ Run</button>${j.source === "kept" ? `<button class="quiet" data-forget-journey="${esc(j.slug)}" title="Forget this journey">Forget</button>` : ""}</span></div>`;
|
|
366
379
|
node.innerHTML = [...groups.entries()].sort(([a], [b]) => (a === "" ? -1 : b === "" ? 1 : a.localeCompare(b))).map(([group, items]) =>
|
|
367
380
|
group === ""
|
|
368
381
|
? items.map(row).join("")
|
|
@@ -370,18 +383,68 @@ function renderJourneys() {
|
|
|
370
383
|
).join("");
|
|
371
384
|
}
|
|
372
385
|
|
|
373
|
-
async function
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
386
|
+
async function loadJourneys() {
|
|
387
|
+
if (!state.session || state.session.access === "anonymous") { state.journeys = []; return; }
|
|
388
|
+
state.journeys = (await api("/api/journeys").catch(() => ({ journeys: [] }))).journeys || [];
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
async function runJourney(slug) {
|
|
392
|
+
const name = String(slug).replace(/^\.tapp\/flows\//, "").replace(/\.ya?ml$/i, "");
|
|
393
|
+
const known = (state.journeys || []).find((j) => j.slug === name);
|
|
394
|
+
state.promptRun = true; state.promptPlatform = "web";
|
|
395
|
+
showProduct(); activateView("overview"); renderDeviceChrome(); renderChat();
|
|
396
|
+
document.querySelector(".device-stage")?.classList.remove("hidden");
|
|
397
|
+
setHeading(known?.name || name, "Replaying the journey exactly as kept.", { owned: true });
|
|
377
398
|
const result = await runOperation("run-flow", { name }, { input: name });
|
|
378
399
|
if (result?.kind === "self-host") { answerSelfHost(result); return; }
|
|
379
400
|
if (result?.kind === "journey") {
|
|
380
401
|
pushLine({ kind: "summary", tone: result.passed ? "ready" : "blocked", pill: result.passed ? "Passed" : "Failed", text: `${result.name}: ${result.executed}/${result.total} steps${result.failed ? `, ${result.failed} failed` : ""}.` });
|
|
381
402
|
renderChat();
|
|
403
|
+
await loadJourneys(); renderJourneys();
|
|
382
404
|
}
|
|
383
405
|
}
|
|
384
406
|
|
|
407
|
+
async function forgetJourney(slug) {
|
|
408
|
+
await api(`/api/journeys/${encodeURIComponent(slug)}`, { method:"DELETE" });
|
|
409
|
+
await loadJourneys(); renderJourneys();
|
|
410
|
+
toast("Forgot that journey.");
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// A run that got somewhere is worth keeping: offer it in the chat, with a name to edit.
|
|
414
|
+
async function offerJourney(result) {
|
|
415
|
+
const captureId = result?.capture?.id;
|
|
416
|
+
if (!captureId || !(result?.actionsPerformed > 0)) return;
|
|
417
|
+
// Ask the server what the journey would be — its name comes from where the run went.
|
|
418
|
+
let preview = null;
|
|
419
|
+
try { preview = await api(`/api/captures/${encodeURIComponent(captureId)}/keep`, { method:"POST", body:JSON.stringify({ preview: true }) }); }
|
|
420
|
+
catch { return; /* a run that only looked around is not offered */ }
|
|
421
|
+
state.pendingKeep = { captureId, suggested: preview.name, steps: preview.steps, screens: preview.screens || [], signedIn: preview.signedIn };
|
|
422
|
+
renderChat();
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function renderKeepCard() {
|
|
426
|
+
const keep = state.pendingKeep;
|
|
427
|
+
if (!keep || state.activeJob) return "";
|
|
428
|
+
return `<form class="chat-ask chat-keep" id="chat-keep" data-capture="${esc(keep.captureId)}">
|
|
429
|
+
<div class="chat-ask-head"><span class="chat-icon">🧭</span><span>This run got somewhere${keep.signedIn ? ", signed in" : ""}: <b>${esc((keep.screens || []).join(" → "))}</b> (${keep.steps} steps). Keep it as a journey? It will replay exactly this path and tell you when it stops working.</span></div>
|
|
430
|
+
<label class="ask-field"><span>Name</span><input name="name" type="text" value="${esc(keep.suggested)}" maxlength="120"></label>
|
|
431
|
+
<div class="ask-actions"><button type="submit" class="primary">Keep</button><button type="button" class="quiet" data-keep="dismiss">Not now</button></div>
|
|
432
|
+
</form>`;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
async function keepJourney(form) {
|
|
436
|
+
const captureId = form.dataset.capture;
|
|
437
|
+
const name = form.elements.name.value.trim();
|
|
438
|
+
try {
|
|
439
|
+
const kept = await api(`/api/captures/${encodeURIComponent(captureId)}/keep`, { method:"POST", body:JSON.stringify({ name }) });
|
|
440
|
+
state.pendingKeep = null;
|
|
441
|
+
pushLine({ kind: "step", icon: "🧭", text: `Kept as “${kept.name}” — ${kept.steps} steps${kept.signedIn ? ", signs in as your test account" : ""}. Run it any time from Journeys.` });
|
|
442
|
+
renderChat();
|
|
443
|
+
await loadJourneys(); renderJourneys();
|
|
444
|
+
toast(`Kept “${kept.name}”.`);
|
|
445
|
+
} catch (error) { toast(error.message, true); }
|
|
446
|
+
}
|
|
447
|
+
|
|
385
448
|
function renderRuns() {
|
|
386
449
|
renderJourneys();
|
|
387
450
|
renderActors();
|
|
@@ -446,6 +509,8 @@ function renderChat() {
|
|
|
446
509
|
// engine waits, so leave the DOM alone until the ask is answered or withdrawn.
|
|
447
510
|
const openAsk = node.querySelector("#chat-ask");
|
|
448
511
|
if (openAsk && state.pendingInput && openAsk.dataset.request === String(state.pendingInput.requestId)) return;
|
|
512
|
+
const openKeep = node.querySelector("#chat-keep");
|
|
513
|
+
if (openKeep && state.pendingKeep && openKeep.dataset.capture === state.pendingKeep.captureId && !state.activeJob) return;
|
|
449
514
|
const stickToBottom = node.scrollTop + node.clientHeight >= node.scrollHeight - 24;
|
|
450
515
|
const lines = state.transcript.map((entry) => {
|
|
451
516
|
if (entry.kind === "shots") return `<div class="chat-shots">${entry.shots.map((shot) => `<a href="${esc(shot.href)}" target="_blank" rel="noreferrer" title="${esc(shot.caption)}"><img src="${esc(shot.src)}" alt="${esc(shot.caption)}"></a>`).join("")}</div>`;
|
|
@@ -454,7 +519,7 @@ function renderChat() {
|
|
|
454
519
|
if (entry.kind === "finding") return `<div class="chat-line finding ${esc(entry.severity)}"><span class="chat-icon">${entry.icon}</span><span>${esc(entry.text)}</span></div>`;
|
|
455
520
|
if (entry.kind === "progress") return "";
|
|
456
521
|
return `<div class="chat-line ${esc(entry.kind || "")}"><span class="chat-icon">${entry.icon || "•"}</span><span>${esc(entry.text)}${entry.detail ? ` <em>— ${esc(entry.detail)}</em>` : ""}</span></div>`;
|
|
457
|
-
}).join("") + renderAskCard() + (state.activeJob && !state.pendingInput ? '<div class="chat-line typing"><span class="chat-icon">✨</span><span>tapp is working<i>…</i></span></div>' : "");
|
|
522
|
+
}).join("") + renderAskCard() + renderKeepCard() + (state.activeJob && !state.pendingInput ? '<div class="chat-line typing"><span class="chat-icon">✨</span><span>tapp is working<i>…</i></span></div>' : "");
|
|
458
523
|
node.innerHTML = lines;
|
|
459
524
|
if (stickToBottom) node.scrollTop = node.scrollHeight;
|
|
460
525
|
const progress = [...state.transcript].reverse().find((entry) => entry.kind === "progress");
|
|
@@ -577,7 +642,7 @@ async function finishTranscript(name, job) {
|
|
|
577
642
|
if (items.length) pushLine({ kind: "attachments", items });
|
|
578
643
|
} catch { /* the summary still renders */ }
|
|
579
644
|
}
|
|
580
|
-
pushLine({ kind: "summary", ...summarize(name, result.exploration ? { ...result, report } : result) });
|
|
645
|
+
pushLine({ kind: "summary", ...summarize(name, result.exploration ? { ...result, report } : result, { access: state.session?.access || "" }) });
|
|
581
646
|
}
|
|
582
647
|
|
|
583
648
|
function seedIdleTranscript() {
|
|
@@ -662,6 +727,7 @@ async function refresh() {
|
|
|
662
727
|
state.audits = runs.audits || [];
|
|
663
728
|
state.explores = runs.explores || [];
|
|
664
729
|
state.actors = actors.apps || [];
|
|
730
|
+
await loadJourneys();
|
|
665
731
|
renderProject();
|
|
666
732
|
return;
|
|
667
733
|
}
|
|
@@ -670,6 +736,7 @@ async function refresh() {
|
|
|
670
736
|
state.live = live;
|
|
671
737
|
state.audits = runs.audits || [];
|
|
672
738
|
state.explores = runs.explores || [];
|
|
739
|
+
await loadJourneys();
|
|
673
740
|
renderProject();
|
|
674
741
|
}
|
|
675
742
|
|
|
@@ -774,6 +841,8 @@ async function startFromPrompt(raw) {
|
|
|
774
841
|
}
|
|
775
842
|
if (result?.kind === "self-host") { answerSelfHost(result); return; }
|
|
776
843
|
state.selectedRunId = result?.capture?.id || state.selectedRunId;
|
|
844
|
+
state.pendingKeep = null;
|
|
845
|
+
await offerJourney(result);
|
|
777
846
|
return;
|
|
778
847
|
}
|
|
779
848
|
state.promptRun = true; state.promptPlatform = "web";
|
|
@@ -844,6 +913,8 @@ document.addEventListener("submit", (event) => {
|
|
|
844
913
|
if (ask) { event.preventDefault(); answerAsk(ask, "submit"); }
|
|
845
914
|
const signin = event.target.closest("#signin-form");
|
|
846
915
|
if (signin) { event.preventDefault(); requestSignInLink(signin.elements.email.value.trim()); }
|
|
916
|
+
const keep = event.target.closest("#chat-keep");
|
|
917
|
+
if (keep) { event.preventDefault(); keepJourney(keep); }
|
|
847
918
|
});
|
|
848
919
|
document.addEventListener("click", (event) => {
|
|
849
920
|
const button = event.target.closest("#chat-ask [data-ask]");
|
|
@@ -858,6 +929,9 @@ document.addEventListener("click", (event) => {
|
|
|
858
929
|
state.signInOpen = true; renderAccount(); showPrompt(); setTimeout(() => $("#signin-email")?.focus(), 50);
|
|
859
930
|
}
|
|
860
931
|
if (event.target.closest("[data-signout]")) { event.preventDefault(); signOut(); }
|
|
932
|
+
if (event.target.closest("[data-keep=dismiss]")) { event.preventDefault(); state.pendingKeep = null; renderChat(); }
|
|
933
|
+
const forgetJ = event.target.closest("[data-forget-journey]");
|
|
934
|
+
if (forgetJ) { event.preventDefault(); forgetJourney(forgetJ.dataset.forgetJourney).catch((error) => toast(error.message, true)); }
|
|
861
935
|
const forget = event.target.closest("[data-forget-actor]");
|
|
862
936
|
if (forget) { event.preventDefault(); forgetActor(forget.dataset.forgetHost, forget.dataset.forgetActor).catch((error) => toast(error.message, true)); }
|
|
863
937
|
});
|
package/browser/index.html
CHANGED
|
@@ -176,8 +176,8 @@
|
|
|
176
176
|
<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
177
|
<div id="actors-list"><div class="empty">None yet. Explore a site with a sign-in and tapp will ask.</div></div>
|
|
178
178
|
</section>
|
|
179
|
-
<section class="panel section" id="journeys-panel"
|
|
180
|
-
<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>
|
|
179
|
+
<section class="panel section" id="journeys-panel">
|
|
180
|
+
<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
181
|
<div id="journeys-list"><div class="empty">No journeys yet.</div></div>
|
|
182
182
|
</section>
|
|
183
183
|
<div class="split-view">
|
package/browser/view-model.js
CHANGED
|
@@ -85,12 +85,15 @@ export function narrateFinding(finding = {}) {
|
|
|
85
85
|
|
|
86
86
|
// The summary card at the end of a run: the gate's outcome when there is one, otherwise what the
|
|
87
87
|
// engine's headline says it observed. Never a score.
|
|
88
|
-
export function summarize(name, result = {}) {
|
|
88
|
+
export function summarize(name, result = {}, { access = "" } = {}) {
|
|
89
89
|
const report = result?.report || result;
|
|
90
90
|
const gateOutcome = report?.gate?.outcome || (report?.gate?.failed === true ? "fail" : report?.gate ? "pass" : null);
|
|
91
91
|
if (name === "audit") {
|
|
92
92
|
const issues = result.issueCount || 0;
|
|
93
|
-
|
|
93
|
+
// A visitor only ever gets the read-only look; say what the next step is, because the
|
|
94
|
+
// interesting part of any real application is behind its sign-in.
|
|
95
|
+
const next = access === "anonymous" ? " Sign in and tapp will go inside — and ask you for a test account if it meets a sign-in." : "";
|
|
96
|
+
return { tone: issues ? "caution" : "ready", pill: issues ? `${issues} issue${issues === 1 ? "" : "s"} found` : "✓ Nothing broken observed", text: `${result.pagesAudited || 0} page(s) rendered read-only — nothing was clicked. ${issues ? "Each issue is listed in the run detail with the pages it appears on." : "This says the pages are served without structural defects, not that the site works."}${next}` };
|
|
94
97
|
}
|
|
95
98
|
if (gateOutcome) {
|
|
96
99
|
const tone = { pass: "ready", fail: "blocked", inconclusive: "caution" }[gateOutcome] || "caution";
|
package/docs/BROWSER-PRODUCT.md
CHANGED
|
@@ -114,3 +114,26 @@ write-only from the UI, encrypted at rest, decrypted only inside the run that si
|
|
|
114
114
|
|
|
115
115
|
A local trial of the public mode (`--origin http://127.0.0.1:PORT`) does not pin browser egress
|
|
116
116
|
to public addresses, so it can reach a site on the same machine; a real origin always does.
|
|
117
|
+
|
|
118
|
+
## Journeys: keeping a proven run
|
|
119
|
+
|
|
120
|
+
A run that got somewhere is offered in the chat as a journey (`journeys.js`). Keeping it writes a
|
|
121
|
+
Flow in the runner's vocabulary — `wait_for` each screen, `tap` each control and navigation link,
|
|
122
|
+
`login: $TEST_EMAIL / $TEST_PASSWORD` for a sign-in, `assert_screen` on the last screen — to the
|
|
123
|
+
place this person owns:
|
|
124
|
+
|
|
125
|
+
| Who | Where | Replayed by |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| Operator with a repository open | `<repo>/.tapp/flows/<slug>.yml` | the Studio, `tapp run`, `tapp ci` |
|
|
128
|
+
| Account on a public Studio | `TAPP_HOME/accounts/journeys/<id>/<slug>.yml` | the Studio |
|
|
129
|
+
| Operator without a repository | `TAPP_HOME/journeys/<slug>.yml` | the Studio |
|
|
130
|
+
|
|
131
|
+
The last replay's result sits beside it in `.status/<slug>.json` and shows in the Journeys panel
|
|
132
|
+
as *passing · 2h ago*, *failing* or *never run*. A replay resolves `$TEST_EMAIL`/`$TEST_PASSWORD`
|
|
133
|
+
from the encrypted actor store for the journey's `actor` (never from the file) and, for a journey
|
|
134
|
+
kept from a run that started signed in, opens the browser from that actor's saved session.
|
|
135
|
+
|
|
136
|
+
Endpoints: `POST /api/captures/:id/keep` (`{ name, actor, replace, preview }` — `preview` names
|
|
137
|
+
the journey and lists its screens without keeping it), `GET /api/journeys`,
|
|
138
|
+
`DELETE /api/journeys/:slug` (kept journeys only; committed flows are the repository's),
|
|
139
|
+
`POST /api/operations/run-flow` (`{ name }`).
|
|
@@ -21,6 +21,7 @@ import { AccountStore } from "./account-store.js";
|
|
|
21
21
|
import { ActorStore, hostKey } from "./actor-store.js";
|
|
22
22
|
import { createMailer, signInMessage } from "./mailer.js";
|
|
23
23
|
import { accessConfig, createAccessVerifier } from "./access-jwt.js";
|
|
24
|
+
import { journeyFromCapture, JourneyStore, slugify } from "./journeys.js";
|
|
24
25
|
|
|
25
26
|
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
26
27
|
const assetRoot = path.join(packageRoot, "browser");
|
|
@@ -153,8 +154,11 @@ function anonymousAllows(method, pathname) {
|
|
|
153
154
|
function accountAllows(method, pathname) {
|
|
154
155
|
if (anonymousAllows(method, pathname)) return true;
|
|
155
156
|
if (method === "POST" && (pathname === "/api/auth/signout" || /^\/api\/jobs\/[a-f0-9]{20}\/input$/.test(pathname))) return true;
|
|
156
|
-
if (method === "GET" && pathname === "/api/actors") return true;
|
|
157
|
+
if (method === "GET" && (pathname === "/api/actors" || pathname === "/api/journeys")) return true;
|
|
157
158
|
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
|
+
// Journeys: keep a proven run, replay it, forget it (ADR-0009 slice 3).
|
|
160
|
+
if (method === "POST" && (/^\/api\/captures\/[A-Za-z0-9._-]{1,128}\/keep$/.test(pathname) || pathname === "/api/operations/run-flow")) return true;
|
|
161
|
+
if (method === "DELETE" && /^\/api\/journeys\/[a-z0-9-]{1,60}$/.test(pathname)) return true;
|
|
158
162
|
return false;
|
|
159
163
|
}
|
|
160
164
|
|
|
@@ -255,6 +259,57 @@ function markPromptStarted(structured) {
|
|
|
255
259
|
} catch { /* listing is a convenience; the capture is the evidence */ }
|
|
256
260
|
}
|
|
257
261
|
|
|
262
|
+
// Replay one web journey and record how it went. Shared by the Studio's Run button and the
|
|
263
|
+
// daily check, so both leave the same status and the same evidence behind.
|
|
264
|
+
async function replayJourney({ store, slug, flow, actorRoot = "", ownerKey = null, progress = () => {} }) {
|
|
265
|
+
// A journey that signs in does so as the test account tapp was told about for that site: the
|
|
266
|
+
// values come from the encrypted actor store at replay and never from the file.
|
|
267
|
+
const variables = {};
|
|
268
|
+
let storageStatePath = "";
|
|
269
|
+
if (flow.url && (flow.actor || (flow.steps || []).some((step) => step && typeof step === "object" && "login" in step))) {
|
|
270
|
+
const actors = new ActorStore(actorRoot ? { root: actorRoot } : {});
|
|
271
|
+
const record = actors.read(flow.url, flow.actor || "default");
|
|
272
|
+
if (record?.credentials?.email) variables.TEST_EMAIL = record.credentials.email;
|
|
273
|
+
if (record?.credentials?.password) variables.TEST_PASSWORD = record.credentials.password;
|
|
274
|
+
// A journey that began inside replays from the actor's saved session, like the run did.
|
|
275
|
+
if (flow.actor) storageStatePath = actors.sessionFile(flow.url, flow.actor) || "";
|
|
276
|
+
}
|
|
277
|
+
const captureId = `flow-web-${Date.now().toString(36)}-${crypto.randomBytes(4).toString("hex")}`;
|
|
278
|
+
const evidenceDir = path.join(captureRoot(), captureId);
|
|
279
|
+
fs.mkdirSync(evidenceDir, { recursive: true });
|
|
280
|
+
if (ownerKey) setCaptureOwner(captureId, ownerKey);
|
|
281
|
+
progress({ phase: "runtime", text: `Replaying ${flow.name || slug}` });
|
|
282
|
+
const { runWebFlow } = await import("./web-flow.js");
|
|
283
|
+
let result;
|
|
284
|
+
try { result = await runWebFlow({ flow, variables, storageStatePath, logPath: path.join(evidenceDir, "flow.log"), screenshotDir: evidenceDir, recordVideoDir: evidenceDir }); }
|
|
285
|
+
finally { if (storageStatePath) { try { fs.rmSync(storageStatePath, { force: true }); } catch { /* temp */ } } }
|
|
286
|
+
// The runner's log is marker lines; the chat wants one plain sentence per step.
|
|
287
|
+
for (const line of result.lines || []) {
|
|
288
|
+
const raw = typeof line === "string" ? line : (line.text || "");
|
|
289
|
+
const step = raw.match(/^OCQA_FLOW_STEP:(\{.*\})$/);
|
|
290
|
+
if (step) {
|
|
291
|
+
try {
|
|
292
|
+
const st = JSON.parse(step[1]);
|
|
293
|
+
const what = st.action === "login" ? "Signed in" : st.action === "wait_for" ? `Reached ${st.target}` : st.action === "assert_screen" ? `On ${st.target}` : st.action === "tap" ? `Tapped "${st.target}"` : `${st.action} ${st.target || ""}`.trim();
|
|
294
|
+
progress({ phase: "replay", text: st.status === "pass" ? `${what}` : `Step ${st.index}: ${what} — ${st.detail || "failed"}` });
|
|
295
|
+
} catch { progress({ phase: "replay", text: raw }); }
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
if (/^OCQA_(FLOW_RESULT|ISSUE):/.test(raw)) continue;
|
|
299
|
+
if (raw) progress({ phase: "replay", text: raw });
|
|
300
|
+
}
|
|
301
|
+
const status = store.recordRun(slug, { passed: result.passed, captureId, executed: result.executed, total: result.total, failed: result.failed });
|
|
302
|
+
return { kind: "journey", name: flow.name || slug, slug, passed: result.passed, executed: result.executed, total: result.total, failed: result.failed, status, capture: { id: captureId, path: evidenceDir } };
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
// "Make sure this always works": kept journeys on a public Studio are replayed on a schedule,
|
|
306
|
+
// each in its owner's lane so a check never queues ahead of the owner's own run. A journey is
|
|
307
|
+
// due when its last result is older than the interval (TAPP_JOURNEY_CHECK_HOURS, default 24);
|
|
308
|
+
// a restart therefore does not re-run everything, and a busy lane simply waits for the next tick.
|
|
309
|
+
export function dueJourneys(journeys, { intervalMs, now = Date.now() }) {
|
|
310
|
+
return journeys.filter((j) => (j.platform || "web") === "web" && (!j.status || now - Date.parse(j.status.at || 0) >= intervalMs));
|
|
311
|
+
}
|
|
312
|
+
|
|
258
313
|
function openBrowser(url) {
|
|
259
314
|
const invocation = process.platform === "darwin" ? ["open", [url]]
|
|
260
315
|
: process.platform === "win32" ? ["cmd", ["/c", "start", "", url]]
|
|
@@ -583,6 +638,37 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
583
638
|
return job;
|
|
584
639
|
};
|
|
585
640
|
|
|
641
|
+
// Daily checks of every account's kept journeys (public Studio only; a local Studio is not
|
|
642
|
+
// always running, and its journeys are the repository's to guard in CI).
|
|
643
|
+
const checkIntervalMs = Math.max(1, Number(process.env.TAPP_JOURNEY_CHECK_HOURS) || 24) * 60 * 60 * 1000;
|
|
644
|
+
const runJourneyChecks = async () => {
|
|
645
|
+
if (!accounts) return;
|
|
646
|
+
const journeysRoot = path.join(accounts.root, "journeys");
|
|
647
|
+
let owners = [];
|
|
648
|
+
try { owners = fs.readdirSync(journeysRoot, { withFileTypes: true }).filter((d) => d.isDirectory() && /^[a-f0-9]{24}$/.test(d.name)).map((d) => d.name); } catch { return; }
|
|
649
|
+
for (const accountId of owners) {
|
|
650
|
+
const store = JourneyStore.forAccount(accountId);
|
|
651
|
+
const ownerKey = `acct:${accountId}`;
|
|
652
|
+
for (const journey of dueJourneys(store.list(), { intervalMs: checkIntervalMs })) {
|
|
653
|
+
const flowPath = store.flowPath(journey.slug);
|
|
654
|
+
let flow;
|
|
655
|
+
try { const { loadFlowFile } = await import("./flow-runtime.js"); flow = loadFlowFile(flowPath); } catch { continue; }
|
|
656
|
+
let job;
|
|
657
|
+
try {
|
|
658
|
+
job = startJob("check-journey", (progress) => replayJourney({ store, slug: journey.slug, flow, actorRoot: accounts.actorRoot(accountId), ownerKey, progress }), null, { lane: ownerKey });
|
|
659
|
+
} catch { continue; /* the owner is busy; next tick */ }
|
|
660
|
+
job.ownerKey = ownerKey;
|
|
661
|
+
// One at a time per owner: wait for this check before starting the next.
|
|
662
|
+
await new Promise((resolve) => { const tick = () => (job.status === "running" ? setTimeout(tick, 1000) : resolve()); tick(); });
|
|
663
|
+
logUsage("journey.checked", { owner: ownerKey.slice(0, 13), passed: job.result?.passed ?? null });
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
const checkTimer = publicAccess ? setInterval(() => { runJourneyChecks().catch(() => {}); }, 60 * 60 * 1000) : null;
|
|
668
|
+
if (checkTimer?.unref) checkTimer.unref();
|
|
669
|
+
const firstCheck = publicAccess ? setTimeout(() => { runJourneyChecks().catch(() => {}); }, 10 * 60 * 1000) : null;
|
|
670
|
+
if (firstCheck?.unref) firstCheck.unref();
|
|
671
|
+
|
|
586
672
|
const server = http.createServer(async (request, response) => {
|
|
587
673
|
const url = new URL(request.url || "/", origin || "http://127.0.0.1");
|
|
588
674
|
const baseHeaders = {
|
|
@@ -787,6 +873,56 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
787
873
|
json(response, 200, { ok: true });
|
|
788
874
|
return;
|
|
789
875
|
}
|
|
876
|
+
// Where this person's journeys live: the open repository's .tapp/flows/ for the operator,
|
|
877
|
+
// the account's own store on a public Studio, this machine's store otherwise.
|
|
878
|
+
const journeyStore = () => {
|
|
879
|
+
if (account) return JourneyStore.forAccount(account.id);
|
|
880
|
+
const root = registry.currentRoot();
|
|
881
|
+
return root ? JourneyStore.forRepository(root) : JourneyStore.forMachine();
|
|
882
|
+
};
|
|
883
|
+
const keepMatch = !anonymous && request.method === "POST" ? url.pathname.match(/^\/api\/captures\/([A-Za-z0-9._-]{1,128})\/keep$/) : null;
|
|
884
|
+
if (keepMatch) {
|
|
885
|
+
requireMutationAuth(request, hosted ? publicOrigins : origin, csrfToken);
|
|
886
|
+
if (!visibleToOwner(keepMatch[1], evidenceOwner)) { response.writeHead(404); response.end("Not found"); return; }
|
|
887
|
+
const captureDir = capturePath(keepMatch[1], ".");
|
|
888
|
+
if (!captureDir || !fs.existsSync(captureDir)) { json(response, 404, { error: "No such capture" }); return; }
|
|
889
|
+
const body = await readJsonBody(request);
|
|
890
|
+
const journey = journeyFromCapture(captureDir, { name: String(body.name || "").slice(0, 120), actor: /^[A-Za-z][A-Za-z0-9_-]{0,63}$/.test(String(body.actor || "")) ? String(body.actor) : "default" });
|
|
891
|
+
if (!journey) { json(response, 409, { error: "That run only looked around; there is no path to keep." }); return; }
|
|
892
|
+
// A preview names the journey and lists where it went without keeping anything, so the
|
|
893
|
+
// Studio can offer it with the right name instead of a guess.
|
|
894
|
+
if (body.preview === true) { json(response, 200, { name: journey.flow.name, slug: slugify(journey.flow.name), steps: journey.steps, screens: journey.screens, signedIn: journey.signedIn, preview: true }); return; }
|
|
895
|
+
let kept;
|
|
896
|
+
try { kept = journeyStore().keep(journey, { replace: body.replace === true }); }
|
|
897
|
+
catch (error) { json(response, error.statusCode || 500, { error: error.message }); return; }
|
|
898
|
+
logUsage("journey.kept", { owner: (ownerKey || "operator").slice(0, 13), steps: journey.steps, signedIn: journey.signedIn });
|
|
899
|
+
json(response, 200, { name: journey.flow.name, slug: kept.slug, steps: journey.steps, screens: journey.screens, signedIn: journey.signedIn, path: registry.currentRoot() && !account ? path.relative(registry.currentRoot(), kept.path) : null });
|
|
900
|
+
return;
|
|
901
|
+
}
|
|
902
|
+
if (!anonymous && request.method === "GET" && url.pathname === "/api/journeys") {
|
|
903
|
+
const store = journeyStore();
|
|
904
|
+
const root = !account ? registry.currentRoot() : null;
|
|
905
|
+
let journeys;
|
|
906
|
+
if (root) {
|
|
907
|
+
// The repository's committed flows, recursively, with the last Studio replay beside each.
|
|
908
|
+
const { readProductProject } = await import("./product-operations.js");
|
|
909
|
+
const flows = readProductProject({ projectDir: root }).flows || [];
|
|
910
|
+
journeys = flows.map((flow) => ({ name: flow.name, slug: flow.relativePath.replace(/^\.tapp\/flows\//, "").replace(/\.(?:ya?ml|json)$/i, ""), group: flow.group || "", platform: flow.platform, steps: flow.steps, source: "repo", status: store.status(flow.relativePath.replace(/^\.tapp\/flows\//, "").replace(/\.(?:ya?ml|json)$/i, "")) }));
|
|
911
|
+
} else {
|
|
912
|
+
journeys = store.list().map((journey) => ({ ...journey, group: "" }));
|
|
913
|
+
}
|
|
914
|
+
json(response, 200, { journeys });
|
|
915
|
+
return;
|
|
916
|
+
}
|
|
917
|
+
const forgetJourneyMatch = !anonymous && request.method === "DELETE" ? url.pathname.match(/^\/api\/journeys\/([a-z0-9-]{1,60})$/) : null;
|
|
918
|
+
if (forgetJourneyMatch) {
|
|
919
|
+
requireMutationAuth(request, hosted ? publicOrigins : origin, csrfToken);
|
|
920
|
+
// Committed flows are the repository's; only kept journeys are forgotten from here.
|
|
921
|
+
if (!account && registry.currentRoot()) { json(response, 409, { error: "That journey is committed in the repository; remove the file there." }); return; }
|
|
922
|
+
journeyStore().forget(forgetJourneyMatch[1]);
|
|
923
|
+
json(response, 200, { ok: true });
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
790
926
|
if (request.method === "GET" && url.pathname === "/api/session") {
|
|
791
927
|
if (account) {
|
|
792
928
|
json(response, 200, {
|
|
@@ -1033,30 +1169,29 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
1033
1169
|
// answered with the command to run it where that is.
|
|
1034
1170
|
if (operation === "run-flow") {
|
|
1035
1171
|
if (anonymous) { json(response, 401, { error: "Sign in to replay a journey" }); return; }
|
|
1036
|
-
const
|
|
1037
|
-
|
|
1172
|
+
const store = journeyStore();
|
|
1173
|
+
const root = !account ? registry.currentRoot() : null;
|
|
1038
1174
|
const name = String(body.name || "").replace(/\.ya?ml$/i, "");
|
|
1039
1175
|
if (!/^[A-Za-z0-9][A-Za-z0-9._\/-]{0,120}$/.test(name) || name.includes("..")) throw Object.assign(new Error("That is not a journey name"), { statusCode: 400 });
|
|
1040
|
-
|
|
1041
|
-
|
|
1176
|
+
// A repository journey may sit in a subfolder; a kept one is a flat slug in its store.
|
|
1177
|
+
const flowPath = root ? path.join(root, ".tapp", "flows", `${name}.yml`) : store.flowPath(name);
|
|
1178
|
+
if (!flowPath.startsWith(store.root + path.sep) || !fs.existsSync(flowPath)) throw Object.assign(new Error(`No journey named ${name}`), { statusCode: 404 });
|
|
1042
1179
|
const { loadFlowFile, inferFlowPlatform } = await import("./flow-runtime.js");
|
|
1043
1180
|
const flow = loadFlowFile(flowPath);
|
|
1044
1181
|
const platform = inferFlowPlatform(flow);
|
|
1182
|
+
const shown = root ? path.relative(root, flowPath) : `${name}.yml`;
|
|
1045
1183
|
if (platform !== "web") {
|
|
1046
|
-
json(response, 200, { kind: "self-host", command: `npx -y @aarwitz/tapp@latest run ${
|
|
1047
|
-
message: `${flow.name || name} runs on ${platform === "android" ? "an Android device or emulator" : "an iOS simulator"}, which the Studio does not have. Run it where that is: npx -y @aarwitz/tapp@latest run ${
|
|
1184
|
+
json(response, 200, { kind: "self-host", command: `npx -y @aarwitz/tapp@latest run ${shown}`,
|
|
1185
|
+
message: `${flow.name || name} runs on ${platform === "android" ? "an Android device or emulator" : "an iOS simulator"}, which the Studio does not have. Run it where that is: npx -y @aarwitz/tapp@latest run ${shown}` });
|
|
1048
1186
|
return;
|
|
1049
1187
|
}
|
|
1050
|
-
const
|
|
1051
|
-
const evidenceDir = path.join(captureRoot(), captureId);
|
|
1052
|
-
fs.mkdirSync(evidenceDir, { recursive: true });
|
|
1188
|
+
const slug = root ? name : slugify(name);
|
|
1053
1189
|
const job = startJob(operation, async (progress) => {
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
}, null);
|
|
1190
|
+
const result = await replayJourney({ store, slug, flow, actorRoot: actorRootFor() || "", ownerKey, progress });
|
|
1191
|
+
logUsage("journey.run", { owner: (ownerKey || "operator").slice(0, 13), passed: result.passed });
|
|
1192
|
+
return result;
|
|
1193
|
+
}, null, { lane: ownerKey || OPERATOR_LANE });
|
|
1194
|
+
job.ownerKey = ownerKey;
|
|
1060
1195
|
json(response, 202, { job: publicJob(job, { hosted }) });
|
|
1061
1196
|
return;
|
|
1062
1197
|
}
|
|
@@ -1239,6 +1374,8 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
|
|
|
1239
1374
|
}
|
|
1240
1375
|
await new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
|
|
1241
1376
|
if (usageHeartbeat) clearInterval(usageHeartbeat);
|
|
1377
|
+
if (checkTimer) clearInterval(checkTimer);
|
|
1378
|
+
if (firstCheck) clearTimeout(firstCheck);
|
|
1242
1379
|
if (egressProxy) { await egressProxy.close().catch(() => {}); restoreEgressEnv(); }
|
|
1243
1380
|
registry.close();
|
|
1244
1381
|
},
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// A proven run becomes a journey you own (ADR-0009 slice 3).
|
|
2
|
+
//
|
|
3
|
+
// An exploration that got somewhere — through a sign-in, across a few screens — is worth more
|
|
4
|
+
// than its report: replayed, it is a test of that path through the real application. This
|
|
5
|
+
// module turns the capture's action log (OCQA_ACTION / OCQA_STATE markers) into a Flow in the
|
|
6
|
+
// vocabulary the deterministic runner already speaks, keeps it where it belongs, and remembers
|
|
7
|
+
// how its last replay went.
|
|
8
|
+
//
|
|
9
|
+
// Where a journey lives:
|
|
10
|
+
// a repository → <repo>/.tapp/flows/<slug>.yml (committed, guarded by `tapp ci`)
|
|
11
|
+
// an account → TAPP_HOME/accounts/journeys/<id>/<slug>.yml
|
|
12
|
+
// a local prompt run → TAPP_HOME/journeys/<slug>.yml
|
|
13
|
+
// Its last result lives beside it in .status/<slug>.json. Credentials never enter a journey: a
|
|
14
|
+
// sign-in is `login: $TEST_EMAIL / $TEST_PASSWORD`, resolved at replay from the actor store.
|
|
15
|
+
import fs from "node:fs";
|
|
16
|
+
import os from "node:os";
|
|
17
|
+
import path from "node:path";
|
|
18
|
+
|
|
19
|
+
const MAX_STEPS = 40;
|
|
20
|
+
|
|
21
|
+
export function slugify(name) {
|
|
22
|
+
return String(name || "").toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "").slice(0, 60) || "journey";
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function readMarkers(captureDir) {
|
|
26
|
+
let text = "";
|
|
27
|
+
try { text = fs.readFileSync(path.join(captureDir, "ocqa-markers.txt"), "utf8"); } catch { return []; }
|
|
28
|
+
const out = [];
|
|
29
|
+
for (const line of text.split("\n")) {
|
|
30
|
+
const match = line.match(/^(OCQA_ACTION|OCQA_STATE):(\{.*\})\s*$/);
|
|
31
|
+
if (!match) continue;
|
|
32
|
+
try { out.push({ kind: match[1], ...JSON.parse(match[2]) }); } catch { /* a torn line */ }
|
|
33
|
+
}
|
|
34
|
+
return out;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// tapp names a revisited screen "Orders (refreshed)"; the page itself still says "Orders".
|
|
38
|
+
const pageName = (screen) => String(screen || "").replace(/\s*\((?:refreshed|again|\d+)\)\s*$/i, "").trim();
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Build a Flow from an exploration capture. Returns null when the run did nothing worth
|
|
42
|
+
* replaying (no action but the opening).
|
|
43
|
+
*/
|
|
44
|
+
export function journeyFromCapture(captureDir, { name = "", actor = "default" } = {}) {
|
|
45
|
+
let provenance = null;
|
|
46
|
+
try { provenance = JSON.parse(fs.readFileSync(path.join(captureDir, "provenance.json"), "utf8")); } catch { /* older capture */ }
|
|
47
|
+
const target = String(provenance?.target || "");
|
|
48
|
+
if (!/^https?:\/\//i.test(target)) return null;
|
|
49
|
+
const markers = readMarkers(captureDir);
|
|
50
|
+
const steps = [];
|
|
51
|
+
const screens = [];
|
|
52
|
+
let lastWaited = "";
|
|
53
|
+
const waitFor = (screen) => {
|
|
54
|
+
const page = pageName(screen);
|
|
55
|
+
if (!page || page === lastWaited) return;
|
|
56
|
+
steps.push({ wait_for: page });
|
|
57
|
+
lastWaited = page;
|
|
58
|
+
screens.push(page);
|
|
59
|
+
};
|
|
60
|
+
let acted = false;
|
|
61
|
+
let signedIn = false;
|
|
62
|
+
for (let i = 0; i < markers.length && steps.length < MAX_STEPS; i += 1) {
|
|
63
|
+
const marker = markers[i];
|
|
64
|
+
if (marker.kind === "OCQA_STATE") { waitFor(marker.screen); continue; }
|
|
65
|
+
switch (marker.type) {
|
|
66
|
+
case "open":
|
|
67
|
+
// The first open is the journey's URL; a later one came through a navigation link.
|
|
68
|
+
if (marker.via && marker.via !== marker.target && marker.via !== "/") { steps.push({ tap: marker.via }); acted = true; }
|
|
69
|
+
break;
|
|
70
|
+
case "login":
|
|
71
|
+
steps.push({ login: { email: "$TEST_EMAIL", password: "$TEST_PASSWORD" } });
|
|
72
|
+
signedIn = true; acted = true;
|
|
73
|
+
break;
|
|
74
|
+
case "session":
|
|
75
|
+
// The run started inside from a saved session; the replay will too (storageState).
|
|
76
|
+
signedIn = true;
|
|
77
|
+
break;
|
|
78
|
+
case "tap":
|
|
79
|
+
if (marker.target) { steps.push({ tap: marker.target }); acted = true; }
|
|
80
|
+
break;
|
|
81
|
+
case "type":
|
|
82
|
+
// What was typed during exploration is not part of the path; the field is.
|
|
83
|
+
if (marker.target && !marker.secure) { steps.push({ type: { field: marker.target, value: String(marker.value || "") } }); acted = true; }
|
|
84
|
+
break;
|
|
85
|
+
default:
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (!acted) return null;
|
|
90
|
+
// End on the screen the run ended on, so a replay that drifts is a failure, not a pass.
|
|
91
|
+
if (lastWaited) { steps.pop(); steps.push({ assert_screen: lastWaited }); }
|
|
92
|
+
const host = (() => { try { return new URL(target).host; } catch { return "site"; } })();
|
|
93
|
+
const journeyName = String(name || "").trim() || `${host} — ${screens[0] || "start"}${screens.length > 1 ? ` to ${screens[screens.length - 1]}` : ""}`;
|
|
94
|
+
const flow = { name: journeyName, platform: "web", url: target, ...(signedIn ? { actor } : {}), steps };
|
|
95
|
+
return { flow, yaml: flowToYaml(flow), steps: steps.length, screens, signedIn };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// The Flow vocabulary is small and flat; a dependency-free emitter keeps the hosted Studio from
|
|
99
|
+
// needing python for this. Strings are JSON-quoted, which YAML accepts verbatim.
|
|
100
|
+
const q = (value) => JSON.stringify(String(value));
|
|
101
|
+
export function flowToYaml(flow) {
|
|
102
|
+
const lines = [`name: ${q(flow.name)}`, `platform: ${flow.platform || "web"}`];
|
|
103
|
+
if (flow.url) lines.push(`url: ${q(flow.url)}`);
|
|
104
|
+
if (flow.actor) lines.push(`actor: ${q(flow.actor)}`);
|
|
105
|
+
lines.push("steps:");
|
|
106
|
+
for (const step of flow.steps || []) {
|
|
107
|
+
const [action, value] = Object.entries(step)[0];
|
|
108
|
+
if (value && typeof value === "object") {
|
|
109
|
+
lines.push(`- ${action}:`);
|
|
110
|
+
for (const [key, inner] of Object.entries(value)) lines.push(` ${key}: ${/^\$[A-Z_]+$/.test(String(inner)) ? inner : q(inner)}`);
|
|
111
|
+
} else {
|
|
112
|
+
lines.push(`- ${action}: ${q(value)}`);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return `${lines.join("\n")}\n`;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** Where kept journeys and their statuses live for one owner. */
|
|
119
|
+
export class JourneyStore {
|
|
120
|
+
constructor({ root }) {
|
|
121
|
+
this.root = root;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
static forAccount(accountId, env = process.env) {
|
|
125
|
+
const home = (env.TAPP_HOME || "").trim() || path.join(os.homedir(), ".tapp");
|
|
126
|
+
if (!/^[a-f0-9]{24}$/.test(String(accountId || ""))) throw new Error("Not an account id");
|
|
127
|
+
return new JourneyStore({ root: path.join(home, "accounts", "journeys", accountId) });
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
static forMachine(env = process.env) {
|
|
131
|
+
const home = (env.TAPP_HOME || "").trim() || path.join(os.homedir(), ".tapp");
|
|
132
|
+
return new JourneyStore({ root: path.join(home, "journeys") });
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
static forRepository(repoRoot) {
|
|
136
|
+
return new JourneyStore({ root: path.join(repoRoot, ".tapp", "flows") });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
flowPath(slug) {
|
|
140
|
+
const safe = slugify(slug);
|
|
141
|
+
return path.join(this.root, `${safe}.yml`);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
keep(journey, { replace = false } = {}) {
|
|
145
|
+
const slug = slugify(journey.flow.name);
|
|
146
|
+
const file = this.flowPath(slug);
|
|
147
|
+
if (fs.existsSync(file) && !replace) throw Object.assign(new Error(`A journey named '${journey.flow.name}' already exists. Pick another name or replace it.`), { statusCode: 409 });
|
|
148
|
+
fs.mkdirSync(this.root, { recursive: true, mode: 0o700 });
|
|
149
|
+
fs.writeFileSync(file, journey.yaml, { mode: 0o600 });
|
|
150
|
+
return { slug, path: file };
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
forget(slug) {
|
|
154
|
+
try { fs.rmSync(this.flowPath(slug), { force: true }); fs.rmSync(this.statusPath(slug), { force: true }); return true; } catch { return false; }
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
statusPath(slug) {
|
|
158
|
+
return path.join(this.root, ".status", `${slugify(slug)}.json`);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
recordRun(slug, { passed, captureId = null, executed = 0, total = 0, failed = 0 }) {
|
|
162
|
+
const file = this.statusPath(slug);
|
|
163
|
+
fs.mkdirSync(path.dirname(file), { recursive: true, mode: 0o700 });
|
|
164
|
+
const status = { passed: !!passed, at: new Date().toISOString(), captureId, executed, total, failed };
|
|
165
|
+
fs.writeFileSync(file, JSON.stringify(status), { mode: 0o600 });
|
|
166
|
+
return status;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
status(slug) {
|
|
170
|
+
try { return JSON.parse(fs.readFileSync(this.statusPath(slug), "utf8")); } catch { return null; }
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** Every journey here, with its last result. Names only; never the file contents. */
|
|
174
|
+
list() {
|
|
175
|
+
let entries = [];
|
|
176
|
+
try { entries = fs.readdirSync(this.root, { withFileTypes: true }); } catch { return []; }
|
|
177
|
+
const out = [];
|
|
178
|
+
for (const entry of entries.sort((a, b) => a.name.localeCompare(b.name))) {
|
|
179
|
+
if (!entry.isFile() || !/\.ya?ml$/i.test(entry.name)) continue;
|
|
180
|
+
const slug = entry.name.replace(/\.ya?ml$/i, "");
|
|
181
|
+
let source = "";
|
|
182
|
+
try { source = fs.readFileSync(path.join(this.root, entry.name), "utf8"); } catch { continue; }
|
|
183
|
+
const scalar = (key) => { const m = source.match(new RegExp(`^${key}:\\s*(.+?)\\s*$`, "m")); return m ? m[1].replace(/^["']|["']$/g, "") : ""; };
|
|
184
|
+
const steps = (source.match(/^- [a-z_]+:/gm) || []).length;
|
|
185
|
+
out.push({ name: scalar("name") || slug, slug, platform: scalar("platform") || "web", url: scalar("url"), actor: scalar("actor"), steps, status: this.status(slug), source: "kept" });
|
|
186
|
+
}
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -879,7 +879,9 @@ export async function exploreWeb({ url, maxActions = 40, timeoutSec = 300, outDi
|
|
|
879
879
|
let probeCapHit = false;
|
|
880
880
|
let actions = 0;
|
|
881
881
|
let screenCount = 0;
|
|
882
|
-
|
|
882
|
+
// A marker as well as a line, so a journey kept from this run knows it began inside and
|
|
883
|
+
// replays from the same saved session rather than at a sign-in it never saw.
|
|
884
|
+
if (startedSignedIn) emitAction({ type: "session", target: "saved session", narrative: "Starting signed in from the saved session" });
|
|
883
885
|
// Which distinct on-screen states each route has produced, so one route cannot mint states
|
|
884
886
|
// without limit when something on it never settles.
|
|
885
887
|
const signaturesByRoute = new Map();
|
|
@@ -290,7 +290,7 @@ export function resolveGateFlowUrl(declared, gateUrl) {
|
|
|
290
290
|
}
|
|
291
291
|
}
|
|
292
292
|
|
|
293
|
-
export async function runWebFlow({ flow, url, logPath, screenshotDir, recordVideoDir, variables = {}, strictOrigin = false, playwright, device = "", viewport = "", urlIsFallback = false }) {
|
|
293
|
+
export async function runWebFlow({ flow, url, logPath, screenshotDir, recordVideoDir, variables = {}, strictOrigin = false, playwright, device = "", viewport = "", urlIsFallback = false, storageStatePath = "" }) {
|
|
294
294
|
// urlIsFallback = the caller is a gate: the Flow's own page wins, rebased onto the gate's
|
|
295
295
|
// deployment (see resolveGateFlowUrl). An explicit caller url (CLI positional) still overrides.
|
|
296
296
|
const declaredUrl = flow.url || (/^https?:\/\//i.test(flow.app || "") ? flow.app : "");
|
|
@@ -311,6 +311,8 @@ export async function runWebFlow({ flow, url, logPath, screenshotDir, recordVide
|
|
|
311
311
|
const context = await browser.newContext({
|
|
312
312
|
...contextOptions,
|
|
313
313
|
...(recordVideoDir ? { recordVideo: { dir: recordVideoDir, ...(contextOptions.viewport ? { size: contextOptions.viewport } : {}) } } : {}),
|
|
314
|
+
// A journey kept from a run that started signed in replays from the same saved session.
|
|
315
|
+
...(storageStatePath ? { storageState: storageStatePath } : {}),
|
|
314
316
|
});
|
|
315
317
|
const page = await context.newPage();
|
|
316
318
|
const timeout = Number(flow.timeoutMs ?? flow.timeout) || DEFAULT_TIMEOUT;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aarwitz/tapp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.24.1",
|
|
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/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/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
|
}
|
package/scripts/flow_lib.py
CHANGED
|
@@ -37,7 +37,7 @@ def to_yaml(json_str):
|
|
|
37
37
|
# Order keys for readability. `platform` + `url` make the same repository-native
|
|
38
38
|
# Flow format portable across the XCUITest, Playwright, and Android drivers.
|
|
39
39
|
ordered = {}
|
|
40
|
-
for k in ("name", "platform", "app", "url", "vars", "reset"):
|
|
40
|
+
for k in ("name", "platform", "app", "url", "actor", "vars", "reset"):
|
|
41
41
|
if flow.get(k):
|
|
42
42
|
ordered[k] = flow[k]
|
|
43
43
|
ordered["steps"] = flow.get("steps", [])
|
|
@@ -54,6 +54,8 @@ def to_json(path):
|
|
|
54
54
|
"platform": flow.get("platform", ""),
|
|
55
55
|
"app": flow.get("app", ""),
|
|
56
56
|
"url": flow.get("url", ""),
|
|
57
|
+
# Which test account a journey signs in as (ADR-0009); the Studio resolves it at replay.
|
|
58
|
+
"actor": str(flow.get("actor", "") or ""),
|
|
57
59
|
"steps": flow.get("steps", []),
|
|
58
60
|
"vars": flow.get("vars", {}),
|
|
59
61
|
"reset": flow.get("reset", "launch"),
|