genclass 0.1.0 → 0.2.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/dist/genclass.mjs CHANGED
@@ -12,7 +12,7 @@ var __export = (target, all) => {
12
12
  var define_GENCLASS_BUILD_default;
13
13
  var init_define_GENCLASS_BUILD = __esm({
14
14
  "<define:__GENCLASS_BUILD__>"() {
15
- define_GENCLASS_BUILD_default = { version: "0.1.0", runtimeVersion: "0.3.0-beta.6", mcpVersion: "0.2.2", workflow: `# GenClass on your existing Playwright suite: no change to your tests or your playwright.config.
15
+ define_GENCLASS_BUILD_default = { version: "0.2.0", runtimeVersion: "0.3.0-beta.6", mcpVersion: "0.2.2", workflow: `# GenClass on your existing Playwright suite: no change to your tests or your playwright.config.
16
16
  # Copy to .github/workflows/genclass.yml.
17
17
  #
18
18
  # Assumes "npx playwright test" works on a fresh checkout with dependencies installed, which usually
@@ -134,20 +134,20 @@ function diffLines(a, b) {
134
134
  const a2 = A.slice(pre, A.length - suf);
135
135
  const b2 = B.slice(pre, B.length - suf);
136
136
  const ops = A.slice(0, pre).map((l) => [" ", l]);
137
- const n = a2.length;
137
+ const n2 = a2.length;
138
138
  const m = b2.length;
139
- if (n * m > 4e6) {
139
+ if (n2 * m > 4e6) {
140
140
  for (const l of a2) ops.push(["-", l]);
141
141
  for (const l of b2) ops.push(["+", l]);
142
142
  } else {
143
143
  const w = m + 1;
144
- const dp = new Uint32Array((n + 1) * w);
145
- for (let i2 = n - 1; i2 >= 0; i2--) {
144
+ const dp = new Uint32Array((n2 + 1) * w);
145
+ for (let i2 = n2 - 1; i2 >= 0; i2--) {
146
146
  for (let j2 = m - 1; j2 >= 0; j2--) dp[i2 * w + j2] = a2[i2] === b2[j2] ? dp[(i2 + 1) * w + j2 + 1] + 1 : Math.max(dp[(i2 + 1) * w + j2], dp[i2 * w + j2 + 1]);
147
147
  }
148
148
  let i = 0;
149
149
  let j = 0;
150
- while (i < n && j < m) {
150
+ while (i < n2 && j < m) {
151
151
  if (a2[i] === b2[j]) {
152
152
  ops.push([" ", a2[i]]);
153
153
  i++;
@@ -155,7 +155,7 @@ function diffLines(a, b) {
155
155
  } else if (dp[(i + 1) * w + j] >= dp[i * w + j + 1]) ops.push(["-", a2[i++]]);
156
156
  else ops.push(["+", b2[j++]]);
157
157
  }
158
- while (i < n) ops.push(["-", a2[i++]]);
158
+ while (i < n2) ops.push(["-", a2[i++]]);
159
159
  while (j < m) ops.push(["+", b2[j++]]);
160
160
  }
161
161
  for (const l of A.slice(A.length - suf)) ops.push([" ", l]);
@@ -203,6 +203,7 @@ function printChange(change) {
203
203
  }
204
204
  async function ask(question) {
205
205
  if (!interactive()) return null;
206
+ await lastClosed;
206
207
  if (typedAhead.length) {
207
208
  const a = typedAhead.shift();
208
209
  process.stdout.write(`${question}${a}
@@ -218,6 +219,8 @@ async function ask(question) {
218
219
  const rl = createInterface({ input: process.stdin, output: process.stdout });
219
220
  let answered = false;
220
221
  let closing2 = false;
222
+ let closed;
223
+ lastClosed = new Promise((done) => closed = done);
221
224
  rl.on("line", (line) => typedAhead.push(line));
222
225
  rl.question(question, (line) => {
223
226
  if (!process.stdout.isTTY) process.stdout.write(`${line}
@@ -241,6 +244,7 @@ async function ask(question) {
241
244
  if (!process.stdout.isTTY) process.stdout.write("\n");
242
245
  resolve7("");
243
246
  }
247
+ closed();
244
248
  });
245
249
  });
246
250
  }
@@ -260,13 +264,13 @@ async function choose(question, labels, def = 0) {
260
264
  const a = await ask(` ${c.bold("Number")} ${c.gray(`(1-${labels.length}, Enter for ${def + 1})`)} `);
261
265
  if (a === null) return null;
262
266
  if (a === "") return def;
263
- const n = Number(a);
264
- if (Number.isInteger(n) && n >= 1 && n <= labels.length) return n - 1;
267
+ const n2 = Number(a);
268
+ if (Number.isInteger(n2) && n2 >= 1 && n2 <= labels.length) return n2 - 1;
265
269
  out(` ${c.yellow(sym.warn)} Type a number from 1 to ${labels.length}.`);
266
270
  }
267
271
  return null;
268
272
  }
269
- var env, tty, useColor, unicode, wrap, c, sym, out, err, splitLines, interactive, typedAhead, inputEnded, inputClosed;
273
+ var env, tty, useColor, unicode, wrap, c, sym, out, err, splitLines, interactive, typedAhead, inputEnded, inputClosed, lastClosed;
270
274
  var init_ui = __esm({
271
275
  "../runtime/bin/lib/ui.mjs"() {
272
276
  "use strict";
@@ -304,6 +308,7 @@ var init_ui = __esm({
304
308
  typedAhead = [];
305
309
  inputEnded = false;
306
310
  inputClosed = () => inputEnded;
311
+ lastClosed = Promise.resolve();
307
312
  }
308
313
  });
309
314
 
@@ -736,7 +741,7 @@ function detectProject(cwd) {
736
741
  const dir = resolve(cwd);
737
742
  const pkg = readJson(join3(dir, "package.json"));
738
743
  const deps = { ...pkg?.peerDependencies ?? {}, ...pkg?.devDependencies ?? {}, ...pkg?.dependencies ?? {} };
739
- const has = (n) => Object.prototype.hasOwnProperty.call(deps, n);
744
+ const has = (n2) => Object.prototype.hasOwnProperty.call(deps, n2);
740
745
  const ts = isFile(join3(dir, "tsconfig.json")) || has("typescript");
741
746
  const pm = pkg ? detectPackageManager(dir, pkg) : null;
742
747
  const p = { dir, pkg, deps, has, pm, ts, name: pkg?.name || dir.split(sep).pop(), framework: null, label: "", details: {} };
@@ -767,10 +772,10 @@ function detectProject(cwd) {
767
772
  }
768
773
  if (has("react-scripts")) return { ...p, framework: "cra", label: "Create React App" };
769
774
  if (has("vite") || firstFile(dir, withExts("vite.config", ["ts", "js", "mts", "mjs", "cts", "cjs"]))) {
770
- const flavor = VITE_FLAVORS.find(([n]) => has(n))?.[1] ?? "vanilla";
775
+ const flavor = VITE_FLAVORS.find(([n2]) => has(n2))?.[1] ?? "vanilla";
771
776
  return { ...p, framework: "vite", label: `Vite + ${flavor}`, details: { flavor } };
772
777
  }
773
- const bundler = ["webpack", "@rspack/core", "@rsbuild/core", "parcel", "esbuild", "rollup"].find((n) => has(n));
778
+ const bundler = ["webpack", "@rspack/core", "@rsbuild/core", "parcel", "esbuild", "rollup"].find((n2) => has(n2));
774
779
  if (bundler) {
775
780
  const lib = libraryEvidence(pkg);
776
781
  if (lib) {
@@ -790,7 +795,7 @@ function detectProject(cwd) {
790
795
  return p;
791
796
  }
792
797
  function libraryEvidence(pkg) {
793
- const peer = UI_PEERS.find((n) => Object.prototype.hasOwnProperty.call(pkg?.peerDependencies ?? {}, n));
798
+ const peer = UI_PEERS.find((n2) => Object.prototype.hasOwnProperty.call(pkg?.peerDependencies ?? {}, n2));
794
799
  if (peer) return `${peer} is a peer dependency`;
795
800
  const field = ["exports", "module", "types", "typings", "bin"].find((f) => pkg?.[f] !== void 0);
796
801
  return field ? `package.json has a "${field}" field` : null;
@@ -798,7 +803,7 @@ function libraryEvidence(pkg) {
798
803
  function browserEvidence(dir, pkg) {
799
804
  for (const f of ["index.html", "src/index.html", "public/index.html"]) if (isFile(join3(dir, f))) return f;
800
805
  const own = { ...pkg?.devDependencies ?? {}, ...pkg?.dependencies ?? {} };
801
- const dep = BROWSER_DEPS.find((n) => Object.prototype.hasOwnProperty.call(own, n));
806
+ const dep = BROWSER_DEPS.find((n2) => Object.prototype.hasOwnProperty.call(own, n2));
802
807
  if (dep) return dep;
803
808
  const sources = [pkg?.source].flat().filter((x) => typeof x === "string");
804
809
  if (sources.some((x) => /\.html?$/i.test(x))) return "package.json source (HTML)";
@@ -808,11 +813,11 @@ function browserEvidence(dir, pkg) {
808
813
  function htmlFiles(dir) {
809
814
  let names = [];
810
815
  try {
811
- names = readdirSync(dir).filter((n) => /\.html?$/i.test(n)).sort();
816
+ names = readdirSync(dir).filter((n2) => /\.html?$/i.test(n2)).sort();
812
817
  } catch {
813
818
  return [];
814
819
  }
815
- return names.map((n) => join3(dir, n)).filter((f) => /<head[\s>]/i.test(readText(f) ?? ""));
820
+ return names.map((n2) => join3(dir, n2)).filter((f) => /<head[\s>]/i.test(readText(f) ?? ""));
816
821
  }
817
822
  function detectState(project, files) {
818
823
  const found = { redux: null, zustand: null, useState: 0, useStateFiles: 0, others: [] };
@@ -825,9 +830,9 @@ function detectState(project, files) {
825
830
  else if (/\b(?:legacy_)?createStore\s*\(/.test(t)) found.redux = { file: rel(f), kind: "createStore" };
826
831
  }
827
832
  if (!found.zustand && /from\s+['"]zustand(?:\/[a-z]+)?['"]/.test(t) && /\bcreate(?:Store)?\s*(?:<[^>]*>)?\s*\(/.test(t)) found.zustand = { file: rel(f) };
828
- const n = (t.match(/\buseState\s*(?:<[^>]*>)?\s*\(/g) ?? []).length;
829
- if (n) {
830
- found.useState += n;
833
+ const n2 = (t.match(/\buseState\s*(?:<[^>]*>)?\s*\(/g) ?? []).length;
834
+ if (n2) {
835
+ found.useState += n2;
831
836
  found.useStateFiles++;
832
837
  }
833
838
  }
@@ -1338,13 +1343,13 @@ function switchMetaConfig(text, cfg) {
1338
1343
  const metaAt = lines.findIndex((l) => l.includes(MARK) && /<meta\s+name=["']genclass["']/i.test(l));
1339
1344
  if (metaAt >= 0) {
1340
1345
  const cur = /content=["']([^"']*)["']/i.exec(lines[metaAt])?.[1] ?? "";
1341
- const pairs = Object.fromEntries(cur.split(/[,;]\s*/).filter(Boolean).map((p) => [p.split("=")[0].trim(), p.slice(p.indexOf("=") + 1).trim()]));
1342
- if (cfg.token) pairs.token = cfg.token;
1343
- if (cfg.telemetry === false) pairs.telemetry = "off";
1344
- if (cfg.telemetry === true) delete pairs.telemetry;
1345
- if (cfg.model) Object.assign(pairs, { model: cfg.model.baseUrl, ort: cfg.model.ortWasmPaths, ...cfg.model.device ? { device: cfg.model.device } : {} });
1346
- if (cfg.sinks?.length) pairs.sink = cfg.sinks.join("+");
1347
- const content2 = Object.entries(pairs).map(([k, v]) => `${k}=${v}`).join(", ");
1346
+ const pairs2 = Object.fromEntries(cur.split(/[,;]\s*/).filter(Boolean).map((p) => [p.split("=")[0].trim(), p.slice(p.indexOf("=") + 1).trim()]));
1347
+ if (cfg.token) pairs2.token = cfg.token;
1348
+ if (cfg.telemetry === false) pairs2.telemetry = "off";
1349
+ if (cfg.telemetry === true) delete pairs2.telemetry;
1350
+ if (cfg.model) Object.assign(pairs2, { model: cfg.model.baseUrl, ort: cfg.model.ortWasmPaths, ...cfg.model.device ? { device: cfg.model.device } : {} });
1351
+ if (cfg.sinks?.length) pairs2.sink = cfg.sinks.join("+");
1352
+ const content2 = Object.entries(pairs2).map(([k, v]) => `${k}=${v}`).join(", ");
1348
1353
  if (!content2) {
1349
1354
  lines[metaAt] = "";
1350
1355
  return lines.join("");
@@ -2367,7 +2372,7 @@ async function offerAccount(o, tk) {
2367
2372
  if (!tk.pending && !tk.wouldCreate) return tk;
2368
2373
  const creds = readCredentials();
2369
2374
  if (!creds) return tk;
2370
- if (tk.wouldCreate || o.yes || !interactive()) return { ...tk, account: creds };
2375
+ if (tk.wouldCreate || o.yes || o.inAccount || !interactive()) return { ...tk, account: creds };
2371
2376
  const ok = await confirm(`Signed in as ${accountLabel(creds.account)}: create this app in your GenClass account?`);
2372
2377
  if (ok === false) {
2373
2378
  out(` ${c.gray("Not in your account: init creates the app with a private dashboard link instead, as without an account.")}`);
@@ -2491,7 +2496,7 @@ async function init(o, ctx = {}) {
2491
2496
  for (const ch of plan.changes) printChange({ ...ch, file: ch.rel });
2492
2497
  if (install) out(` ${c.bold("Install")} ${c.cyan(installArgs(project.pm, spec).flat().join(" "))}`);
2493
2498
  else if (needsPackage) out(` ${c.yellow(sym.warn)} --no-install: ${older ? `upgrade ${PKG} yourself (${installArgs(project.pm, spec).flat().join(" ")})` : `add ${PKG} to your dependencies yourself`}.`);
2494
- for (const n of plan.notes ?? []) out(` ${c.yellow(sym.warn)} ${n}`);
2499
+ for (const n2 of plan.notes ?? []) out(` ${c.yellow(sym.warn)} ${n2}`);
2495
2500
  out();
2496
2501
  const recs = recommendations(project, detectState(project, files));
2497
2502
  const money = moneyFlows(project, files);
@@ -2717,7 +2722,7 @@ remove takes out exactly what init added (the lines and blocks marked "${MARK}
2717
2722
  package.json's name), writes it into what it adds, and saves the token and your
2718
2723
  private dashboard link in ${LOCAL_FILE} (the dashboard is free; visitor analytics
2719
2724
  come with the Team plan; \`dashboard\` prints the link again). Signed in (\`login\`), init first asks
2720
- whether the new app goes into your GenClass account instead (--yes: it does)
2725
+ whether the new app goes into your GenClass account instead (--yes or --in-account: it does)
2721
2726
  --no-token no token, no network (no dashboard; you can add one later: ${START_URL})
2722
2727
  --no-telemetry turn off GenClass's anonymous diagnostics (on by default; see TELEMETRY.md and
2723
2728
  PRIVACY.md). Written as an option file (genclass.config.ts/js, imported right before
@@ -2764,6 +2769,7 @@ remove takes out exactly what init added (the lines and blocks marked "${MARK}
2764
2769
  "no-telemetry": "noTelemetry",
2765
2770
  telemetry: "telemetry",
2766
2771
  "no-token": "noToken",
2772
+ "in-account": "inAccount",
2767
2773
  help: "help",
2768
2774
  h: "help"
2769
2775
  };
@@ -2956,27 +2962,27 @@ async function connectApp(o, creds, st, me) {
2956
2962
  out();
2957
2963
  }
2958
2964
  const createName = String(o.name || pkgName).slice(0, 80);
2959
- let pick2;
2965
+ let pick;
2960
2966
  if (o.app) {
2961
- pick2 = apps.findIndex((a) => a.id === o.app || a.name === o.app);
2962
- if (pick2 < 0) {
2967
+ pick = apps.findIndex((a) => a.id === o.app || a.name === o.app);
2968
+ if (pick < 0) {
2963
2969
  err(` ${c.red(sym.cross)} No app "${o.app}" in your account.${apps.length ? ` Your apps: ${apps.map((a) => `${a.name} (${a.id})`).join(", ")}.` : " It has no apps yet."}`);
2964
2970
  out();
2965
2971
  return 1;
2966
2972
  }
2967
- } else if (o.name) pick2 = apps.length;
2973
+ } else if (o.name) pick = apps.length;
2968
2974
  else {
2969
2975
  const same = apps.findIndex((a) => a.name === pkgName);
2970
2976
  const def = same >= 0 ? same : apps.length;
2971
- pick2 = def;
2977
+ pick = def;
2972
2978
  if (apps.length && !o.yes && interactive()) {
2973
2979
  const labels = [...apps.map((a) => `${a.name} ${c.gray(`${a.token} ${a.last_event ? `last event ${when(a.last_event)}` : "no events yet"}`)}`), `Create a new app named ${c.bold(createName)}`];
2974
2980
  const got = await choose(`Which app of your account is this (${pkgName})?`, labels, def);
2975
- if (got !== null) pick2 = got;
2981
+ if (got !== null) pick = got;
2976
2982
  out();
2977
2983
  }
2978
2984
  }
2979
- const app = pick2 < apps.length ? apps[pick2] : null;
2985
+ const app = pick < apps.length ? apps[pick] : null;
2980
2986
  if (st.token && st.token !== app?.token) {
2981
2987
  out(` ${c.yellow(sym.warn)} This replaces the project key ${st.token} in your setup.`);
2982
2988
  if (st.local?.dashboardUrl && st.local.token === st.token)
@@ -3168,7 +3174,7 @@ async function whoami() {
3168
3174
  }
3169
3175
  function showDashboard(o, link, notes = []) {
3170
3176
  out(` ${c.bold("Your dashboard")} ${c.bold(c.cyan(link))}`);
3171
- for (const n of notes) out(` ${n}`);
3177
+ for (const n2 of notes) out(` ${n2}`);
3172
3178
  for (const l of FREE_LINES) out(` ${c.gray(l)}`);
3173
3179
  if (o.open && openBrowser(link, o)) out(` ${c.gray("Opening it in your browser.")}`);
3174
3180
  out();
@@ -3390,9 +3396,9 @@ function parseArgs(argv) {
3390
3396
  else if (a === "--hosted") o.hosted = true;
3391
3397
  else if (a === "--local") o.local = true;
3392
3398
  else if (key === "--timeout") {
3393
- const n = Number(value());
3394
- if (!Number.isFinite(n) || n <= 0 || n > 600) throw new UsageError2("--timeout must be a number of seconds between 1 and 600");
3395
- o.timeout = n;
3399
+ const n2 = Number(value());
3400
+ if (!Number.isFinite(n2) || n2 <= 0 || n2 > 600) throw new UsageError2("--timeout must be a number of seconds between 1 and 600");
3401
+ o.timeout = n2;
3396
3402
  } else if (key === "--cwd") o.cwd = resolve4(value());
3397
3403
  else if (a.startsWith("-")) throw new UsageError2(`unknown option ${a}`);
3398
3404
  else if (o.url === null) o.url = a;
@@ -3775,10 +3781,10 @@ function formatReport(rep) {
3775
3781
  else p(c.gray(` ran remotely on the genclass.dev page check (${sizes || "desktop and phone"}): the page was loaded by its browser, not this computer`));
3776
3782
  for (const v of rep.views) if (v.error) p(` ${c.yellow(sym.warn)} ${v.id}: ${v.error}`);
3777
3783
  p();
3778
- const n = rep.findings.length;
3784
+ const n2 = rep.findings.length;
3779
3785
  const counts = SEVERITIES.filter((s) => rep.summary[s]).map((s) => `${rep.summary[s]} ${s}`).join(", ");
3780
3786
  const score = rep.score.value === null ? "no score" : `${rep.ranAt === "local" ? "Visual score" : "Score"} ${c.bold(`${rep.score.value}/100`)}`;
3781
- p(` ${score} ${c.gray(sym.dot)} ${n === 0 ? c.green(`${sym.ok} no problems found`) : `${n} problem${n === 1 ? "" : "s"} (${counts})`}`);
3787
+ p(` ${score} ${c.gray(sym.dot)} ${n2 === 0 ? c.green(`${sym.ok} no problems found`) : `${n2} problem${n2 === 1 ? "" : "s"} (${counts})`}`);
3782
3788
  if (rep.blocked) p(` ${c.yellow(sym.warn)} ${rep.blocked}`);
3783
3789
  if (rep.categories?.length) {
3784
3790
  p();
@@ -4015,7 +4021,37 @@ async function requestPlan(creds, digest, opts = {}) {
4015
4021
  limited: j.limited === true
4016
4022
  };
4017
4023
  }
4018
- var str, sameOrigin2;
4024
+ async function fetchApp(creds, id, range = "7d", opts = {}) {
4025
+ const r = await request(`/api/cli/app?id=${encodeURIComponent(id)}&range=${encodeURIComponent(range)}`, { token: creds.access_token, host: creds.host, fetchFn: opts.fetchFn });
4026
+ if (!r.ok) return { ok: false, status: r.status, reason: failure(r), ...r.status === 404 ? { missing: true } : {}, ...r.json?.reauth === true ? { reauth: true } : {}, ...r.json?.locked === true ? { locked: true, upgradeUrl: sameOrigin2(r.json.upgrade_url, creds.host) } : {} };
4027
+ const j = r.json ?? {};
4028
+ const t = j.totals && typeof j.totals === "object" ? j.totals : {};
4029
+ const b = j.breakdowns && typeof j.breakdowns === "object" ? j.breakdowns : {};
4030
+ const st = j.agent?.stages && typeof j.agent.stages === "object" ? j.agent.stages : {};
4031
+ const v = j.visits && typeof j.visits === "object" ? j.visits : {};
4032
+ const lock = j.locked?.analytics && typeof j.locked.analytics === "object" ? j.locked.analytics : null;
4033
+ return {
4034
+ ok: true,
4035
+ name: str(j.name, 80) ?? "",
4036
+ range: str(j.range, 8) ?? range,
4037
+ lastEvent: str(j.lastEvent, 40),
4038
+ totals: { visits: count(t.sessions), found: count(t.detections), handled: count(t.acted), possible: count(t.possible), checks: count(t.checks), pageViews: count(t.ix_views) },
4039
+ previous: { found: count(j.previous?.detections), visits: count(j.previous?.sessions) },
4040
+ /** problems found per bucket (hour or day), oldest first */
4041
+ series: (Array.isArray(j.series) ? j.series : []).slice(-400).map((x) => count(x?.detections)),
4042
+ /** kind TAB page */
4043
+ problems: pairs(b.detect_issue, 200),
4044
+ possible: pairs(b.possible_issue, 200),
4045
+ checks: pairs(b.check_issue, 200),
4046
+ kinds: pairs(b.detect_diagnosis, 25),
4047
+ recent: (Array.isArray(j.recent) ? j.recent : []).filter((x) => x && typeof x === "object").slice(0, 20).map((x) => ({ at: str(x.t, 40), kind: str(x.diagnosis, 60), route: str(x.route, 200), handled: x.acted === 1 || x.acted === true })),
4048
+ visitors: lock ? null : { visits: count(v.sessions), pages: count(v.pages), bounces: count(v.bounces), entry: pairs(v.entry, 25) },
4049
+ visitorsPlan: lock ? { plan: str(lock.plan, 40), upgradeUrl: sameOrigin2(lock.upgrade_url, creds.host) } : null,
4050
+ agent: { found: count(st.found), reproduced: count(st.reproduced), fixed: count(st.fixed), closed: count(st.closed), open: count(st.open), last: str(j.agent?.last, 40) },
4051
+ dashboardUrl: sameOrigin2(j.dashboard_url, creds.host)
4052
+ };
4053
+ }
4054
+ var str, sameOrigin2, count, pairs;
4019
4055
  var init_api = __esm({
4020
4056
  "src/api.mjs"() {
4021
4057
  init_define_GENCLASS_BUILD();
@@ -4028,6 +4064,8 @@ var init_api = __esm({
4028
4064
  return null;
4029
4065
  }
4030
4066
  };
4067
+ count = (v) => Number.isFinite(Number(v)) ? Math.max(0, Math.round(Number(v))) : 0;
4068
+ pairs = (list, max) => (Array.isArray(list) ? list : []).filter((x) => x && typeof x === "object" && typeof x.key === "string").slice(0, max).map((x) => ({ key: x.key.slice(0, 300), count: count(x.count) }));
4031
4069
  }
4032
4070
  });
4033
4071
 
@@ -4105,6 +4143,20 @@ function checklist(steps) {
4105
4143
  out(` ${(MARK2[s.state] ?? MARK2.todo)()} ${title}${detail ? c.gray(detail) : ""}`);
4106
4144
  }
4107
4145
  }
4146
+ function summary(steps) {
4147
+ const room = width() - 4 - 3 - 9;
4148
+ const names = (list) => clean(list.map((s) => s.title).join(` ${sym.dot} `), room);
4149
+ const line = (mark2, label, text) => out(` ${mark2} ${label}${text}`);
4150
+ const pad = (label) => label.padEnd(9);
4151
+ const done = steps.filter((s) => s.state === "done");
4152
+ const next = steps.find((s) => s.state === "next");
4153
+ const later = steps.filter((s) => s.state === "todo");
4154
+ if (done.length) line(MARK2.done(), pad("Done"), c.gray(names(done)));
4155
+ for (const b of steps.filter((s) => s.state === "blocked")) line(MARK2.blocked(), pad(b.title), c.gray(clean(b.detail ?? "", room)));
4156
+ if (next) line(MARK2.next(), c.bold(pad("Next")), c.bold(clean(next.doing ?? next.title, room)));
4157
+ for (const w of steps.filter((s) => s.state === "waiting")) line(MARK2.waiting(), pad("Waiting"), c.gray(clean(`${w.title}: ${w.detail ?? ""}`, room)));
4158
+ if (later.length) line(MARK2.todo(), c.gray(pad("Later")), c.gray(names(later)));
4159
+ }
4108
4160
  function nextBlock(title, text) {
4109
4161
  out();
4110
4162
  out(` ${c.cyan(c.bold("Next"))} ${c.bold(title)}`);
@@ -4114,10 +4166,6 @@ async function agree(question, def = true) {
4114
4166
  const a = await confirm(question, def);
4115
4167
  return inputClosed() ? false : a;
4116
4168
  }
4117
- async function pick(question, labels, def = 0) {
4118
- const i = await choose(question, labels, def);
4119
- return inputClosed() ? null : i;
4120
- }
4121
4169
  async function typed(question) {
4122
4170
  const a = await ask(question);
4123
4171
  return a === null || a === "" && inputClosed() ? null : a;
@@ -4159,9 +4207,9 @@ function ago(iso, now = Date.now()) {
4159
4207
  [3600, "hour"],
4160
4208
  [60, "minute"]
4161
4209
  ];
4162
- for (const [n, name] of units) {
4163
- if (s >= n) {
4164
- const v = Math.floor(s / n);
4210
+ for (const [n2, name] of units) {
4211
+ if (s >= n2) {
4212
+ const v = Math.floor(s / n2);
4165
4213
  return `${v} ${name}${v === 1 ? "" : "s"} ago`;
4166
4214
  }
4167
4215
  }
@@ -4273,7 +4321,7 @@ var init_checks = __esm({
4273
4321
  const s = String(text ?? "");
4274
4322
  return `"${s.length > max ? `${s.slice(0, max - 3)}...` : s}"`;
4275
4323
  };
4276
- plural = (n, one, many) => `${n} ${n === 1 ? one : many}`;
4324
+ plural = (n2, one, many) => `${n2} ${n2 === 1 ? one : many}`;
4277
4325
  baseOf = (path) => String(path).slice(String(path).lastIndexOf("/") + 1);
4278
4326
  CHECKS = [
4279
4327
  // ---- Launch ------------------------------------------------------------------------------------------------------
@@ -4329,8 +4377,8 @@ var init_checks = __esm({
4329
4377
  if (!home) return miss;
4330
4378
  if (!home.title) return fail("the page has no <title>");
4331
4379
  if (home.defaultTitle) return fail(`the title is a starter template's: ${quote(home.title)}`);
4332
- const n = home.title.length;
4333
- if (n < 10 || n > 65) return fail(`the title is ${plural(n, "character", "characters")}: ${quote(home.title)}`);
4380
+ const n2 = home.title.length;
4381
+ if (n2 < 10 || n2 > 65) return fail(`the title is ${plural(n2, "character", "characters")}: ${quote(home.title)}`);
4334
4382
  return pass(`title: ${quote(home.title)}`);
4335
4383
  }
4336
4384
  },
@@ -4416,8 +4464,8 @@ var init_checks = __esm({
4416
4464
  const { home, miss } = page(site);
4417
4465
  if (!home) return miss;
4418
4466
  if (!home.description) return fail('no <meta name="description"> in the page');
4419
- const n = home.description.length;
4420
- if (n < 50 || n > 160) return fail(`the description is ${plural(n, "character", "characters")}: ${quote(home.description, 70)}`);
4467
+ const n2 = home.description.length;
4468
+ if (n2 < 50 || n2 > 160) return fail(`the description is ${plural(n2, "character", "characters")}: ${quote(home.description, 70)}`);
4421
4469
  return pass(`description: ${quote(home.description, 70)}`);
4422
4470
  }
4423
4471
  },
@@ -4574,9 +4622,9 @@ var init_checks = __esm({
4574
4622
  run({ site }) {
4575
4623
  const { home, miss } = page(site);
4576
4624
  if (!home) return miss;
4577
- const n = Number(home.textChars) || 0;
4578
- if (n >= MIN_TEXT) return pass(`${n} characters of text in the HTML the server sends`);
4579
- return fail(`${plural(n, "character", "characters")} of visible text in the HTML the server sends`, `${plural(Number(home.scripts) || 0, "script tag", "script tags")} in the page`);
4625
+ const n2 = Number(home.textChars) || 0;
4626
+ if (n2 >= MIN_TEXT) return pass(`${n2} characters of text in the HTML the server sends`);
4627
+ return fail(`${plural(n2, "character", "characters")} of visible text in the HTML the server sends`, `${plural(Number(home.scripts) || 0, "script tag", "script tags")} in the page`);
4580
4628
  }
4581
4629
  },
4582
4630
  {
@@ -4731,8 +4779,8 @@ var init_checks = __esm({
4731
4779
  run({ repo }) {
4732
4780
  if (!repo) return unknown(NO_REPO);
4733
4781
  const t = repo.tests || {};
4734
- const n = Number(t.files) || 0;
4735
- if (n > 0) return pass(plural(n, "test file", "test files"), ...t.runner ? [`runner: ${t.runner}`] : []);
4782
+ const n2 = Number(t.files) || 0;
4783
+ if (n2 > 0) return pass(plural(n2, "test file", "test files"), ...t.runner ? [`runner: ${t.runner}`] : []);
4736
4784
  if (t.script) return unknown('package.json has a "test" script, but no test files were found');
4737
4785
  if (repo.truncated) return unknown("the project has more files than were listed, and none of the listed ones is a test");
4738
4786
  return fail("no test files in the project");
@@ -5063,13 +5111,13 @@ function readHead(path, limit = MAX_READ) {
5063
5111
  fd = openSync(path, "r");
5064
5112
  const max = Math.max(0, Math.min(limit, MAX_READ));
5065
5113
  const buf = Buffer.allocUnsafe(max);
5066
- let n = 0;
5067
- while (n < max) {
5068
- const got = readSync(fd, buf, n, max - n, null);
5114
+ let n2 = 0;
5115
+ while (n2 < max) {
5116
+ const got = readSync(fd, buf, n2, max - n2, null);
5069
5117
  if (got <= 0) break;
5070
- n += got;
5118
+ n2 += got;
5071
5119
  }
5072
- return buf.subarray(0, n).toString("utf8").replace(/^\uFEFF/, "");
5120
+ return buf.subarray(0, n2).toString("utf8").replace(/^\uFEFF/, "");
5073
5121
  } catch {
5074
5122
  return null;
5075
5123
  } finally {
@@ -5137,10 +5185,10 @@ function readPackage(facts, ctx) {
5137
5185
  function stringMap(value) {
5138
5186
  const out2 = {};
5139
5187
  if (!value || typeof value !== "object" || Array.isArray(value)) return out2;
5140
- let n = 0;
5188
+ let n2 = 0;
5141
5189
  for (const key of Object.keys(value)) {
5142
5190
  if (typeof value[key] !== "string") continue;
5143
- if (++n > 1e3) break;
5191
+ if (++n2 > 1e3) break;
5144
5192
  out2[redactSecrets(key)] = redactSecrets(value[key]);
5145
5193
  }
5146
5194
  return out2;
@@ -5166,11 +5214,11 @@ function readTests(facts) {
5166
5214
  const deps = facts.pkg ? facts.pkg.deps : {};
5167
5215
  const scripts = facts.pkg ? facts.pkg.scripts : {};
5168
5216
  const has = (re) => facts.files.some((f) => re.test(f));
5169
- let count = 0;
5170
- for (const f of facts.files) if (TEST_FILE.test(f) && !f.endsWith(".d.ts")) count++;
5217
+ let count2 = 0;
5218
+ for (const f of facts.files) if (TEST_FILE.test(f) && !f.endsWith(".d.ts")) count2++;
5171
5219
  const script = typeof scripts.test === "string" && scripts.test.trim() && !/no test specified/i.test(scripts.test) ? scripts.test : null;
5172
5220
  const playwright = "@playwright/test" in deps || "playwright" in deps || has(/(?:^|\/)playwright\.config\.[cm]?[jt]s$/);
5173
- facts.tests = { files: count, script, playwright, runner: testRunner(script || "", deps, has, playwright) };
5221
+ facts.tests = { files: count2, script, playwright, runner: testRunner(script || "", deps, has, playwright) };
5174
5222
  }
5175
5223
  function testRunner(script, deps, has, playwright) {
5176
5224
  const inScript = [
@@ -5314,14 +5362,14 @@ function readReadme(facts, ctx) {
5314
5362
  function readDeps(facts) {
5315
5363
  const names = facts.pkg ? Object.keys(facts.pkg.deps) : [];
5316
5364
  for (const [provider, re] of PAYMENT_DEPS2) {
5317
- if (names.some((n) => re.test(n))) {
5365
+ if (names.some((n2) => re.test(n2))) {
5318
5366
  facts.payments.provider = provider;
5319
5367
  break;
5320
5368
  }
5321
5369
  }
5322
- facts.monitoring.genclass = names.some((n) => GENCLASS_DEP.test(n));
5323
- facts.monitoring.sentry = names.some((n) => SENTRY_DEP.test(n));
5324
- facts.monitoring.other = MONITOR_DEPS.filter(([, re]) => names.some((n) => re.test(n))).map(([name]) => name);
5370
+ facts.monitoring.genclass = names.some((n2) => GENCLASS_DEP.test(n2));
5371
+ facts.monitoring.sentry = names.some((n2) => SENTRY_DEP.test(n2));
5372
+ facts.monitoring.other = MONITOR_DEPS.filter(([, re]) => names.some((n2) => re.test(n2))).map(([name]) => name);
5325
5373
  }
5326
5374
  function scanContents(facts, ctx) {
5327
5375
  const tracked2 = ctx.trackedSet;
@@ -5510,7 +5558,7 @@ function readHosting(facts, ctx) {
5510
5558
  if (!provider && exists(join9(ctx.root, ".vercel"))) provider = "vercel";
5511
5559
  if (!provider && exists(join9(ctx.root, ".netlify"))) provider = "netlify";
5512
5560
  if (!provider) {
5513
- for (const [name, re] of HOSTING_DEPS) if (!provider && names.some((n) => re.test(n))) provider = name;
5561
+ for (const [name, re] of HOSTING_DEPS) if (!provider && names.some((n2) => re.test(n2))) provider = name;
5514
5562
  }
5515
5563
  if (!provider) {
5516
5564
  for (const [name, re] of HOSTING_WORKFLOW) if (!provider && workflows.some((t) => re.test(t))) provider = name;
@@ -5545,8 +5593,8 @@ function readSeo(facts) {
5545
5593
  const names = facts.pkg ? Object.keys(facts.pkg.deps) : [];
5546
5594
  const has = (re, webRootOnly) => facts.files.some((f) => re.test(f) && (!webRootOnly || WEB_ROOT.test(f)) && !TEST_PATH.test(f));
5547
5595
  facts.seo = {
5548
- robots: has(SEO_FILES.robots, false) || names.some((n) => SEO_DEPS.robots.test(n)),
5549
- sitemap: has(SEO_FILES.sitemap, false) || names.some((n) => SEO_DEPS.sitemap.test(n)),
5596
+ robots: has(SEO_FILES.robots, false) || names.some((n2) => SEO_DEPS.robots.test(n2)),
5597
+ sitemap: has(SEO_FILES.sitemap, false) || names.some((n2) => SEO_DEPS.sitemap.test(n2)),
5550
5598
  llms: has(SEO_FILES.llms, false),
5551
5599
  ogImage: has(SEO_FILES.ogImage, true),
5552
5600
  manifest: has(SEO_FILES.manifest, true)
@@ -5797,27 +5845,27 @@ async function readBody(res, max) {
5797
5845
  if (body && typeof body.getReader === "function") {
5798
5846
  const reader = body.getReader();
5799
5847
  const chunks = [];
5800
- let n = 0;
5801
- while (n < max) {
5848
+ let n2 = 0;
5849
+ while (n2 < max) {
5802
5850
  const { done, value } = await reader.read();
5803
5851
  if (done) break;
5804
5852
  if (!value || !value.length) continue;
5805
- const take = value.length > max - n ? value.subarray(0, max - n) : value;
5853
+ const take = value.length > max - n2 ? value.subarray(0, max - n2) : value;
5806
5854
  chunks.push(take);
5807
- n += take.length;
5855
+ n2 += take.length;
5808
5856
  }
5809
5857
  try {
5810
5858
  Promise.resolve(reader.cancel()).catch(() => {
5811
5859
  });
5812
5860
  } catch {
5813
5861
  }
5814
- const all = new Uint8Array(n);
5862
+ const all = new Uint8Array(n2);
5815
5863
  let at = 0;
5816
5864
  for (const chunk of chunks) {
5817
5865
  all.set(chunk, at);
5818
5866
  at += chunk.length;
5819
5867
  }
5820
- return { text: new TextDecoder("utf-8").decode(all), bytes: n };
5868
+ return { text: new TextDecoder("utf-8").decode(all), bytes: n2 };
5821
5869
  }
5822
5870
  if (typeof res.text === "function") {
5823
5871
  const bytes = new TextEncoder().encode(String(await res.text()));
@@ -6295,11 +6343,11 @@ function layOut(results, plan) {
6295
6343
  const rest = failed.filter((r) => !order.includes(r.id)).sort((a, b) => b.weight - a.weight);
6296
6344
  const shown = plan ? plan.items.length : Math.min(FREE_SHOWN, rest.length);
6297
6345
  for (const r of rest) order.push(r.id);
6298
- return order.map((id, n) => {
6346
+ return order.map((id, n2) => {
6299
6347
  const r = by.get(id);
6300
6348
  const words = full.get(id);
6301
- const open = plan ? full.has(id) : n < shown;
6302
- return { ...r, n: n + 1, open, why: open && words?.why || r.why, step: open && words?.step || r.fix, prompt: open && words?.prompt || r.prompt, fromModel: !!(open && words?.why) };
6349
+ const open = plan ? full.has(id) : n2 < shown;
6350
+ return { ...r, n: n2 + 1, open, why: open && words?.why || r.why, step: open && words?.step || r.fix, prompt: open && words?.prompt || r.prompt, fromModel: !!(open && words?.why) };
6303
6351
  });
6304
6352
  }
6305
6353
  function printItem(i, full) {
@@ -6474,11 +6522,11 @@ function genclassWorkflows(root) {
6474
6522
  const dir = join10(root, ".github", "workflows");
6475
6523
  let names = [];
6476
6524
  try {
6477
- names = readdirSync4(dir).filter((n) => /\.ya?ml$/i.test(n));
6525
+ names = readdirSync4(dir).filter((n2) => /\.ya?ml$/i.test(n2));
6478
6526
  } catch {
6479
6527
  return [];
6480
6528
  }
6481
- return names.filter((n) => /genclass-playwright-run|@genclass\/playwright|genclass-races/.test(read3(join10(dir, n)) ?? "")).map((n) => `.github/workflows/${n}`);
6529
+ return names.filter((n2) => /genclass-playwright-run|@genclass\/playwright|genclass-races/.test(read3(join10(dir, n2)) ?? "")).map((n2) => `.github/workflows/${n2}`);
6482
6530
  }
6483
6531
  function hasPlaywright(cwd, project) {
6484
6532
  if (project?.has?.("@playwright/test") || project?.has?.("playwright")) return true;
@@ -6510,33 +6558,59 @@ async function readState(o = {}, deps = {}) {
6510
6558
  const isApp = !project.refused && !!project.framework;
6511
6559
  steps.push({
6512
6560
  id: "account",
6513
- title: "Signed in",
6561
+ title: "Account",
6562
+ doing: "Sign in",
6514
6563
  state: me ? "done" : creds && offline && offline !== "expired" ? "done" : "todo",
6515
6564
  detail: me ? `${accountLabel(me.account)}${me.plan ? ` \xB7 ${me.plan.name} plan` : ""}` : creds && offline === "expired" ? "the saved session expired: sign in again" : creds && offline ? `${accountLabel(creds.account)} (not checked: ${offline})` : otherHost ? `the saved session is for ${otherHost}` : "",
6516
- why: "Your account is where your apps, their dashboards and your plan live. Signing in opens genclass.dev in your browser; you approve a short code there, and nothing is typed here.",
6565
+ why: "Opens genclass.dev in your browser. You approve a short code there.",
6566
+ more: "Your account is where your apps, their dashboards and your plan live. Nothing is typed in the terminal.",
6517
6567
  run: "genclass login",
6518
6568
  human: "approve the sign-in in your browser"
6519
6569
  });
6520
6570
  const linked = !!st.token && (!me || !!app);
6521
6571
  steps.push({
6522
6572
  id: "runtime",
6523
- title: "GenClass is in this app",
6573
+ title: "Runtime",
6574
+ doing: st.fresh ? "Add GenClass to this app" : "Put this app in your account",
6524
6575
  state: !isApp ? "blocked" : st.fresh ? "todo" : linked ? "done" : "todo",
6525
6576
  detail: !isApp ? project.refused ?? "no web app in this folder (no package.json with a browser app, no HTML page)" : st.fresh ? project.label : !st.token ? "added, with no dashboard yet" : me && !app ? "added, but this app is not in your account yet" : `${st.handWritten ? "added by hand" : "added"}${app ? ` \xB7 app "${app.name}"` : ""}`,
6526
- why: st.fresh ? "This adds the GenClass runtime to your app: one import (or one script tag) and the package. It watches the page in your users' browsers for lost edits, double submits and old data shown over new, and only reports. You see the exact change before anything is written." : "The runtime is in the code. This gives the app its place in your account, so what it finds shows up on your dashboard.",
6577
+ why: st.fresh ? "One import and the package. You see the change before it is written." : "Gives the app its place in your account, so what it finds shows on your dashboard.",
6578
+ more: "The runtime watches the page in your users' browsers for lost edits, double submits and old data shown over new. It only reports: it never holds, delays or changes anything your app does.",
6527
6579
  run: st.fresh ? "genclass init" : "genclass connect",
6528
6580
  human: null
6529
6581
  });
6530
6582
  steps.push({
6531
- id: "first-page",
6532
- title: "First page seen",
6583
+ id: "dashboard",
6584
+ title: "Dashboard",
6585
+ doing: "See your first page",
6533
6586
  state: !isApp ? "optional" : app?.last_event ? "done" : app ? "waiting" : "todo",
6534
6587
  detail: !isApp ? "" : app?.last_event ? `last page ${ago(app.last_event, now)}` : app ? "deploy, then open your site once" : "",
6535
- why: "GenClass sends nothing from localhost, so the dashboard fills once your deployed site has been opened. Deploy as you normally do, open the site, and run genclass again.",
6588
+ why: "It fills once your live site has been opened.",
6589
+ more: "GenClass sends nothing from localhost, so the dashboard starts with your deployed site. Deploy as you normally do, open the site, and run genclass again.",
6536
6590
  run: null,
6537
6591
  human: "deploy your app and open the live site once"
6538
6592
  });
6539
- const pr = { state: (
6593
+ const wf = { state: (
6594
+ /** @type {StepState} */
6595
+ "todo"
6596
+ ), detail: "" };
6597
+ if (!isApp) wf.state = "optional";
6598
+ else if (!git.repo) Object.assign(wf, { state: "optional", detail: "not a git repository yet" });
6599
+ else if (!git.github) Object.assign(wf, { state: "optional", detail: "the repository is not on GitHub" });
6600
+ else if (workflows.length) Object.assign(wf, { state: "done", detail: workflows[0] });
6601
+ else if (!playwright) Object.assign(wf, { state: "optional", detail: "no Playwright tests yet" });
6602
+ else Object.assign(wf, { state: "todo", detail: "Playwright found \xB7 no workflow file yet" });
6603
+ steps.push({
6604
+ id: "workflow",
6605
+ title: "Test workflow",
6606
+ doing: "Add the test workflow",
6607
+ ...wf,
6608
+ why: `One new file, ${WORKFLOW_PATH}. Your tests are not changed.`,
6609
+ more: "On each pull request it runs your Playwright tests once more with slow and reordered responses, in a job of its own that is allowed to fail, and uploads small race files. It needs no secret.",
6610
+ run: "genclass setup",
6611
+ human: null
6612
+ });
6613
+ const gh = { state: (
6540
6614
  /** @type {StepState} */
6541
6615
  "todo"
6542
6616
  ), detail: "", run: (
@@ -6546,33 +6620,34 @@ async function readState(o = {}, deps = {}) {
6546
6620
  /** @type {string | null} */
6547
6621
  null
6548
6622
  ) };
6549
- if (!isApp) Object.assign(pr, { state: "optional", detail: "" });
6550
- else if (!git.repo) Object.assign(pr, { state: "optional", detail: "not a git repository yet" });
6551
- else if (!git.github) Object.assign(pr, { state: "optional", detail: "the repository is not on GitHub" });
6552
- else if (!playwright && !workflows.length) Object.assign(pr, { state: "optional", detail: "no Playwright tests yet" });
6553
- else if (!workflows.length) Object.assign(pr, { state: "todo", detail: "Playwright found \xB7 no workflow file yet" });
6554
- else if (!me) Object.assign(pr, { state: "todo", detail: "workflow file in place \xB7 sign in to check the app" });
6555
- else if (!repo || !repo.ok) {
6556
- Object.assign(pr, repo?.missing ? { state: "waiting", detail: "workflow file in place \xB7 app: genclass.dev/account/github", run: null } : { state: "todo", detail: `workflow file in place \xB7 could not check the app${repo ? ` (${repo.reason})` : ""}` });
6557
- } else if (!repo.known) Object.assign(pr, { state: "todo", detail: "workflow file in place \xB7 continue with GitHub", human: "install the GitHub App and continue with GitHub in your browser" });
6558
- else if (!repo.installed) Object.assign(pr, { state: "todo", detail: `the GitHub App is not on ${git.github} yet`, human: "install the GitHub App on this repository" });
6559
- else if (repo.needsPlan) Object.assign(pr, { state: "waiting", detail: "private repository: reviews come with the Team plan", run: null });
6560
- else if (repo.paused) Object.assign(pr, { state: "waiting", detail: "paused on your GitHub page at genclass.dev", run: null });
6561
- else if (repo.evidence) Object.assign(pr, { state: "done", detail: repo.prs ? `reviewing \xB7 ${repo.prs} pull request${repo.prs === 1 ? "" : "s"} so far` : "reviewing" });
6562
- else Object.assign(pr, { state: "waiting", detail: "ready \xB7 open a pull request and the first review appears", run: null, human: "commit the workflow file and open a pull request" });
6623
+ if (!isApp || !git.github) Object.assign(gh, { state: "optional", detail: !isApp ? "" : git.repo ? "the repository is not on GitHub" : "not a git repository yet" });
6624
+ else if (!workflows.length && !playwright) Object.assign(gh, { state: "optional", detail: "needs Playwright tests first" });
6625
+ else if (!workflows.length) Object.assign(gh, { detail: "after the test workflow" });
6626
+ else if (!me) Object.assign(gh, { detail: "sign in to check" });
6627
+ else if (!repo || !repo.ok) Object.assign(gh, repo?.missing ? { state: "waiting", detail: "check it at genclass.dev/account/github", run: null } : { detail: `could not check${repo ? ` (${repo.reason})` : ""}` });
6628
+ else if (!repo.known) Object.assign(gh, { detail: "continue with GitHub to check", human: "install the GitHub App and continue with GitHub in your browser" });
6629
+ else if (!repo.installed) Object.assign(gh, { detail: `not on ${git.github} yet`, human: "install the GitHub App on this repository" });
6630
+ else if (repo.needsPlan) Object.assign(gh, { state: "waiting", detail: "private repository: reviews come with the Team plan", run: null });
6631
+ else if (repo.paused) Object.assign(gh, { state: "waiting", detail: "paused on your GitHub page at genclass.dev", run: null });
6632
+ else if (repo.evidence) Object.assign(gh, { state: "done", detail: repo.prs ? `reviewing \xB7 ${repo.prs} pull request${repo.prs === 1 ? "" : "s"} so far` : "reviewing" });
6633
+ else Object.assign(gh, { state: "waiting", detail: "installed \xB7 open a pull request and the first review appears", run: null, human: "commit the workflow file and open a pull request" });
6563
6634
  steps.push({
6564
- id: "pull-requests",
6565
- title: "Pull requests checked",
6566
- ...pr,
6567
- why: "On each pull request GenClass runs your Playwright tests once more with slow and reordered responses, and comments when a page ends up wrong, with the steps to see it. It needs one workflow file in the repository and the GenClass GitHub App on it. The app cannot read or change your code."
6635
+ id: "github-app",
6636
+ title: "GitHub App",
6637
+ doing: "Connect the GitHub App",
6638
+ ...gh,
6639
+ why: "It comments on a pull request when a page ends up wrong. It cannot read or change your code.",
6640
+ more: "The app reads the race files the test workflow uploads and posts one check and one comment, with the steps to see the problem. You install it on GitHub in your browser; this command only waits for GitHub's answer."
6568
6641
  });
6569
6642
  const agents = [.../* @__PURE__ */ new Set([...agentConfigs(cwd), ...git.root && git.root !== cwd ? agentConfigs(git.root) : []])];
6570
6643
  steps.push({
6571
6644
  id: "agent",
6572
- title: "Coding agent connected",
6645
+ title: "Coding agent",
6646
+ doing: "Connect your coding agent",
6573
6647
  state: !isApp ? "optional" : agents.length ? "done" : "todo",
6574
6648
  detail: agents.length ? agents.join(", ") : "",
6575
- why: "This lets Claude Code, Cursor and other coding agents ask GenClass what went wrong, replay it and check their fix. It adds GenClass's MCP server to the project's agent configuration; the server runs on your machine.",
6649
+ why: "Adds GenClass's tools to Claude Code, Cursor and other agents in this project.",
6650
+ more: "It adds GenClass's MCP server to the project's agent configuration (.mcp.json). The server runs on your machine and lets an agent ask what went wrong on a page, replay it and check its fix.",
6576
6651
  run: "genclass setup",
6577
6652
  human: null
6578
6653
  });
@@ -6581,10 +6656,12 @@ async function readState(o = {}, deps = {}) {
6581
6656
  steps.push({
6582
6657
  id: "suggestions",
6583
6658
  title: "Suggestions",
6659
+ doing: "See what your app is missing",
6584
6660
  // run once, it is done only when nothing is left on the list; until then it waits on the person, not on a command
6585
6661
  state: !s ? "todo" : s.failed ? "waiting" : "done",
6586
6662
  detail: !s ? "" : s.failed ? `${s.failed} to do${s.urgent ? `, ${s.urgent} urgent` : ""} \xB7 checked ${ago(s.at, now)}` : `nothing to do \xB7 checked ${ago(s.at, now)}`,
6587
- why: "GenClass checks your repository and your live site for what a launched app needs (search engines and AI assistants can read it, payments are live, secrets are safe, people can see the price) and tells you what to do first, in plain words.",
6663
+ why: "Checks your repository and your live site, and tells you what to do first.",
6664
+ more: "It measures what a launched app needs (search engines and AI assistants can read it, payments are live, secrets are safe, people can see the price) and explains each thing in plain words, with a prompt for your coding agent.",
6588
6665
  run: "genclass suggest",
6589
6666
  human: s?.failed ? "work through the list: genclass suggest" : null
6590
6667
  });
@@ -6596,6 +6673,8 @@ async function readState(o = {}, deps = {}) {
6596
6673
  app: { name: app?.name ?? project.name ?? null, framework: project.label || null, isApp, token: st.token ?? null, dashboardUrl: app?.dashboard_url ?? st.local?.dashboardUrl ?? null, site: notes.site ?? null },
6597
6674
  account: me ? { label: accountLabel(me.account), plan: me.plan, suggestions: me.suggestions, billingUrl: me.billingUrl, github: me.github } : null,
6598
6675
  signedIn: !!me,
6676
+ /** the account's apps as genclass.dev lists them ([] signed out) */
6677
+ projects: me?.projects ?? [],
6599
6678
  sessionProblem: creds && !me ? offline : null,
6600
6679
  git: { repo: git.repo, github: git.github, root: git.root, branch: git.branch },
6601
6680
  playwright,
@@ -6613,7 +6692,7 @@ function stateJson(s) {
6613
6692
  account: s.account ? { label: s.account.label, plan: s.account.plan } : null,
6614
6693
  github: s.git.github,
6615
6694
  steps: s.steps.map((x) => ({ id: x.id, title: x.title, state: x.state, detail: x.detail, run: x.state === "done" ? null : x.run, human: x.state === "done" ? null : x.human })),
6616
- next: s.next ? { id: s.next.id, title: s.next.title, run: s.next.run, human: s.next.human, why: s.next.why } : null,
6695
+ next: s.next ? { id: s.next.id, title: s.next.doing, run: s.next.run, human: s.next.human, why: s.next.why } : null,
6617
6696
  complete: s.complete
6618
6697
  };
6619
6698
  }
@@ -6685,7 +6764,7 @@ async function signIn(o = {}) {
6685
6764
  }
6686
6765
  async function addRuntime(state, o = {}) {
6687
6766
  const step = state.steps.find((s) => s.id === "runtime");
6688
- const args = ["--cwd", state.cwd, ...o.yes ? ["--yes"] : []];
6767
+ const args = ["--cwd", state.cwd, ...o.yes ? ["--yes"] : [], ...state.signedIn ? ["--in-account"] : []];
6689
6768
  const code = step?.run === "genclass connect" ? await run2("connect", args) : await run("init", args);
6690
6769
  return code === 0 ? "done" : "failed";
6691
6770
  }
@@ -6723,82 +6802,94 @@ function workflowFor(sub) {
6723
6802
  `);
6724
6803
  return withDir.includes(`working-directory: ${sub}`) && withDir.includes(`path: ${sub}/test-results/genclass`) ? withDir : null;
6725
6804
  }
6726
- async function addWorkflow(state, o) {
6805
+ async function addWorkflow(state, o = {}) {
6727
6806
  const root = state.git.root;
6728
6807
  const sub = relative5(root, state.cwd).split(sep5).join("/");
6729
6808
  const text = workflowFor(sub);
6730
6809
  if (text === null) {
6731
6810
  warn(`This app's folder (${sub}) has a name the workflow cannot use as it is. Copy docs/github-app/workflows/genclass.yml from the GenClass repository and set its working directory by hand.`);
6732
- return false;
6811
+ return "skipped";
6733
6812
  }
6734
6813
  const file = join11(root, WORKFLOW_PATH);
6735
- out();
6736
- out(` ${c.bold(WORKFLOW_PATH)} ${c.gray("(")}${c.green("new file")}${c.gray(`, ${text.split("\n").length - 1} lines)`)}`);
6737
- para("A job of its own, allowed to fail, so it never blocks a pull request. It installs your dependencies, runs your Playwright tests under two seeds with GenClass on the pages they open, and uploads the small race files. It needs no secret and changes nothing in your tests.", " ", c.gray);
6738
- out();
6739
- if (!o.yes) {
6814
+ if (!o.yes && !o.confirmed) {
6740
6815
  if (!interactive()) {
6741
- note(`Not a terminal: run ${c.cyan("genclass setup --yes")} to write it.`);
6742
- return false;
6816
+ note(`Not a terminal: run ${c.cyan("genclass setup --yes")} to write ${WORKFLOW_PATH}.`);
6817
+ return "skipped";
6743
6818
  }
6744
- if (!await agree("Write this file?")) return false;
6819
+ if (!await agree(`Write ${WORKFLOW_PATH}?`)) return "skipped";
6745
6820
  }
6746
6821
  try {
6747
6822
  mkdirSync4(dirname8(file), { recursive: true });
6748
6823
  writeFileSync5(file, text, { flag: "wx" });
6749
6824
  } catch (e) {
6750
6825
  bad(`Could not write ${WORKFLOW_PATH}: ${e?.code === "EEXIST" ? "a file with that name is already there" : e?.message ?? e}`);
6751
- return false;
6826
+ return e?.code === "EEXIST" ? "skipped" : "failed";
6752
6827
  }
6753
- good(`Wrote ${c.bold(WORKFLOW_PATH)}`);
6828
+ good(`Wrote ${c.bold(WORKFLOW_PATH)} ${c.gray(`(new file, ${text.split("\n").length - 1} lines)`)}`);
6754
6829
  note("It is not committed. When you are ready:");
6755
6830
  out(` ${c.cyan(`git add ${WORKFLOW_PATH} && git commit -m "Add GenClass to pull requests" && git push`)}`);
6756
- return true;
6831
+ return "done";
6757
6832
  }
6758
- async function waitForApp(creds, repo, seconds = 180) {
6759
- const sp = spinner("Waiting for GitHub's answer (finish in the browser, then come back here)");
6760
- const until = Date.now() + seconds * 1e3;
6761
- while (Date.now() < until) {
6762
- await sleep3(4e3);
6833
+ async function waitForGithub(creds, repo, text, until, seconds) {
6834
+ const sp = spinner(text);
6835
+ const end = Date.now() + seconds * 1e3;
6836
+ let last = null;
6837
+ while (Date.now() < end) {
6838
+ await sleep3(3e3);
6763
6839
  const r = await fetchRepoStatus(creds, repo);
6764
- if (r.ok && r.known && r.installed) {
6765
- sp.stop("ok", `The GenClass GitHub App is on ${c.bold(repo)}.`);
6840
+ if (r.ok) last = r;
6841
+ if (r.ok && until(r)) {
6842
+ sp.stop();
6766
6843
  return r;
6767
6844
  }
6768
- if (r.ok && r.known && r.installed === false) sp.update(`GitHub lists no installation on ${repo} yet. Waiting`);
6769
6845
  }
6770
- sp.stop("warn", "No answer yet. Finish in the browser and run genclass again: this step picks up where it stopped.");
6771
- return null;
6846
+ sp.stop();
6847
+ return last && until(last) ? last : null;
6772
6848
  }
6773
- async function setUpPullRequests(state, o = {}) {
6774
- if (!state.workflows.length && !await addWorkflow(state, o)) return "skipped";
6849
+ async function connectGithubApp(state, o = {}) {
6775
6850
  const creds = readCredentials();
6776
6851
  const repo = state.git.github;
6777
- if (!creds || !repo) return "done";
6778
- const st = await fetchRepoStatus(creds, repo);
6852
+ if (!creds || !repo) return "skipped";
6853
+ let st = await fetchRepoStatus(creds, repo);
6779
6854
  if (!st.ok && st.missing) {
6780
- note(`This genclass.dev cannot tell the CLI about the GitHub App yet. Check it in the browser: ${c.cyan(hostUrl("/account/github"))}`);
6781
- return "done";
6855
+ note(`This genclass.dev cannot tell the command about the GitHub App. Check it in the browser: ${c.cyan(hostUrl("/account/github"))}`);
6856
+ return "skipped";
6782
6857
  }
6783
- if (st.ok && st.known && st.installed) {
6858
+ const on = (r) => r.known && r.installed === true;
6859
+ if (st.ok && on(st)) {
6784
6860
  good(`The GenClass GitHub App is on ${c.bold(repo)}.`);
6785
6861
  return "done";
6786
6862
  }
6787
6863
  const installUrl = st.ok && st.installUrl || hostUrl("/github/install");
6788
6864
  const connectUrl = st.ok && st.connectUrl || hostUrl("/github/connect");
6789
- out();
6790
- para(`The GenClass GitHub App posts the review on your pull requests. It reads the race files that workflow uploads and nothing else: it has no permission to read or change your code.`, " ");
6791
6865
  if (o.yes || !interactive()) {
6792
- out(` Install it on ${c.bold(repo)}: ${c.cyan(installUrl)}`);
6866
+ out(` Install the GenClass GitHub App on ${c.bold(repo)}: ${c.cyan(installUrl)}`);
6793
6867
  out(` Then, on the page GitHub sends you to, press ${c.bold("Continue with GitHub")}. Already installed: ${c.cyan(connectUrl)}`);
6868
+ return "skipped";
6869
+ }
6870
+ if (!st.ok || !st.known) {
6871
+ out(` ${c.gray(sym.arrow)} Asking GitHub which repositories the app is on: ${c.cyan(connectUrl)}`);
6872
+ openBrowser2(connectUrl, o);
6873
+ st = await waitForGithub(creds, repo, "Waiting for GitHub's answer (approve in the browser if it asks)", (r) => r.known, 90) ?? st;
6874
+ if (st.ok && on(st)) {
6875
+ good(`The GenClass GitHub App is on ${c.bold(repo)}.`);
6876
+ return "done";
6877
+ }
6878
+ if (!st.ok || !st.known) {
6879
+ warn(`No answer yet. Make sure the browser is signed in to the same GenClass account as this command, then run genclass again.`);
6880
+ return "skipped";
6881
+ }
6882
+ }
6883
+ out(` ${c.gray(sym.arrow)} The app is not on ${c.bold(repo)} yet. Opening GitHub to install it: ${c.cyan(installUrl)}`);
6884
+ note("Pick this repository on GitHub's page. On the page that follows, press Continue with GitHub.");
6885
+ openBrowser2(installUrl, o);
6886
+ const done = await waitForGithub(creds, repo, `Waiting for the app to be installed on ${repo}`, on, 240);
6887
+ if (done) {
6888
+ good(`The GenClass GitHub App is on ${c.bold(repo)}.`);
6794
6889
  return "done";
6795
6890
  }
6796
- const chosen = await pick("The GitHub App", [`Install it on ${repo} (opens GitHub; then press Continue with GitHub on the page that follows)`, "It is installed already: check with GitHub (opens genclass.dev)", "Skip for now"], 0);
6797
- if (chosen === null || chosen === 2) return "skipped";
6798
- const url = chosen === 0 ? installUrl : connectUrl;
6799
- out(` ${c.gray(sym.arrow)} ${c.cyan(url)}`);
6800
- openBrowser2(url, o);
6801
- return await waitForApp(creds, repo) ? "done" : "skipped";
6891
+ warn("Not installed yet. Finish on GitHub and run genclass again: this step picks up where it stopped.");
6892
+ return "skipped";
6802
6893
  }
6803
6894
  function planAgentConfig(dir) {
6804
6895
  const file = existsSync5(join11(dir, ".cursor")) && !existsSync5(join11(dir, ".mcp.json")) ? ".cursor/mcp.json" : ".mcp.json";
@@ -6829,9 +6920,9 @@ async function connectAgent(state, o = {}) {
6829
6920
  out(` ${c.cyan(`"genclass": ${JSON.stringify(mcpServer())}`)}`);
6830
6921
  return "skipped";
6831
6922
  }
6832
- out();
6833
- printChange(plan.change);
6834
- if (!o.yes) {
6923
+ if (!o.yes && !o.confirmed) {
6924
+ out();
6925
+ printChange(plan.change);
6835
6926
  if (!interactive()) {
6836
6927
  note(`Not a terminal: run ${c.cyan("genclass setup --yes")} to write it.`);
6837
6928
  return "skipped";
@@ -6845,8 +6936,8 @@ async function connectAgent(state, o = {}) {
6845
6936
  bad(`Could not write ${plan.file}: ${e?.message ?? e}`);
6846
6937
  return "failed";
6847
6938
  }
6848
- good(`Wrote ${c.bold(plan.file)}`);
6849
- note("Restart your coding agent in this folder and it has GenClass's tools: what went wrong on a page, a replay of it, and a check of the fix.");
6939
+ good(`${plan.change.kind === "create" ? "Wrote" : "Updated"} ${c.bold(plan.file)} ${c.gray("(GenClass's MCP server)")}`);
6940
+ note("Restart your coding agent in this folder and it has GenClass's tools.");
6850
6941
  return "done";
6851
6942
  }
6852
6943
  var sleep3, mcpServer;
@@ -6867,6 +6958,223 @@ var init_actions = __esm({
6867
6958
  }
6868
6959
  });
6869
6960
 
6961
+ // src/app.mjs
6962
+ var app_exports = {};
6963
+ __export(app_exports, {
6964
+ KINDS: () => KINDS,
6965
+ dashboard: () => dashboard2,
6966
+ render: () => render,
6967
+ spark: () => spark
6968
+ });
6969
+ function spark(series) {
6970
+ if (!series.length) return "";
6971
+ const max = Math.max(...series);
6972
+ if (max <= 0) return "";
6973
+ return series.map((v) => BARS[Math.min(BARS.length - 1, Math.round(v / max * (BARS.length - 1)))]).join("");
6974
+ }
6975
+ function table(title, list, shown, describe) {
6976
+ if (!list.length) return;
6977
+ out();
6978
+ out(` ${c.bold(title)}`);
6979
+ const top = list.slice(0, shown).map((r) => ({ ...r, page: r.page || "(page unknown)" }));
6980
+ const wCount = Math.max(...top.map((r) => n(r.count).length));
6981
+ const wKind = Math.min(22, Math.max(...top.map((r) => r.kind.length)));
6982
+ const wPage = Math.min(28, Math.max(4, ...top.map((r) => r.page.length)));
6983
+ for (const r of top) {
6984
+ const what = describe ? describe[r.kind] ?? "" : "";
6985
+ const left = ` ${c.bold(n(r.count).padStart(wCount))} ${r.kind.padEnd(wKind)} ${c.cyan(clean(r.page, wPage).padEnd(wPage))}`;
6986
+ const room = width() - 4 - wCount - wKind - wPage - 8;
6987
+ out(`${left}${what && room > 16 ? ` ${c.gray(clean(what, room))}` : ""}`.trimEnd());
6988
+ }
6989
+ if (list.length > shown) out(` ${c.gray(`and ${n(list.length - shown)} more: genclass dashboard --all`)}`);
6990
+ }
6991
+ function render(app, state, o = {}) {
6992
+ const all = !!o.all;
6993
+ const t = app.totals;
6994
+ const line = spark(app.series);
6995
+ const cell = (label, value) => `${c.gray(label.padEnd(15))}${c.bold(String(value).padEnd(9))}`;
6996
+ out(` ${c.gray(RANGE_WORDS[app.range] ?? app.range)}${app.lastEvent ? c.gray(` \xB7 last page ${ago(app.lastEvent, o.now)}`) : ""}`);
6997
+ out();
6998
+ out(` ${cell("Visits watched", n(t.visits))} ${cell("Problems found", n(t.found))}${line ? ` ${c.green(line)}` : ""}`.trimEnd());
6999
+ out(` ${cell("Handled", n(t.handled))} ${cell("Visual checks", n(t.checks))}`.trimEnd());
7000
+ if (!t.visits && !t.found && !t.checks) {
7001
+ out();
7002
+ note(app.lastEvent ? "Nothing in this period. Try a longer one: genclass dashboard --range 30d" : "Nothing received yet. GenClass sends nothing from localhost: deploy your app, open the live site once, and run this again.");
7003
+ } else if (!t.found && !t.checks) {
7004
+ out();
7005
+ out(` ${c.green(sym.ok)} No problems found in this period.`);
7006
+ }
7007
+ table("Problems", rows(app.problems), all ? 200 : 5, KINDS);
7008
+ if (all) table("Possible problems (lower confidence)", rows(app.possible), 200, KINDS);
7009
+ table("Visual checks", rows(app.checks), all ? 200 : 3, null);
7010
+ if (all && app.recent.length) {
7011
+ out();
7012
+ out(` ${c.bold("Latest")}`);
7013
+ for (const r of app.recent) out(` ${c.gray(ago(r.at, o.now).padEnd(15))}${clean(r.kind ?? "", 22).padEnd(22)} ${c.cyan(clean(r.route ?? "", 40))}${r.handled ? c.gray(" handled") : ""}`.trimEnd());
7014
+ }
7015
+ out();
7016
+ const part = (label, text) => out(` ${c.bold(label.padEnd(15))}${text}`);
7017
+ if (app.visitors) {
7018
+ const v = app.visitors;
7019
+ const bounce = v.visits ? ` \xB7 ${Math.round(v.bounces / v.visits * 100)}% left after one page` : "";
7020
+ part("Visitors", v.visits ? `${plural2(v.visits, "visit")} \xB7 ${plural2(v.pages, "page view")}${bounce}` : c.gray("none counted in this period (analytics is opt-in: genclass.dev/docs)"));
7021
+ if (v.visits && v.entry.length) out(` ${" ".repeat(15)}${c.gray(`came in on ${v.entry.slice(0, all ? 10 : 3).map((e) => `${clean(e.key, 30)} (${n(e.count)})`).join(", ")}`)}`);
7022
+ } else if (app.visitorsPlan) part("Visitors", c.gray(`visitor analytics come with the ${clean(app.visitorsPlan.plan ?? "Team", 20)} plan${app.visitorsPlan.upgradeUrl ? `: ${app.visitorsPlan.upgradeUrl}` : ""}`));
7023
+ const a = app.agent;
7024
+ const agentStep = state?.steps?.find((s) => s.id === "agent");
7025
+ part("Coding agent", a.found ? `${n(a.found)} found \xB7 ${n(a.reproduced)} reproduced \xB7 ${n(a.fixed)} fixed \xB7 ${n(a.closed)} with a test` : agentStep?.state === "done" ? c.gray("connected \xB7 nothing reported in this period") : c.gray("not connected yet: genclass setup"));
7026
+ const gh = state?.steps?.find((s) => s.id === "github-app");
7027
+ if (gh) part("GitHub App", gh.state === "done" ? clean(gh.detail, 60) : c.gray(gh.detail ? clean(gh.detail, 60) : gh.state === "optional" ? "not used in this project" : "not connected yet: genclass setup"));
7028
+ const sg = state?.steps?.find((s) => s.id === "suggestions");
7029
+ if (sg) part("Suggestions", sg.detail ? sg.state === "done" ? clean(sg.detail, 60) : `${clean(sg.detail, 60)}${c.gray(" \xB7 genclass suggest")}` : c.gray("not run yet: genclass suggest"));
7030
+ out();
7031
+ if (app.dashboardUrl) out(` ${c.gray("In the browser")} ${c.cyan(app.dashboardUrl)} ${c.gray("(genclass dashboard --open)")}`);
7032
+ if (!all) out(` ${c.gray("Every row: genclass dashboard --all \xB7 another period: --range 24h, 7d or 30d")}`);
7033
+ out();
7034
+ }
7035
+ async function dashboard2(o = {}, deps = {}) {
7036
+ const range = ["24h", "7d", "30d", "90d", "1y"].includes(o.range) ? o.range : "7d";
7037
+ let state = await readState({ cwd: o.cwd }, deps);
7038
+ if (!state.signedIn) {
7039
+ if (!o.json && deps.fallback) return deps.fallback();
7040
+ if (o.json) out(JSON.stringify({ ok: false, error: "not signed in", run: "genclass login" }));
7041
+ else {
7042
+ header({ app: state.app.name, framework: state.app.framework, host: state.host });
7043
+ note(state.sessionProblem && state.sessionProblem !== "expired" ? `Could not reach genclass.dev (${state.sessionProblem}).` : "Sign in to see your app here: genclass login (or just genclass, which walks you through it).");
7044
+ out();
7045
+ }
7046
+ return 1;
7047
+ }
7048
+ const { creds } = readCredentialsFor();
7049
+ const projects = state.projects;
7050
+ const wanted = o.app ? projects.filter((p) => p.name.toLowerCase() === String(o.app).toLowerCase() || p.id === o.app) : state.app.token ? projects.filter((p) => p.token === state.app.token) : projects.length === 1 ? projects : [];
7051
+ if (wanted.length !== 1) {
7052
+ if (o.json) out(JSON.stringify({ ok: false, error: projects.length ? "which app" : "no app yet", apps: projects.map((p) => p.name) }));
7053
+ else {
7054
+ header({ app: state.app.name, framework: state.app.framework, account: state.account?.label, plan: state.account?.plan?.name, host: state.host });
7055
+ if (!projects.length) note("No app in your account yet. Run genclass in your web app's folder: it adds GenClass and gives the app its dashboard.");
7056
+ else {
7057
+ note(o.app ? `No app named "${clean(o.app, 40)}" in your account. Your apps:` : state.app.token ? "This folder's app is not in your account yet (genclass puts it there). Your apps:" : "Which app? Run this in the app's folder, or name one:");
7058
+ for (const p of projects.slice(0, 30)) out(` ${c.cyan(`genclass dashboard --app "${clean(p.name, 40)}"`)}${p.last_event ? c.gray(` last page ${ago(p.last_event, deps.now)}`) : ""}`);
7059
+ }
7060
+ out();
7061
+ }
7062
+ return projects.length ? 2 : 1;
7063
+ }
7064
+ const target = wanted[0];
7065
+ if (o.open && target.dashboard_url) openBrowser2(target.dashboard_url, o);
7066
+ let app = await fetchApp(creds, target.id, range, deps);
7067
+ if (!app.ok && app.reauth && !o.json && interactive()) {
7068
+ header({ app: target.name, framework: state.app.framework, account: state.account?.label, plan: state.account?.plan?.name, host: state.host });
7069
+ note("This sign-in is from before the command could show dashboards, so it was not approved for that. Signing in once more fixes it.");
7070
+ const a = await typed(` ${c.bold("Enter")} ${c.gray("to sign in again,")} ${c.bold("q")} ${c.gray("to stop")} `);
7071
+ if (a === null || /^q/i.test(a)) return 1;
7072
+ if (await signIn(o) !== "done") return 1;
7073
+ const again = readCredentialsFor().creds;
7074
+ state = await readState({ cwd: o.cwd }, deps);
7075
+ app = await fetchApp(again, target.id, range, deps);
7076
+ }
7077
+ if (!app.ok) {
7078
+ if (o.json) out(JSON.stringify({ ok: false, error: app.reauth ? "sign in again" : app.reason, run: app.reauth ? "genclass login" : null, dashboard_url: target.dashboard_url }));
7079
+ else {
7080
+ header({ app: target.name, framework: state.app.framework, account: state.account?.label, plan: state.account?.plan?.name, host: state.host });
7081
+ if (app.reauth) warn(`This sign-in is from before the command could show dashboards. Run ${c.cyan("genclass login")} once, then ${c.cyan("genclass dashboard")}.`);
7082
+ else if (app.missing) note("This genclass.dev cannot show a dashboard in the terminal yet.");
7083
+ else bad(`Could not read the dashboard: ${clean(app.reason, 200)}`);
7084
+ if (target.dashboard_url) out(` ${c.gray("In the browser")} ${c.cyan(target.dashboard_url)}`);
7085
+ else out(` ${c.gray("Your apps")} ${c.cyan(hostUrl("/account"))}`);
7086
+ out();
7087
+ }
7088
+ return 1;
7089
+ }
7090
+ if (o.json) {
7091
+ out(JSON.stringify({ ok: true, app: target.name, ...app, github_app: state.steps.find((s) => s.id === "github-app")?.detail ?? null }, null, 2));
7092
+ return 0;
7093
+ }
7094
+ header({ app: target.name, framework: state.app.token === target.token ? state.app.framework : null, account: state.account?.label, plan: state.account?.plan?.name, host: state.host });
7095
+ render(app, state.app.token === target.token ? state : { steps: [] }, { all: o.all, now: deps.now });
7096
+ return 0;
7097
+ }
7098
+ var KINDS, RANGE_WORDS, BARS, n, plural2, rows;
7099
+ var init_app = __esm({
7100
+ "src/app.mjs"() {
7101
+ init_define_GENCLASS_BUILD();
7102
+ init_account();
7103
+ init_host();
7104
+ init_ui();
7105
+ init_actions();
7106
+ init_api();
7107
+ init_state();
7108
+ init_tui();
7109
+ KINDS = {
7110
+ stale: "old data replaced newer data",
7111
+ conflict: "two operations competed over the same data",
7112
+ duplicate: "the same request went out twice",
7113
+ inconsistent: "the page's state contradicted itself",
7114
+ failing: "a request keeps failing",
7115
+ slow: "a request was far slower than usual",
7116
+ overload: "work was triggered far too often",
7117
+ unusual: "an operation behaved unlike it normally does",
7118
+ transient: "a one-off failure"
7119
+ };
7120
+ RANGE_WORDS = { "24h": "last 24 hours", "7d": "last 7 days", "30d": "last 30 days", "90d": "last 90 days", "1y": "last year" };
7121
+ BARS = ["\u2581", "\u2582", "\u2583", "\u2584", "\u2585", "\u2586", "\u2587", "\u2588"];
7122
+ n = (v) => Number(v).toLocaleString("en-US");
7123
+ plural2 = (v, one, many = `${one}s`) => `${n(v)} ${v === 1 ? one : many}`;
7124
+ rows = (list) => list.map((x) => {
7125
+ const i = x.key.indexOf(" ");
7126
+ return { kind: clean(i < 0 ? x.key : x.key.slice(0, i), 40), page: clean(i < 0 ? "" : x.key.slice(i + 1), 60), count: x.count };
7127
+ });
7128
+ }
7129
+ });
7130
+
7131
+ // src/art.mjs
7132
+ function blockRows(word) {
7133
+ const letters = [...word].map((ch) => LETTERS[ch]);
7134
+ return [0, 1, 2, 3, 4, 5].map((r) => letters.map((l) => l[r]).join(""));
7135
+ }
7136
+ function canDraw(columns = process.stdout.columns, env2 = process.env, platform = process.platform) {
7137
+ const unicode3 = platform !== "win32" || !!env2.WT_SESSION || !!env2.TERM_PROGRAM;
7138
+ return !!process.stdout.isTTY && unicode3 && env2.TERM !== "dumb" && Number(columns) >= WORDMARK[0].length + 4;
7139
+ }
7140
+ function opening(version2, tagline = "Finds what breaks in your web app, and tells you what it needs next.") {
7141
+ const truecolor = useColor && /truecolor|24bit/i.test(process.env.COLORTERM ?? "");
7142
+ out();
7143
+ if (canDraw()) {
7144
+ WORDMARK.forEach((row2, i) => {
7145
+ const [r, g, b] = SHADES[i];
7146
+ out(` ${truecolor ? `\x1B[38;2;${r};${g};${b}m${row2}\x1B[39m` : c.green(row2)}`);
7147
+ });
7148
+ out();
7149
+ } else out(` ${c.bold(c.green("GenClass"))}`);
7150
+ out(` ${tagline} ${c.gray(`v${version2}`)}`);
7151
+ }
7152
+ var LETTERS, WORDMARK, SHADES;
7153
+ var init_art = __esm({
7154
+ "src/art.mjs"() {
7155
+ init_define_GENCLASS_BUILD();
7156
+ init_ui();
7157
+ LETTERS = {
7158
+ G: [" \u2588\u2588\u2588\u2588\u2588\u2588\u2557 ", "\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D ", "\u2588\u2588\u2551 \u2588\u2588\u2588\u2557", "\u2588\u2588\u2551 \u2588\u2588\u2551", "\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2554\u255D", " \u255A\u2550\u2550\u2550\u2550\u2550\u255D "],
7159
+ E: ["\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557", "\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D", "\u2588\u2588\u2588\u2588\u2588\u2557 ", "\u2588\u2588\u2554\u2550\u2550\u255D ", "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557", "\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D"],
7160
+ N: ["\u2588\u2588\u2588\u2557 \u2588\u2588\u2557", "\u2588\u2588\u2588\u2588\u2557 \u2588\u2588\u2551", "\u2588\u2588\u2554\u2588\u2588\u2557 \u2588\u2588\u2551", "\u2588\u2588\u2551\u255A\u2588\u2588\u2557\u2588\u2588\u2551", "\u2588\u2588\u2551 \u255A\u2588\u2588\u2588\u2588\u2551", "\u255A\u2550\u255D \u255A\u2550\u2550\u2550\u255D"],
7161
+ C: [" \u2588\u2588\u2588\u2588\u2588\u2588\u2557", "\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D", "\u2588\u2588\u2551 ", "\u2588\u2588\u2551 ", "\u255A\u2588\u2588\u2588\u2588\u2588\u2588\u2557", " \u255A\u2550\u2550\u2550\u2550\u2550\u255D"],
7162
+ L: ["\u2588\u2588\u2557 ", "\u2588\u2588\u2551 ", "\u2588\u2588\u2551 ", "\u2588\u2588\u2551 ", "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557", "\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D"],
7163
+ A: [" \u2588\u2588\u2588\u2588\u2588\u2557 ", "\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2557", "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551", "\u2588\u2588\u2554\u2550\u2550\u2588\u2588\u2551", "\u2588\u2588\u2551 \u2588\u2588\u2551", "\u255A\u2550\u255D \u255A\u2550\u255D"],
7164
+ S: ["\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557", "\u2588\u2588\u2554\u2550\u2550\u2550\u2550\u255D", "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2557", "\u255A\u2550\u2550\u2550\u2550\u2588\u2588\u2551", "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2551", "\u255A\u2550\u2550\u2550\u2550\u2550\u2550\u255D"]
7165
+ };
7166
+ WORDMARK = blockRows("GENCLASS");
7167
+ SHADES = [
7168
+ [150, 245, 190],
7169
+ [120, 236, 170],
7170
+ [90, 226, 150],
7171
+ [64, 214, 134],
7172
+ [47, 198, 120],
7173
+ [29, 179, 106]
7174
+ ];
7175
+ }
7176
+ });
7177
+
6870
7178
  // src/setup.mjs
6871
7179
  var setup_exports = {};
6872
7180
  __export(setup_exports, {
@@ -6874,9 +7182,14 @@ __export(setup_exports, {
6874
7182
  show: () => show,
6875
7183
  status: () => status
6876
7184
  });
6877
- function show(state) {
7185
+ function show(state, details = false) {
6878
7186
  header({ app: state.app.name, framework: state.app.framework, account: state.account?.label ?? null, plan: state.account?.plan?.name ?? null, host: state.host });
6879
- checklist(state.steps);
7187
+ if (details) checklist(state.steps);
7188
+ else summary(state.steps);
7189
+ }
7190
+ function showNext(step, details) {
7191
+ nextBlock(step.doing, step.why);
7192
+ if (details && step.more) para(step.more, " ", c.gray);
6880
7193
  }
6881
7194
  function closing(state) {
6882
7195
  out();
@@ -6892,7 +7205,7 @@ function closing(state) {
6892
7205
  out(` ${c.gray("Day to day")}`);
6893
7206
  out(` ${c.cyan("genclass".padEnd(20))}${c.gray("where things stand and what comes next")}`);
6894
7207
  out(` ${c.cyan("genclass suggest".padEnd(20))}${c.gray("what your app is missing, most important first")}`);
6895
- if (state.app.token) out(` ${c.cyan("genclass dashboard".padEnd(20))}${c.gray("what GenClass found on your live site")}`);
7208
+ if (state.app.token) out(` ${c.cyan("genclass dashboard".padEnd(20))}${c.gray("what GenClass found on your live site, here in the terminal")}`);
6896
7209
  out();
6897
7210
  }
6898
7211
  async function status(o = {}) {
@@ -6901,12 +7214,13 @@ async function status(o = {}) {
6901
7214
  out(JSON.stringify(stateJson(state), null, 2));
6902
7215
  return 0;
6903
7216
  }
6904
- show(state);
7217
+ show(state, !!o.all);
6905
7218
  const step = state.next;
6906
7219
  if (step) {
6907
- nextBlock(DOING[step.id] ?? step.title, step.why);
7220
+ showNext(step, !!o.all);
6908
7221
  out();
6909
7222
  out(` ${c.gray("Run")} ${c.cyan(step.run ?? "genclass setup")}${step.human ? c.gray(` (then: ${step.human})`) : ""}`);
7223
+ if (!o.all) out(` ${c.gray("Every part:")} ${c.cyan("genclass status --all")}`);
6910
7224
  out();
6911
7225
  } else closing(state);
6912
7226
  return 0;
@@ -6916,35 +7230,47 @@ async function setup(o = {}, deps = {}) {
6916
7230
  if (!auto && !interactive()) return status(o);
6917
7231
  const skip2 = [];
6918
7232
  let failed = false;
6919
- for (let turn = 0; turn < 12; turn++) {
7233
+ let details = !!o.all;
7234
+ if (!auto) opening(BUILD.version);
7235
+ for (let turn = 0; turn < 14; turn++) {
6920
7236
  const state = await readState({ cwd: o.cwd, skip: skip2 });
6921
- show(state);
6922
7237
  const step = state.next;
6923
- if (!step) {
6924
- closing(state);
6925
- break;
6926
- }
6927
- nextBlock(DOING[step.id] ?? step.title, step.why);
6928
- out();
6929
- if (!auto) {
6930
- const a = await typed(` ${c.bold("Enter")} ${c.gray("to continue,")} ${c.bold("s")} ${c.gray("to skip,")} ${c.bold("q")} ${c.gray("to stop")} `) ?? "q";
7238
+ let go = auto;
7239
+ for (; ; ) {
7240
+ show(state, details);
7241
+ if (!step) break;
7242
+ showNext(step, details);
7243
+ out();
7244
+ if (auto) break;
7245
+ const keys = ` ${c.bold("Enter")} ${c.gray("to continue,")} ${c.bold("d")} ${c.gray(details ? "for less," : "for every part,")} ${c.bold("s")} ${c.gray("to skip,")} ${c.bold("q")} ${c.gray("to stop")} `;
7246
+ const a = await typed(keys) ?? "q";
7247
+ if (/^d/i.test(a)) {
7248
+ details = !details;
7249
+ continue;
7250
+ }
6931
7251
  if (/^q/i.test(a)) {
6932
7252
  out();
6933
7253
  note("Stopped. Run genclass again any time: it continues from here.");
6934
7254
  out();
6935
7255
  return 0;
6936
7256
  }
6937
- if (/^s/i.test(a)) {
6938
- skip2.push(step.id);
6939
- continue;
6940
- }
7257
+ if (/^s/i.test(a)) skip2.push(step.id);
7258
+ else go = true;
7259
+ break;
6941
7260
  }
7261
+ if (!step) {
7262
+ closing(state);
7263
+ break;
7264
+ }
7265
+ if (!go) continue;
7266
+ const so = { ...o, confirmed: true };
6942
7267
  let result = "skipped";
6943
- if (step.id === "account") result = await signIn(o);
6944
- else if (step.id === "runtime") result = await addRuntime(state, o);
6945
- else if (step.id === "first-page") result = await watchFirstPage(state, o);
6946
- else if (step.id === "pull-requests") result = await setUpPullRequests(state, o);
6947
- else if (step.id === "agent") result = await connectAgent(state, o);
7268
+ if (step.id === "account") result = await signIn(so);
7269
+ else if (step.id === "runtime") result = await addRuntime(state, so);
7270
+ else if (step.id === "dashboard") result = await watchFirstPage(state, so);
7271
+ else if (step.id === "workflow") result = await addWorkflow(state, so);
7272
+ else if (step.id === "github-app") result = await connectGithubApp(state, so);
7273
+ else if (step.id === "agent") result = await connectAgent(state, so);
6948
7274
  else if (step.id === "suggestions") {
6949
7275
  if (auto || !deps.runSuggest) {
6950
7276
  note(`Run ${c.cyan("genclass suggest")} to see what your app is missing.`);
@@ -6959,22 +7285,15 @@ async function setup(o = {}, deps = {}) {
6959
7285
  if (o.json) out(JSON.stringify(stateJson(await readState({ cwd: o.cwd })), null, 2));
6960
7286
  return failed ? 1 : 0;
6961
7287
  }
6962
- var DOING;
6963
7288
  var init_setup = __esm({
6964
7289
  "src/setup.mjs"() {
6965
7290
  init_define_GENCLASS_BUILD();
6966
7291
  init_ui();
6967
7292
  init_actions();
7293
+ init_art();
7294
+ init_assets();
6968
7295
  init_state();
6969
7296
  init_tui();
6970
- DOING = {
6971
- account: "Sign in to GenClass",
6972
- runtime: "Add GenClass to this app",
6973
- "first-page": "See your first page",
6974
- "pull-requests": "Check every pull request",
6975
- agent: "Connect your coding agent",
6976
- suggestions: "See what your app is missing"
6977
- };
6978
7297
  }
6979
7298
  });
6980
7299
 
@@ -7004,7 +7323,7 @@ function parseArgs2(argv) {
7004
7323
  async function run4(argv) {
7005
7324
  const cmd = argv[0] && !argv[0].startsWith("-") ? argv[0] : null;
7006
7325
  const args = cmd ? argv.slice(1) : argv;
7007
- if (["login", "logout", "whoami", "connect", "dashboard"].includes(cmd)) return (await Promise.resolve().then(() => (init_login(), login_exports))).run(cmd, args);
7326
+ if (["login", "logout", "whoami", "connect"].includes(cmd)) return (await Promise.resolve().then(() => (init_login(), login_exports))).run(cmd, args);
7008
7327
  if (cmd === "init" || cmd === "remove") return (await Promise.resolve().then(() => (init_init(), init_exports))).run(cmd, args);
7009
7328
  if (cmd === "scan" || cmd === "audit") {
7010
7329
  const withHost = args.includes("--local") || args.includes("--hosted") || args.includes("--help") ? args : [...args, "--hosted"];
@@ -7048,6 +7367,10 @@ ${USAGE4}`);
7048
7367
  ${USAGE4}`);
7049
7368
  return 2;
7050
7369
  }
7370
+ if (cmd === "dashboard") {
7371
+ const fallback = async () => (await Promise.resolve().then(() => (init_login(), login_exports))).run("dashboard", args);
7372
+ return (await Promise.resolve().then(() => (init_app(), app_exports))).dashboard(o, { fallback });
7373
+ }
7051
7374
  const { setup: setup2, status: status2 } = await Promise.resolve().then(() => (init_setup(), setup_exports));
7052
7375
  if (cmd === "status") return status2(o);
7053
7376
  if (cmd === "setup" || cmd === null) return setup2(o, { runSuggest });
@@ -7067,18 +7390,19 @@ var init_cli = __esm({
7067
7390
 
7068
7391
  genclass where this project stands; on a terminal it walks you through the next step
7069
7392
  genclass setup the guided setup (--yes: no questions, for a coding agent)
7070
- genclass status the checklist (--json: for a coding agent)
7393
+ genclass status what is done, what is next (--all: every part; --json: for a coding agent)
7071
7394
  genclass suggest [url] what your app is missing, most important first (--json, --yes, --no-model, --all)
7072
- genclass dashboard this app's dashboard (--open)
7395
+ genclass dashboard your app, whole: problems found, checks, visitors, agent, GitHub App
7396
+ (--range 24h|7d|30d, --all, --app <name>, --open, --json)
7073
7397
  genclass scan <url> 23 visual checks on one page
7074
7398
  genclass login sign in (logout, whoami)
7075
7399
  genclass remove take GenClass out of this app again
7076
7400
 
7077
7401
  Options: --cwd <dir> --yes --json --no-browser --help --version
7078
7402
 
7079
- Everything GenClass sets up is listed by "genclass status". Docs: https://genclass.dev/docs`;
7403
+ Every part GenClass sets up is listed by "genclass status --all". Docs: https://genclass.dev/docs`;
7080
7404
  BOOL2 = { yes: "yes", y: "yes", json: "json", "no-browser": "noBrowser", "no-model": "noModel", all: "all", help: "help", h: "help", version: "version", v: "version", open: "open" };
7081
- VALUE2 = { cwd: "cwd", url: "url" };
7405
+ VALUE2 = { cwd: "cwd", url: "url", app: "app", range: "range" };
7082
7406
  }
7083
7407
  });
7084
7408