@aarwitz/tapp 0.24.0 → 0.24.2

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.
@@ -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.24.0",
4
+ "version": "0.24.2",
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.24.0",
27
+ "@aarwitz/tapp@0.24.2",
28
28
  "mcp"
29
29
  ],
30
30
  "cwd": "${CLAUDE_PROJECT_DIR}"
package/browser/app.js CHANGED
@@ -369,7 +369,9 @@ function renderJourneys() {
369
369
  const note = $("#journeys-note");
370
370
  if (note) note.textContent = journeys.some((j) => j.source === "repo")
371
371
  ? "Committed under .tapp/flows/. Each replays exactly as written — no model, no key — and is what the release gate guards."
372
- : "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.";
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.";
373
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; }
374
376
  const groups = new Map();
375
377
  for (const journey of journeys) { const key = journey.group || ""; if (!groups.has(key)) groups.set(key, []); groups.get(key).push(journey); }
@@ -640,7 +642,7 @@ async function finishTranscript(name, job) {
640
642
  if (items.length) pushLine({ kind: "attachments", items });
641
643
  } catch { /* the summary still renders */ }
642
644
  }
643
- 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 || "" }) });
644
646
  }
645
647
 
646
648
  function seedIdleTranscript() {
@@ -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
- 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."}` };
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";
@@ -259,6 +259,78 @@ function markPromptStarted(structured) {
259
259
  } catch { /* listing is a convenience; the capture is the evidence */ }
260
260
  }
261
261
 
262
+ // How a journey gets inside. A journey either types the credentials (it has a `login` step, so it
263
+ // was kept from a run that met the sign-in form and must start signed OUT) or it resumes the
264
+ // actor's saved session (no `login` step: the run it came from already began inside). Doing both
265
+ // breaks the first kind — the browser starts inside and the journey's own first step, waiting for
266
+ // the sign-in screen, never matches.
267
+ export function journeySignInPlan(flow = {}) {
268
+ const signsIn = (flow.steps || []).some((step) => step && typeof step === "object" && "login" in step);
269
+ return { signsIn, usesSession: !!flow.actor && !signsIn };
270
+ }
271
+
272
+ // Replay one web journey and record how it went. Shared by the Studio's Run button and the
273
+ // daily check, so both leave the same status and the same evidence behind.
274
+ async function replayJourney({ store, slug, flow, actorRoot = "", ownerKey = null, progress = () => {} }) {
275
+ // A journey that signs in does so as the test account tapp was told about for that site: the
276
+ // values come from the encrypted actor store at replay and never from the file.
277
+ const variables = {};
278
+ let storageStatePath = "";
279
+ // A journey signs in one of two ways, and they are mutually exclusive:
280
+ // it has a `login` step → it was kept from a run that met the sign-in form, so it must START
281
+ // SIGNED OUT and type the credentials. Handing it a saved session
282
+ // would drop it inside the app, where its own first step ("wait for
283
+ // the sign-in screen") can never match.
284
+ // it has no `login` step → it was kept from a run that already began inside, so the saved
285
+ // session is the only way back in.
286
+ const { signsIn, usesSession } = journeySignInPlan(flow);
287
+ if (flow.url && (flow.actor || signsIn)) {
288
+ const actors = new ActorStore(actorRoot ? { root: actorRoot } : {});
289
+ const record = actors.read(flow.url, flow.actor || "default");
290
+ if (record?.credentials?.email) variables.TEST_EMAIL = record.credentials.email;
291
+ if (record?.credentials?.password) variables.TEST_PASSWORD = record.credentials.password;
292
+ if (usesSession) {
293
+ storageStatePath = actors.sessionFile(flow.url, flow.actor) || "";
294
+ // Say why plainly, rather than letting every step time out looking for a signed-in screen.
295
+ 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.`);
296
+ }
297
+ }
298
+ const captureId = `flow-web-${Date.now().toString(36)}-${crypto.randomBytes(4).toString("hex")}`;
299
+ const evidenceDir = path.join(captureRoot(), captureId);
300
+ fs.mkdirSync(evidenceDir, { recursive: true });
301
+ if (ownerKey) setCaptureOwner(captureId, ownerKey);
302
+ progress({ phase: "runtime", text: `Replaying ${flow.name || slug}` });
303
+ const { runWebFlow } = await import("./web-flow.js");
304
+ let result;
305
+ try { result = await runWebFlow({ flow, variables, storageStatePath, logPath: path.join(evidenceDir, "flow.log"), screenshotDir: evidenceDir, recordVideoDir: evidenceDir }); }
306
+ finally { if (storageStatePath) { try { fs.rmSync(storageStatePath, { force: true }); } catch { /* temp */ } } }
307
+ // The runner's log is marker lines; the chat wants one plain sentence per step.
308
+ for (const line of result.lines || []) {
309
+ const raw = typeof line === "string" ? line : (line.text || "");
310
+ const step = raw.match(/^OCQA_FLOW_STEP:(\{.*\})$/);
311
+ if (step) {
312
+ try {
313
+ const st = JSON.parse(step[1]);
314
+ 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();
315
+ progress({ phase: "replay", text: st.status === "pass" ? `${what}` : `Step ${st.index}: ${what} — ${st.detail || "failed"}` });
316
+ } catch { progress({ phase: "replay", text: raw }); }
317
+ continue;
318
+ }
319
+ if (/^OCQA_(FLOW_RESULT|ISSUE):/.test(raw)) continue;
320
+ if (raw) progress({ phase: "replay", text: raw });
321
+ }
322
+ const status = store.recordRun(slug, { passed: result.passed, captureId, executed: result.executed, total: result.total, failed: result.failed });
323
+ 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 } };
324
+ }
325
+
326
+ // "Make sure this always works": kept journeys on a public Studio are replayed on a schedule,
327
+ // each in its owner's lane so a check never queues ahead of the owner's own run. A journey is
328
+ // due when its last result is older than the interval (TAPP_JOURNEY_CHECK_HOURS, default 24);
329
+ // a restart therefore does not re-run everything, and a busy lane simply waits for the next tick.
330
+ export function dueJourneys(journeys, { intervalMs, now = Date.now() }) {
331
+ return journeys.filter((j) => (j.platform || "web") === "web" && (!j.status || now - Date.parse(j.status.at || 0) >= intervalMs));
332
+ }
333
+
262
334
  function openBrowser(url) {
263
335
  const invocation = process.platform === "darwin" ? ["open", [url]]
264
336
  : process.platform === "win32" ? ["cmd", ["/c", "start", "", url]]
@@ -587,6 +659,37 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
587
659
  return job;
588
660
  };
589
661
 
662
+ // Daily checks of every account's kept journeys (public Studio only; a local Studio is not
663
+ // always running, and its journeys are the repository's to guard in CI).
664
+ const checkIntervalMs = Math.max(1, Number(process.env.TAPP_JOURNEY_CHECK_HOURS) || 24) * 60 * 60 * 1000;
665
+ const runJourneyChecks = async () => {
666
+ if (!accounts) return;
667
+ const journeysRoot = path.join(accounts.root, "journeys");
668
+ let owners = [];
669
+ try { owners = fs.readdirSync(journeysRoot, { withFileTypes: true }).filter((d) => d.isDirectory() && /^[a-f0-9]{24}$/.test(d.name)).map((d) => d.name); } catch { return; }
670
+ for (const accountId of owners) {
671
+ const store = JourneyStore.forAccount(accountId);
672
+ const ownerKey = `acct:${accountId}`;
673
+ for (const journey of dueJourneys(store.list(), { intervalMs: checkIntervalMs })) {
674
+ const flowPath = store.flowPath(journey.slug);
675
+ let flow;
676
+ try { const { loadFlowFile } = await import("./flow-runtime.js"); flow = loadFlowFile(flowPath); } catch { continue; }
677
+ let job;
678
+ try {
679
+ job = startJob("check-journey", (progress) => replayJourney({ store, slug: journey.slug, flow, actorRoot: accounts.actorRoot(accountId), ownerKey, progress }), null, { lane: ownerKey });
680
+ } catch { continue; /* the owner is busy; next tick */ }
681
+ job.ownerKey = ownerKey;
682
+ // One at a time per owner: wait for this check before starting the next.
683
+ await new Promise((resolve) => { const tick = () => (job.status === "running" ? setTimeout(tick, 1000) : resolve()); tick(); });
684
+ logUsage("journey.checked", { owner: ownerKey.slice(0, 13), passed: job.result?.passed ?? null });
685
+ }
686
+ }
687
+ };
688
+ const checkTimer = publicAccess ? setInterval(() => { runJourneyChecks().catch(() => {}); }, 60 * 60 * 1000) : null;
689
+ if (checkTimer?.unref) checkTimer.unref();
690
+ const firstCheck = publicAccess ? setTimeout(() => { runJourneyChecks().catch(() => {}); }, 10 * 60 * 1000) : null;
691
+ if (firstCheck?.unref) firstCheck.unref();
692
+
590
693
  const server = http.createServer(async (request, response) => {
591
694
  const url = new URL(request.url || "/", origin || "http://127.0.0.1");
592
695
  const baseHeaders = {
@@ -1103,46 +1206,11 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
1103
1206
  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}` });
1104
1207
  return;
1105
1208
  }
1106
- // A journey that signs in does so as the test account tapp was told about for that
1107
- // site: the values come from the encrypted actor store at replay and never from the file.
1108
- const variables = {};
1109
- let storageStatePath = "";
1110
- if (flow.url && (flow.actor || (flow.steps || []).some((step) => step && typeof step === "object" && "login" in step))) {
1111
- const actors = new ActorStore(actorRootFor() ? { root: actorRootFor() } : {});
1112
- const record = actors.read(flow.url, flow.actor || "default");
1113
- if (record?.credentials?.email) variables.TEST_EMAIL = record.credentials.email;
1114
- if (record?.credentials?.password) variables.TEST_PASSWORD = record.credentials.password;
1115
- // A journey that began inside replays from the actor's saved session, like the run did.
1116
- if (flow.actor) storageStatePath = actors.sessionFile(flow.url, flow.actor) || "";
1117
- }
1118
- const captureId = `flow-web-${Date.now().toString(36)}-${crypto.randomBytes(4).toString("hex")}`;
1119
- const evidenceDir = path.join(captureRoot(), captureId);
1120
- fs.mkdirSync(evidenceDir, { recursive: true });
1209
+ const slug = root ? name : slugify(name);
1121
1210
  const job = startJob(operation, async (progress) => {
1122
- progress({ phase: "runtime", text: `Replaying ${flow.name || name}` });
1123
- const { runWebFlow } = await import("./web-flow.js");
1124
- let result;
1125
- try { result = await runWebFlow({ flow, variables, storageStatePath, logPath: path.join(evidenceDir, "flow.log"), screenshotDir: evidenceDir, recordVideoDir: evidenceDir }); }
1126
- finally { if (storageStatePath) { try { fs.rmSync(storageStatePath, { force: true }); } catch { /* temp */ } } }
1127
- // The runner's log is marker lines; the chat wants one plain sentence per step.
1128
- for (const line of result.lines || []) {
1129
- const raw = typeof line === "string" ? line : (line.text || "");
1130
- const step = raw.match(/^OCQA_FLOW_STEP:(\{.*\})$/);
1131
- if (step) {
1132
- try {
1133
- const s = JSON.parse(step[1]);
1134
- const what = s.action === "login" ? "Signed in" : s.action === "wait_for" ? `Reached ${s.target}` : s.action === "assert_screen" ? `On ${s.target}` : s.action === "tap" ? `Tapped "${s.target}"` : `${s.action} ${s.target || ""}`.trim();
1135
- progress({ phase: "replay", text: s.status === "pass" ? `${what}` : `Step ${s.index}: ${what} — ${s.detail || "failed"}` });
1136
- } catch { progress({ phase: "replay", text: raw }); }
1137
- continue;
1138
- }
1139
- if (/^OCQA_(FLOW_RESULT|ISSUE):/.test(raw)) continue;
1140
- if (raw) progress({ phase: "replay", text: raw });
1141
- }
1142
- const status = store.recordRun(root ? name : slugify(name), { passed: result.passed, captureId, executed: result.executed, total: result.total, failed: result.failed });
1143
- if (ownerKey) setCaptureOwner(captureId, ownerKey);
1211
+ const result = await replayJourney({ store, slug, flow, actorRoot: actorRootFor() || "", ownerKey, progress });
1144
1212
  logUsage("journey.run", { owner: (ownerKey || "operator").slice(0, 13), passed: result.passed });
1145
- return { kind: "journey", name: flow.name || name, slug: root ? name : slugify(name), passed: result.passed, executed: result.executed, total: result.total, failed: result.failed, status, capture: { id: captureId, path: evidenceDir } };
1213
+ return result;
1146
1214
  }, null, { lane: ownerKey || OPERATOR_LANE });
1147
1215
  job.ownerKey = ownerKey;
1148
1216
  json(response, 202, { job: publicJob(job, { hosted }) });
@@ -1327,6 +1395,8 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
1327
1395
  }
1328
1396
  await new Promise((resolve, reject) => server.close((error) => error ? reject(error) : resolve()));
1329
1397
  if (usageHeartbeat) clearInterval(usageHeartbeat);
1398
+ if (checkTimer) clearInterval(checkTimer);
1399
+ if (firstCheck) clearTimeout(firstCheck);
1330
1400
  if (egressProxy) { await egressProxy.close().catch(() => {}); restoreEgressEnv(); }
1331
1401
  registry.close();
1332
1402
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aarwitz/tapp",
3
- "version": "0.24.0",
3
+ "version": "0.24.2",
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",