@aarwitz/tapp 0.30.1 → 0.31.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.
@@ -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.30.1",
4
+ "version": "0.31.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.30.1",
27
+ "@aarwitz/tapp@0.31.0",
28
28
  "mcp"
29
29
  ],
30
30
  "cwd": "${CLAUDE_PROJECT_DIR}"
package/browser/app.js CHANGED
@@ -227,22 +227,62 @@ function renderAdmin() {
227
227
  }), { journeys: 0, failing: 0 });
228
228
  const stat = (value, label, tone = "") => `<div class="${esc(tone)}"><strong>${esc(String(value))}</strong><small>${esc(label)}</small></div>`;
229
229
  const owner = (email) => (data.admins || []).includes(String(email).toLowerCase());
230
+ const activity = data.activity || { today: {}, week: {}, recent: [], people: [] };
231
+ const count = (bucket, ...names) => names.reduce((sum, name) => sum + (bucket[name] || 0), 0);
232
+
233
+ // The log says what happened; these are the few verbs worth counting.
234
+ const period = (bucket) => [
235
+ stat(count(bucket, "signin.done"), "sign-ins"),
236
+ stat(count(bucket, "audit.start"), "audits"),
237
+ stat(count(bucket, "explore.start"), "explorations"),
238
+ stat(count(bucket, "journey.kept"), "journeys kept"),
239
+ stat(count(bucket, "journey.run", "journey.checked"), "journey runs"),
240
+ stat(count(bucket, "visitor.new"), "new visitors"),
241
+ ].join("");
242
+
243
+ const whatHappened = (entry) => {
244
+ const host = entry.host ? ` · ${esc(entry.host)}` : "";
245
+ const map = {
246
+ "visitor.new": "arrived", "signin.done": `signed in${entry.provider ? ` with ${esc(entry.provider)}` : ""}`,
247
+ "signin.link": "asked for a sign-in link", "signin.oauth.refused": `sign-in refused (${esc(entry.reason || "")})`,
248
+ "signin.access.refused": "sign-in refused", "audit.start": "started a read-only audit", "audit.done": "finished an audit",
249
+ "explore.start": "went inside a site", "journey.kept": "kept a journey", "journey.run": "ran a journey",
250
+ "journey.checked": "daily check", "journey.imported": "added a journey", "token.issued": "created an agent token",
251
+ "refused": `refused: ${esc(entry.reason || "")}`, "scanned": "automated probes refused", "rollup": "hourly rollup",
252
+ };
253
+ const what = map[entry.event] || esc(entry.event);
254
+ const extra = entry.event === "audit.done" ? ` — ${esc(String(entry.findings ?? "?"))} finding(s) over ${esc(String(entry.pagesAudited ?? "?"))} page(s)`
255
+ : entry.event === "journey.run" || entry.event === "journey.checked" ? ` — ${entry.passed ? "passed" : "FAILED"}` : "";
256
+ return `${what}${host}${extra}`;
257
+ };
258
+
230
259
  node.innerHTML = `
231
260
  <section class="panel section">
232
- <div class="section-heading compact"><div><p class="eyebrow">Right now</p><h2>How tapp is being used</h2><p>Since this release started. A visitor is counted only when they ask for something the Studio offers — scanners are not people.</p></div></div>
233
- <div class="run-stats">
234
- ${stat(data.accounts.length, "accounts")}
235
- ${stat(totals.journeys, "journeys")}
236
- ${stat(totals.failing, "failing", totals.failing ? "bad" : "")}
237
- ${stat(data.usage.distinctVisitors, "visitors")}
238
- ${stat(data.usage.audits, "audits")}
239
- ${stat(data.runs.captures, "runs kept")}
240
- </div>
241
- <p class="muted">Release <code>${esc(data.release)}</code> · up since ${esc(compactDate(data.startedAt))} · sign-in via <b>${esc(data.signInProvider)}</b> · kept journeys re-checked every ${esc(String(data.journeyCheckHours))}h · ${esc(String(data.usage.refusals))} refused requests, mostly automated probes.</p>
261
+ <div class="section-heading compact"><div><p class="eyebrow">Last 24 hours</p><h2>What happened today</h2></div></div>
262
+ <div class="run-stats">${period(activity.today)}</div>
263
+ <div class="section-heading compact" style="margin-top:14px"><div><p class="eyebrow">Last 7 days</p><h2>And this week</h2></div></div>
264
+ <div class="run-stats">${period(activity.week)}</div>
265
+ <p class="muted">Release <code>${esc(data.release)}</code> · up since ${esc(compactDate(data.startedAt))} · sign-in via <b>${esc(data.signInProvider)}</b> · kept journeys re-checked every ${esc(String(data.journeyCheckHours))}h · ${esc(String(data.totalRuns))} runs on disk · ${esc(String(activity.logged))} logged events${activity.since ? ` since ${esc(compactDate(activity.since))}` : ""}.</p>
266
+ </section>
267
+
268
+ <section class="panel section">
269
+ <div class="section-heading compact"><div><p class="eyebrow">People</p><h2>Who has been here <i class="zero">${activity.people.length}</i></h2><p>Signed-in accounts, and anonymous visitors by the first eight characters of their cookie — enough to tell two people apart, not enough to be a handle. No IP addresses are kept.</p></div></div>
270
+ ${activity.people.length ? activity.people.map((p) => `<div class="actor-row"><span><strong>${p.kind === "account" ? "account" : "visitor"} ${esc(p.id.split(":")[1])}</strong><br><small>first seen ${esc(compactDate(p.first))} · last ${esc(compactDate(p.last))}</small></span><span><small>${esc(Object.entries(p.events).map(([k, v]) => `${k.replace(/\./g, " ")} ×${v}`).join(" · ").slice(0, 90) || "—")}</small></span><span><small>${esc(p.hosts.join(", ") || "—")}</small></span></div>`).join("") : '<div class="empty">Nobody yet. Activity is recorded from the release that introduced this log.</div>'}
242
271
  </section>
272
+
243
273
  <section class="panel section">
244
- <div class="section-heading compact"><div><p class="eyebrow">People</p><h2>Accounts <i class="zero">${data.accounts.length}</i></h2><p>What each person has set up. Test accounts are counted, never shown — tapp cannot show them.</p></div></div>
274
+ <div class="section-heading compact"><div><p class="eyebrow">Accounts</p><h2>People with a tapp account <i class="zero">${data.accounts.length}</i></h2><p>Test accounts are counted, never shown — tapp cannot show them.</p></div></div>
245
275
  ${data.accounts.length ? data.accounts.map((account) => `<div class="actor-row"><span><strong>${esc(account.email)}</strong>${owner(account.email) ? ' <small class="journey-status passing">owner</small>' : ""}<br><small>joined ${esc(compactDate(account.createdAt))}${account.lastSeenAt ? ` · last seen ${esc(compactDate(account.lastSeenAt))}` : ""}</small></span><span><small>${account.journeys} journey${account.journeys === 1 ? "" : "s"}${account.failing ? ` · <b class="journey-status failing">${account.failing} failing</b>` : ""}${account.neverRun ? ` · ${account.neverRun} never run` : ""}</small></span><span><small>${account.testAccounts} test account${account.testAccounts === 1 ? "" : "s"} · ${account.tokens} token${account.tokens === 1 ? "" : "s"}</small></span></div>`).join("") : '<div class="empty">Nobody has signed in yet.</div>'}
276
+ </section>
277
+
278
+ <section class="panel section">
279
+ <div class="section-heading compact"><div><p class="eyebrow">Runs</p><h2>Every run still on disk <i class="zero">${data.totalRuns}</i></h2><p>Newest first. Evidence belongs to whoever started the run; this is the ledger, not their screenshots.</p></div></div>
280
+ ${(data.recentRuns || []).length ? (data.recentRuns).map((run) => `<div class="actor-row"><span><strong>${esc(run.kind)}</strong> · ${esc(run.target || "—")}<br><small><code>${esc(run.id)}</code></small></span><span><small>${run.at ? esc(compactDate(run.at)) : "—"}</small></span><span><small>${esc(String(run.owner).slice(0, 20))}</small></span></div>`).join("") : '<div class="empty">No runs yet.</div>'}
281
+ </section>
282
+
283
+ <section class="panel section">
284
+ <div class="section-heading compact"><div><p class="eyebrow">Log</p><h2>Recent activity</h2><p>The last ${(activity.recent || []).length} things that happened, newest first.</p></div></div>
285
+ ${(activity.recent || []).length ? `<ul class="detail-list">${activity.recent.map((entry) => `<li><small>${esc(compactDate(entry.at))}</small> · ${entry.account ? `account ${esc(entry.account)}` : entry.visitor ? `visitor ${esc(entry.visitor)}` : "—"} · ${whatHappened(entry)}</li>`).join("")}</ul>` : '<div class="empty">Nothing logged yet on this release.</div>'}
246
286
  </section>`;
247
287
  }
248
288
 
@@ -618,11 +618,29 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
618
618
  // durable handle for one. Off unless the Studio is public; a local Studio logging its owner's
619
619
  // own use is noise.
620
620
  const usage = { visitors: new Set(), audits: 0, refusals: 0, startedAt: new Date().toISOString() };
621
+ // The same line goes to stdout (systemd keeps it) and to a file the Studio can read back, so
622
+ // the owner's page can answer "what has been happening?" after a restart — the in-memory
623
+ // counters start again at zero every deploy, which made them nearly useless for that question.
624
+ // Same discipline either way: no IP address, no full URL, no credential, and only the first
625
+ // eight characters of a visitor id — enough to tell two people apart in a day, not a handle.
626
+ const usageLogPath = path.join(process.env.TAPP_HOME || path.join(os.homedir(), ".tapp"), "usage.jsonl");
627
+ const USAGE_LOG_MAX_BYTES = 2_000_000;
621
628
  const logUsage = (event, fields = {}) => {
622
629
  if (!publicAccess) return;
630
+ const line = JSON.stringify({ at: new Date().toISOString(), event, ...fields });
631
+ try { console.log(`tapp-usage ${line}`); } catch { /* logging must never break a run */ }
623
632
  try {
624
- console.log(`tapp-usage ${JSON.stringify({ at: new Date().toISOString(), event, ...fields })}`);
625
- } catch { /* logging must never break a run */ }
633
+ fs.appendFileSync(usageLogPath, `${line}\n`, { mode: 0o600 });
634
+ // Keep the tail rather than growing without limit; this is a record of activity, not an archive.
635
+ if (fs.statSync(usageLogPath).size > USAGE_LOG_MAX_BYTES) {
636
+ const kept = fs.readFileSync(usageLogPath, "utf8").split("\n").filter(Boolean).slice(-4000);
637
+ fs.writeFileSync(usageLogPath, `${kept.join("\n")}\n`, { mode: 0o600 });
638
+ }
639
+ } catch { /* a full disk must not fail a run either */ }
640
+ };
641
+ const readUsageLog = (limit = 4000) => {
642
+ try { return fs.readFileSync(usageLogPath, "utf8").split("\n").filter(Boolean).slice(-limit).map((line) => { try { return JSON.parse(line); } catch { return null; } }).filter(Boolean); }
643
+ catch { return []; }
626
644
  };
627
645
  // Where a visitor pointed us, without what they may have put in the query string.
628
646
  const safeHost = (value) => { try { return new URL(value).host; } catch { return "unparsed"; } };
@@ -1107,6 +1125,42 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
1107
1125
  }
1108
1126
  } catch { /* none yet */ }
1109
1127
  const owners = listAccounts();
1128
+
1129
+ // What has actually happened here, from the durable log. The in-memory counters only
1130
+ // cover the current process; this survives a deploy.
1131
+ const events = readUsageLog();
1132
+ const since = (hours) => Date.now() - hours * 3600_000;
1133
+ const within = (hours) => events.filter((e) => Date.parse(e.at) >= since(hours));
1134
+ const tally = (list) => list.reduce((counts, e) => ({ ...counts, [e.event]: (counts[e.event] || 0) + 1 }), {});
1135
+
1136
+ // "Three visitors" is not an answer. Who were they, when, and what did they do?
1137
+ const people = new Map();
1138
+ for (const entry of events) {
1139
+ const id = entry.account ? `account:${entry.account}` : entry.visitor ? `visitor:${entry.visitor}` : null;
1140
+ if (!id) continue;
1141
+ const seen = people.get(id) || { id, kind: entry.account ? "account" : "visitor", first: entry.at, last: entry.at, events: {}, hosts: [] };
1142
+ seen.last = entry.at;
1143
+ if (entry.at < seen.first) seen.first = entry.at;
1144
+ seen.events[entry.event] = (seen.events[entry.event] || 0) + 1;
1145
+ if (entry.host && !seen.hosts.includes(entry.host) && seen.hosts.length < 8) seen.hosts.push(entry.host);
1146
+ people.set(id, seen);
1147
+ }
1148
+
1149
+ // Every run still on disk, which predates the log and outlives it.
1150
+ const runs = [];
1151
+ try {
1152
+ for (const name of fs.readdirSync(captureRoot())) {
1153
+ const dir = path.join(captureRoot(), name);
1154
+ const provenance = readCaptureProvenance(dir);
1155
+ if (!provenance) continue;
1156
+ let target = provenance.target || "";
1157
+ try { target = new URL(target).host; } catch { /* a bundle id or a path */ }
1158
+ runs.push({ id: name, kind: provenance.kind || (name.startsWith("web-audit-") ? "audit" : name.startsWith("flow-") ? "journey" : "explore"),
1159
+ target: String(target).slice(0, 60), at: provenance.createdAt || null, owner: captureOwner(name) || "operator" });
1160
+ }
1161
+ } catch { /* none yet */ }
1162
+ runs.sort((a, b) => String(b.at || "").localeCompare(String(a.at || "")));
1163
+
1110
1164
  json(response, 200, {
1111
1165
  release: process.env.TAPP_RELEASE || "dev",
1112
1166
  startedAt: serverStartedAt,
@@ -1116,6 +1170,16 @@ export async function startBrowserProduct({ projectDir, port = 0, launch = false
1116
1170
  accounts: owners,
1117
1171
  journeyCheckHours: Math.max(1, Number(process.env.TAPP_JOURNEY_CHECK_HOURS) || 24),
1118
1172
  admins: [...adminEmails],
1173
+ activity: {
1174
+ logged: events.length,
1175
+ since: events[0]?.at || null,
1176
+ today: tally(within(24)),
1177
+ week: tally(within(24 * 7)),
1178
+ recent: events.slice(-60).reverse(),
1179
+ people: [...people.values()].sort((a, b) => String(b.last).localeCompare(String(a.last))).slice(0, 50),
1180
+ },
1181
+ recentRuns: runs.slice(0, 40),
1182
+ totalRuns: runs.length,
1119
1183
  });
1120
1184
  return;
1121
1185
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aarwitz/tapp",
3
- "version": "0.30.1",
3
+ "version": "0.31.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",