@mushi-mushi/ux 0.1.2 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -175,6 +175,23 @@ interface ProbeResult {
175
175
  consoleErrors: string[];
176
176
  /** Cumulative layout shift observed while the surface settled. */
177
177
  cls: number;
178
+ /**
179
+ * Boxes that collide or stick out of their container. Absent in runs
180
+ * captured before 2026-10-26.
181
+ */
182
+ layout?: LayoutIssue[];
183
+ }
184
+ interface LayoutIssue {
185
+ /**
186
+ * `overlap`: two in-flow siblings drawn on top of each other.
187
+ * `outgrows`: a control wider than its container, sticking past its edge,
188
+ * wrapping past two lines or cutting its own label off.
189
+ */
190
+ kind: 'overlap' | 'outgrows';
191
+ /** Short CSS-ish name of the element, with its text. */
192
+ selector: string;
193
+ /** What was measured, in px. */
194
+ detail: string;
178
195
  }
179
196
 
180
197
  /**
@@ -211,8 +228,14 @@ interface BrowserSession {
211
228
  close(): Promise<void>;
212
229
  }
213
230
  interface SessionOptions {
214
- /** Persistent profile directory from `mushi-ux login`; omit for a clean browser. */
231
+ /** Persistent profile directory from `mushi-ux login`, or `--profile-dir` (a cached, signed-in profile); omit for a clean browser. */
215
232
  profileDir?: string;
233
+ /**
234
+ * Browser build to open it with. 'chrome' opens a profile Google Chrome
235
+ * created (playwright-cli's cached profiles) with the installed Chrome; the
236
+ * bundled Chromium is older and may refuse or rewrite such a profile.
237
+ */
238
+ channel?: 'chrome' | 'chromium';
216
239
  headless?: boolean;
217
240
  allow?: readonly AllowRule[];
218
241
  /** Extra selectors to ignore on top of DEFAULT_IGNORE. */
@@ -282,6 +305,20 @@ interface DiscoverOptions {
282
305
  maxStatesPerPage?: number;
283
306
  /** Paths never visited (globs on pathname), on top of sign-out routes. */
284
307
  excludePaths?: string[];
308
+ /**
309
+ * Only pathnames equal to or under this prefix are visited, e.g.
310
+ * `/mushi-mushi/admin` for a console that shares its origin with docs and
311
+ * a landing site. Omit for the whole origin.
312
+ */
313
+ scopePath?: string;
314
+ /**
315
+ * When two pages count as the same: 'shape' (default) by DOM structure, so
316
+ * `/reports/1` and `/reports/2` are worked on once; 'route' by pathname with
317
+ * ids collapsed and the query ignored, for an app shell whose sidebar and
318
+ * header make every page hash alike (the console kept 3 of 75 loads by
319
+ * shape, 2026-10-24).
320
+ */
321
+ dedupe?: 'shape' | 'route';
285
322
  /**
286
323
  * Visit only startPaths (and the tabs, dialogs and menus they open): no
287
324
  * routes from the source or sitemap, no following links. Set when the
@@ -353,10 +390,12 @@ declare function hammingHex(a: string, b: string): number;
353
390
  * reviewed from its diff and the step it was meant to make.
354
391
  *
355
392
  * Transports: Claude Code (`claude -p`, the person's own sign-in, read-only
356
- * tools) or the Anthropic API (ANTHROPIC_API_KEY).
393
+ * tools), the Anthropic API (ANTHROPIC_API_KEY), or the Cursor CLI
394
+ * (`cursor-agent -p --mode ask`, read-only, any model the Cursor account has,
395
+ * e.g. Grok: a cheaper allowance for screenshot reviews).
357
396
  */
358
397
 
359
- type CheckerVia = 'claude-code' | 'anthropic-api';
398
+ type CheckerVia = 'claude-code' | 'anthropic-api' | 'cursor';
360
399
  interface CheckerSpec {
361
400
  via: CheckerVia;
362
401
  model: string;
@@ -518,7 +557,7 @@ interface SavedRunOptions {
518
557
  steps?: boolean;
519
558
  /** The reviewing model that may veto a kept step (ADR 0021). */
520
559
  checker?: {
521
- via: 'claude-code' | 'anthropic-api';
560
+ via: 'claude-code' | 'anthropic-api' | 'cursor';
522
561
  model: string;
523
562
  } | null;
524
563
  /** Keep edits with nothing visible, flagged for review. */
@@ -742,6 +781,8 @@ interface LoopOptions {
742
781
  /** Selectors that are not the app's UI, on top of DEFAULT_IGNORE (ignore.ts). */
743
782
  ignore?: string[];
744
783
  profileDir?: string;
784
+ /** Browser build for profileDir: 'chrome' for a profile Google Chrome made (`--profile-dir`). */
785
+ channel?: 'chrome' | 'chromium';
745
786
  regressionSample?: number;
746
787
  /** Model for the final pairwise review; null turns it off. */
747
788
  judgeModel?: string | null;
@@ -1001,4 +1042,4 @@ interface Verdict {
1001
1042
  }
1002
1043
  declare function decide(input: VerdictInput): Verdict;
1003
1044
 
1004
- export { AGENTS, type AgentAdapter, type AgentName, type AgentRunOptions, type AllowRule, type AxeViolation, type BrowserSession, type Capture, type CursorCloudDeps, DEFAULT_JUDGE_MODEL, type Dashboard, type DiscoverOptions, type IterationRecord, type JudgeClaim, type JudgeOptions, type JudgeVerdict, type LoopEvent, type LoopHandle, type LoopOptions, POINTER_PROMPT, type PacketInput, type ProbeResult, type ReplayStep, type RunState, type Surface, type SurfaceKind, type SurfaceState, type SurfaceStatus, type SyncConfig, type SyncHandle, VIEWPORTS, type Verdict, type VerdictInput, type Viewport, buildPacket, captureSurface, cropTop, cursorCloudAdapter, cursorModel, dHash, decide, discover, findDesignFiles, getAgent, hammingHex, httpsRepoUrl, installGuard, isDestructiveLabel, isRequestAllowed, judgeSurface, loadState, newRunId, nextRoutePath, normalizeLink, openSession, pixelDiff, probePenalty, quoteArg, reactRouterPaths, routesFromSource, runDir, runProbes, safeShotPath, saveState, settle, sitemapPaths, startDashboard, startLoop, startSync, surfaceKey, syncConfigFromEnv, toSnapshot, unshuffle };
1045
+ export { AGENTS, type AgentAdapter, type AgentName, type AgentRunOptions, type AllowRule, type AxeViolation, type BrowserSession, type Capture, type CursorCloudDeps, DEFAULT_JUDGE_MODEL, type Dashboard, type DiscoverOptions, type IterationRecord, type JudgeClaim, type JudgeOptions, type JudgeVerdict, type LayoutIssue, type LoopEvent, type LoopHandle, type LoopOptions, POINTER_PROMPT, type PacketInput, type ProbeResult, type ReplayStep, type RunState, type Surface, type SurfaceKind, type SurfaceState, type SurfaceStatus, type SyncConfig, type SyncHandle, VIEWPORTS, type Verdict, type VerdictInput, type Viewport, buildPacket, captureSurface, cropTop, cursorCloudAdapter, cursorModel, dHash, decide, discover, findDesignFiles, getAgent, hammingHex, httpsRepoUrl, installGuard, isDestructiveLabel, isRequestAllowed, judgeSurface, loadState, newRunId, nextRoutePath, normalizeLink, openSession, pixelDiff, probePenalty, quoteArg, reactRouterPaths, routesFromSource, runDir, runProbes, safeShotPath, saveState, settle, sitemapPaths, startDashboard, startLoop, startSync, surfaceKey, syncConfigFromEnv, toSnapshot, unshuffle };
package/dist/index.js CHANGED
@@ -606,9 +606,93 @@ async function runProbes(page, consoleErrors, ignore = []) {
606
606
  overflowX: layout.overflowX,
607
607
  smallTargets: layout.smallTargets,
608
608
  consoleErrors: [...consoleErrors],
609
- cls: Math.round(layout.cls * 1e3) / 1e3
609
+ cls: Math.round(layout.cls * 1e3) / 1e3,
610
+ layout: await layoutIssues(page, skip)
610
611
  };
611
612
  }
613
+ var MAX_LAYOUT_ISSUES = 8;
614
+ var LAYOUT_SLOP_PX = 4;
615
+ async function layoutIssues(page, skipSelectors) {
616
+ return page.evaluate(
617
+ ({ skipSelectors: skipSelectors2, max, slop }) => {
618
+ const out = [];
619
+ const seen = /* @__PURE__ */ new Set();
620
+ const add = (kind, el, detail) => {
621
+ const selector = nameOf(el);
622
+ if (seen.has(kind + selector) || out.filter((i) => i.kind === kind).length >= max) return;
623
+ seen.add(kind + selector);
624
+ out.push({ kind, selector, detail });
625
+ };
626
+ function nameOf(el) {
627
+ const id = el.id ? `#${el.id}` : "";
628
+ const cls = typeof el.className === "string" ? el.className.trim().split(/\s+/).filter(Boolean).slice(0, 2).map((c) => `.${c}`).join("") : "";
629
+ const text = (el.textContent ?? "").replace(/\s+/g, " ").trim().slice(0, 40);
630
+ return `${el.tagName.toLowerCase()}${id}${cls}${text ? ` "${text}"` : ""}`;
631
+ }
632
+ const px = (v) => parseFloat(v) || 0;
633
+ const skipped = (el) => skipSelectors2.some((sel) => el.closest(sel));
634
+ const visible = (s, r) => s.display !== "none" && s.visibility !== "hidden" && Number(s.opacity) > 0.05 && r.width > 0 && r.height > 0;
635
+ const placed = (s) => s.position === "relative" && (s.top !== "auto" && px(s.top) !== 0 || s.left !== "auto" && px(s.left) !== 0) || s.transform !== "none" || px(s.marginLeft) < 0 || px(s.marginTop) < 0 || px(s.marginRight) < 0 || px(s.marginBottom) < 0;
636
+ for (const parent of Array.from(document.querySelectorAll("body *"))) {
637
+ if (parent.childElementCount < 2 || skipped(parent)) continue;
638
+ const ps = getComputedStyle(parent);
639
+ const kids = Array.from(parent.children).slice(0, 40).map((el) => ({ el, s: getComputedStyle(el), r: el.getBoundingClientRect() })).filter(
640
+ ({ el, s, r }) => visible(s, r) && (s.position === "static" || s.position === "relative") && s.display !== "inline" && s.display !== "contents" && s.float === "none" && !placed(s) && !skipped(el)
641
+ );
642
+ for (let i = 0; i < kids.length; i++) {
643
+ for (let j = i + 1; j < kids.length; j++) {
644
+ const a = kids[i];
645
+ const b = kids[j];
646
+ if (ps.display.includes("grid") && a.s.gridArea === b.s.gridArea && !a.s.gridArea.startsWith("auto")) continue;
647
+ const w = Math.min(a.r.right, b.r.right) - Math.max(a.r.left, b.r.left);
648
+ const h = Math.min(a.r.bottom, b.r.bottom) - Math.max(a.r.top, b.r.top);
649
+ if (w > slop && h > slop) {
650
+ add("overlap", b.el, `overlaps ${nameOf(a.el)} by ${Math.round(w)}\xD7${Math.round(h)}px`);
651
+ }
652
+ }
653
+ }
654
+ }
655
+ const controls = document.querySelectorAll("button, [role=button], a[href], input[type=submit], input[type=button], select");
656
+ for (const el of Array.from(controls)) {
657
+ if (skipped(el)) continue;
658
+ const s = getComputedStyle(el);
659
+ const r = el.getBoundingClientRect();
660
+ if (!visible(s, r) || s.position === "fixed" || s.position === "absolute" || placed(s)) continue;
661
+ if (el.tagName === "A" && s.display === "inline") continue;
662
+ let box = el.parentElement;
663
+ while (box && getComputedStyle(box).display === "contents") box = box.parentElement;
664
+ if (box) {
665
+ const bs = getComputedStyle(box);
666
+ const br = box.getBoundingClientRect();
667
+ const scrolls = /auto|scroll/.test(bs.overflowX);
668
+ if (!scrolls && br.width > 0) {
669
+ const right = r.right - br.right;
670
+ const left = br.left - r.left;
671
+ if (right > slop || left > slop) {
672
+ add("outgrows", el, `sticks ${Math.round(Math.max(right, left))}px out of its container (${Math.round(r.width)}px wide in ${Math.round(br.width)}px)`);
673
+ continue;
674
+ }
675
+ }
676
+ }
677
+ const labelOnly = Array.from(el.querySelectorAll("*")).every(
678
+ (c) => getComputedStyle(c).display.startsWith("inline") || c.closest("svg") !== null
679
+ );
680
+ const text = (el.textContent ?? "").trim();
681
+ if (!labelOnly || !text || el.tagName === "A") continue;
682
+ if (s.overflow !== "visible" && el.scrollWidth > el.clientWidth + 1 && s.textOverflow !== "ellipsis") {
683
+ add("outgrows", el, `label is cut off (needs ${el.scrollWidth}px, has ${el.clientWidth}px)`);
684
+ continue;
685
+ }
686
+ const line = px(s.lineHeight) || px(s.fontSize) * 1.2;
687
+ const inner = r.height - px(s.paddingTop) - px(s.paddingBottom) - px(s.borderTopWidth) - px(s.borderBottomWidth);
688
+ const lines = line > 0 ? Math.round(inner / line) : 1;
689
+ if (lines > 2) add("outgrows", el, `label wraps to ${lines} lines (${Math.round(r.width)}\xD7${Math.round(r.height)}px)`);
690
+ }
691
+ return out;
692
+ },
693
+ { skipSelectors: [...skipSelectors], max: MAX_LAYOUT_ISSUES, slop: LAYOUT_SLOP_PX }
694
+ );
695
+ }
612
696
  var FRAMEWORK_NOISE = [
613
697
  /Check the render method of `(OuterLayoutRouter|InnerLayoutRouter|LayoutRouter|SegmentViewNode|SegmentStateProvider|RenderFromTemplateContext|ScrollAndFocusHandler|HTTPAccessFallbackBoundary|RedirectBoundary|ErrorBoundaryHandler|AppRouter|HotReload|ReactDevOverlay)`/,
614
698
  /\[(Fast Refresh|HMR)\]/,
@@ -621,7 +705,7 @@ function isFrameworkNoise(message) {
621
705
  var IMPACT_WEIGHT = { critical: 8, serious: 4, moderate: 2, minor: 1 };
622
706
  function probePenalty(p) {
623
707
  const axe = p.axe.reduce((sum, v) => sum + (IMPACT_WEIGHT[v.impact ?? ""] ?? 1) * Math.max(1, v.count), 0);
624
- return axe + (p.overflowX ? 10 : 0) + p.smallTargets + p.consoleErrors.length * 5 + clsPenalty(p.cls);
708
+ return axe + (p.overflowX ? 10 : 0) + p.smallTargets + p.consoleErrors.length * 5 + clsPenalty(p.cls) + (p.layout?.length ?? 0) * 3;
625
709
  }
626
710
  var CLS_GOOD = 0.1;
627
711
  function clsPenalty(cls) {
@@ -642,15 +726,16 @@ async function openSession(opts = {}) {
642
726
  let context;
643
727
  let closeBrowser;
644
728
  let browser;
729
+ const channel = opts.channel === "chrome" ? { channel: "chrome" } : {};
645
730
  if (opts.profileDir) {
646
- context = await chromium.launchPersistentContext(opts.profileDir, { headless, serviceWorkers: "block" });
647
- browser = await chromium.launch({ headless });
731
+ context = await chromium.launchPersistentContext(opts.profileDir, { headless, serviceWorkers: "block", ...channel });
732
+ browser = await chromium.launch({ headless, ...channel });
648
733
  closeBrowser = async () => {
649
734
  await context.close();
650
735
  await browser.close();
651
736
  };
652
737
  } else {
653
- browser = await chromium.launch({ headless });
738
+ browser = await chromium.launch({ headless, ...channel });
654
739
  context = await browser.newContext({ serviceWorkers: "block" });
655
740
  closeBrowser = () => browser.close();
656
741
  }
@@ -1356,6 +1441,7 @@ function renderRun() {
1356
1441
  for (const a of probes.axe || []) lines.push(a.help + ' (' + a.count + ')')
1357
1442
  if (probes.overflowX) lines.push('Scrolls sideways')
1358
1443
  if (probes.smallTargets) lines.push(probes.smallTargets + ' tap target(s) under 24 px')
1444
+ for (const l of (probes.layout || []).slice(0, 4)) lines.push((l.kind === 'overlap' ? 'Overlap: ' : 'Too big: ') + l.selector + ' ' + l.detail)
1359
1445
  for (const e of (probes.consoleErrors || []).slice(0, 3)) lines.push('Console: ' + e)
1360
1446
  if (lines.length) problemsHtml = '<h3>Problems measured on ' + (after ? 'attempt ' + chosen.n : 'the baseline') + ' (' + vp + ')</h3><ul class="problems">' + lines.map((l) => '<li>' + esc(l) + '</li>').join('') + '</ul>'
1361
1447
  } else html += '<p class="empty">No screenshot yet.</p>'
@@ -1771,7 +1857,7 @@ var LaunchInput = z.object({
1771
1857
  steps: z.boolean().default(false),
1772
1858
  /** A second model that may roll a kept step back (ADR 0021); null = measurements alone. */
1773
1859
  checkerModel: z.string().max(120).regex(/^[A-Za-z0-9][A-Za-z0-9._:-]*$/).nullable().default(null),
1774
- checkerVia: z.enum(["claude-code", "anthropic-api"]).default("claude-code"),
1860
+ checkerVia: z.enum(["claude-code", "anthropic-api", "cursor"]).default("claude-code"),
1775
1861
  /** Keep edits with nothing visible, flagged for review. */
1776
1862
  keepInvisible: z.boolean().default(true),
1777
1863
  /** Selectors that are not the app's UI; added to DEFAULT_IGNORE. */
@@ -2107,8 +2193,13 @@ async function sitemapPaths(baseUrl) {
2107
2193
  }
2108
2194
  var COMPONENT_DIRS = ["_components", "components"];
2109
2195
  var MAX_SCREEN_FILES = 12;
2196
+ function trimTrailingSlashes(s) {
2197
+ let end = s.length;
2198
+ while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
2199
+ return s.slice(0, end);
2200
+ }
2110
2201
  function screenFiles(root, urlPath) {
2111
- const want = urlPath.split(/[?#]/)[0].replace(/\/+$/, "") || "/";
2202
+ const want = trimTrailingSlashes(urlPath.split(/[?#]/)[0]) || "/";
2112
2203
  let page = null;
2113
2204
  let files = 0;
2114
2205
  const walk = (dir2, depth) => {
@@ -2164,6 +2255,18 @@ var MAX_REDIRECT_FOLLOWS = 3;
2164
2255
  var LOADS_PER_PAGE = 5;
2165
2256
  var SIGN_IN_PATH_RE = /\/(log-?in|sign-?in|auth)\b/i;
2166
2257
  var SIGN_OUT_PATH_RE = /\/(log-?out|sign-?out|logoff)\b/i;
2258
+ function inScope(pathname, scope) {
2259
+ if (!scope) return true;
2260
+ const s = trimTrailingSlashes(scope) || "/";
2261
+ if (s === "/") return true;
2262
+ return pathname === s || pathname.startsWith(`${s}/`);
2263
+ }
2264
+ function routeKey(path) {
2265
+ const q = path.search(/[?#]/);
2266
+ const pathname = q < 0 ? path : path.slice(0, q);
2267
+ const collapsed = pathname.split("/").map((seg) => /^(\d+|[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}|[0-9a-f]{16,})$/i.test(seg) ? ":id" : seg).join("/");
2268
+ return trimTrailingSlashes(collapsed) || "/";
2269
+ }
2167
2270
  function normalizeLink(href, baseUrl) {
2168
2271
  let u;
2169
2272
  try {
@@ -2270,7 +2373,8 @@ async function discover(session, opts) {
2270
2373
  ...only ? [] : (opts.sourceDir ? routesFromSource(opts.sourceDir) : []).filter(isWorthVisiting),
2271
2374
  ...only ? [] : (await sitemapPaths(opts.baseUrl)).filter(isWorthVisiting)
2272
2375
  ];
2273
- const queue = [...new Set(seeded)];
2376
+ const scoped = (p) => inScope(new URL(p, opts.baseUrl).pathname, opts.scopePath);
2377
+ const queue = [...new Set(seeded)].filter(scoped);
2274
2378
  progress(only ? `${queue.length} page(s) you named` : `${queue.length} start path(s) from the source, sitemap and options`);
2275
2379
  const visited = /* @__PURE__ */ new Set();
2276
2380
  const seenShapes = /* @__PURE__ */ new Set();
@@ -2350,7 +2454,9 @@ async function discover(session, opts) {
2350
2454
  let links;
2351
2455
  try {
2352
2456
  shape = await domHash(page);
2353
- if (seenShapes.has(shape) && !only) continue;
2457
+ if (opts.dedupe === "route") {
2458
+ if (seenShapes.has(`route:${routeKey(here)}`) && !only) continue;
2459
+ } else if (seenShapes.has(shape) && !only) continue;
2354
2460
  title = pageLabel(await page.title(), here, surfaces);
2355
2461
  links = await page.$$eval(
2356
2462
  "a[href]",
@@ -2361,13 +2467,13 @@ async function discover(session, opts) {
2361
2467
  progress(`skipped ${path}: it changed while being read (${err.message.split("\n")[0].slice(0, 120)})`);
2362
2468
  continue;
2363
2469
  }
2364
- seenShapes.add(shape);
2470
+ seenShapes.add(opts.dedupe === "route" ? `route:${routeKey(here)}` : shape);
2365
2471
  surfaces.push({ key: surfaceKey(here, []), kind: "page", path: here, steps: [], label: title, domHash: shape });
2366
2472
  progress(`page ${here}`);
2367
2473
  for (const { href, label } of links) {
2368
2474
  if (isDestructiveLabel(label)) continue;
2369
2475
  const next = normalizeLink(href, page.url());
2370
- if (!only && next && !visited.has(next) && !queue.includes(next)) queue.push(next);
2476
+ if (!only && next && scoped(next) && !visited.has(next) && !queue.includes(next)) queue.push(next);
2371
2477
  }
2372
2478
  const triggers = (await findTriggers(page).catch(() => [])).filter((t) => !isDestructiveLabel(t.label)).slice(0, maxStates);
2373
2479
  for (const trigger of triggers) {
@@ -2382,7 +2488,7 @@ async function discover(session, opts) {
2382
2488
  const after = new URL(page.url());
2383
2489
  if (after.pathname + after.search !== here) {
2384
2490
  const next = normalizeLink(page.url(), opts.baseUrl);
2385
- if (!only && next && !visited.has(next) && !queue.includes(next)) queue.push(next);
2491
+ if (!only && next && scoped(next) && !visited.has(next) && !queue.includes(next)) queue.push(next);
2386
2492
  continue;
2387
2493
  }
2388
2494
  let kind;
@@ -2514,7 +2620,7 @@ ${text.slice(0, MAX_DESIGN_CHARS - out.length)}
2514
2620
  }
2515
2621
  function probeLine(label, p) {
2516
2622
  const axe = p.axe.map((v) => `${v.id}\xD7${v.count}`).join(", ") || "none";
2517
- return `${label}: accessibility violations ${axe}; sideways scroll ${p.overflowX ? "yes" : "no"}; small tap targets ${p.smallTargets}; console errors ${p.consoleErrors.length}; layout shift ${p.cls}`;
2623
+ return `${label}: accessibility violations ${axe}; sideways scroll ${p.overflowX ? "yes" : "no"}; small tap targets ${p.smallTargets}; overlapping or oversized boxes ${p.layout?.length ?? 0}; console errors ${p.consoleErrors.length}; layout shift ${p.cls}`;
2518
2624
  }
2519
2625
  function pngSize(buf) {
2520
2626
  return { width: buf.readUInt32BE(16), height: buf.readUInt32BE(20) };
@@ -2721,7 +2827,21 @@ async function askClaudeCode(prompt, cwd, model, signal, maxTurns = 4) {
2721
2827
  }
2722
2828
  return last;
2723
2829
  }
2724
- async function askApi(prompt, images, model, client) {
2830
+ async function askCursor(prompt, cwd, model, signal) {
2831
+ const args = ["-p", "--trust", "--mode", "ask", "--output-format", "text", "--workspace", cwd, "--model", model, prompt];
2832
+ let last = { text: null, costUsd: null, error: "The Cursor CLI did not run." };
2833
+ for (let attempt = 1; attempt <= 2; attempt++) {
2834
+ if (signal?.aborted) break;
2835
+ const res = await run("cursor-agent", args, { cwd, shell: process.platform === "win32", timeoutMs: 36e4, signal });
2836
+ if (res.timedOut) return { text: null, costUsd: null, error: "The Cursor CLI did not answer within 6 minutes." };
2837
+ if (res.exitCode === 0 && res.stdout.trim()) return { text: res.stdout, costUsd: null };
2838
+ const said = `${res.stdout.trim().slice(0, 200)} ${res.tail.trim().slice(-300)}`.trim();
2839
+ last = { text: null, costUsd: null, error: `Cursor CLI exited ${res.exitCode}: ${said || "no output"}` };
2840
+ if (attempt === 1) await new Promise((r) => setTimeout(r, 5e3));
2841
+ }
2842
+ return last;
2843
+ }
2844
+ async function askApi(prompt, images, model, client, labels = ["a.png", "b.png"]) {
2725
2845
  try {
2726
2846
  const msg = await client.messages.create({
2727
2847
  model,
@@ -2731,7 +2851,7 @@ async function askApi(prompt, images, model, client) {
2731
2851
  role: "user",
2732
2852
  content: [
2733
2853
  ...images.flatMap((png, i) => [
2734
- { type: "text", text: i === 0 ? "a.png:" : "b.png:" },
2854
+ { type: "text", text: `${labels[i] ?? `image ${i + 1}`}:` },
2735
2855
  { type: "image", source: { type: "base64", media_type: "image/png", data: png.toString("base64") } }
2736
2856
  ]),
2737
2857
  { type: "text", text: prompt }
@@ -2750,7 +2870,7 @@ async function checkStep(input) {
2750
2870
  const fail = (mode, error) => ({ model: spec.model, mode, verdict: "unsure", summary: "", votes: [], costUsd: null, error });
2751
2871
  let cost = 0;
2752
2872
  const ask = async (prompt, cwd, images, maxTurns) => {
2753
- const a2 = spec.via === "claude-code" ? await askClaudeCode(prompt, cwd, spec.model, input.signal, maxTurns) : await askApi(prompt, images, spec.model, input.client ?? new Anthropic2());
2873
+ const a2 = spec.via === "claude-code" ? await askClaudeCode(prompt, cwd, spec.model, input.signal, maxTurns) : spec.via === "cursor" ? await askCursor(prompt, cwd, spec.model, input.signal) : await askApi(prompt, images, spec.model, input.client ?? new Anthropic2());
2754
2874
  if (a2.costUsd) cost += a2.costUsd;
2755
2875
  return a2;
2756
2876
  };
@@ -2869,6 +2989,7 @@ function describeProbes(viewport, p) {
2869
2989
  }
2870
2990
  if (p.overflowX) lines.push(`- [${viewport}] The page scrolls sideways at this width.`);
2871
2991
  if (p.smallTargets > 0) lines.push(`- [${viewport}] ${p.smallTargets} tap target(s) smaller than 24\xD724 px.`);
2992
+ for (const i of p.layout ?? []) lines.push(`- [${viewport}] ${i.kind === "overlap" ? "Overlap" : "Too big"}: ${i.selector} ${i.detail}.`);
2872
2993
  for (const e of p.consoleErrors.slice(0, 5)) lines.push(`- [${viewport}] Console error: ${e}`);
2873
2994
  if (p.cls > CLS_GOOD) lines.push(`- [${viewport}] Layout shift ${p.cls} while loading (aim below ${CLS_GOOD}).`);
2874
2995
  return lines;
@@ -3015,6 +3136,8 @@ function whatRose(before, now) {
3015
3136
  const out = [];
3016
3137
  if (now.smallTargets > before.smallTargets) out.push(`tap targets under 24 px ${before.smallTargets} \u2192 ${now.smallTargets}`);
3017
3138
  if (now.cls > CLS_GOOD && now.cls > before.cls) out.push(`layout shift ${before.cls} \u2192 ${now.cls}`);
3139
+ const boxes = (p) => p.layout?.length ?? 0;
3140
+ if (boxes(now) > boxes(before)) out.push(`overlapping or oversized boxes ${boxes(before)} \u2192 ${boxes(now)}`);
3018
3141
  const was = new Map(before.axe.map((v) => [v.id, v.count]));
3019
3142
  for (const v of now.axe) {
3020
3143
  if (v.count > (was.get(v.id) ?? 0)) out.push(`${v.id} ${was.get(v.id) ?? 0} \u2192 ${v.count} element(s)`);
@@ -3382,7 +3505,7 @@ ${res.tail}`);
3382
3505
  });
3383
3506
  state.baseUrl = server.url;
3384
3507
  persist();
3385
- const session = await openSession({ profileDir: opts.profileDir, allow: opts.allow, ignore: opts.ignore });
3508
+ const session = await openSession({ profileDir: opts.profileDir, channel: opts.channel, allow: opts.allow, ignore: opts.ignore });
3386
3509
  try {
3387
3510
  if (state.surfaces.length === 0) {
3388
3511
  log("Mapping screens\u2026");
@@ -3868,11 +3991,6 @@ function syncConfigFromEnv(env = process.env) {
3868
3991
  mode: env.GITHUB_ACTIONS === "true" ? "cloud" : "local"
3869
3992
  };
3870
3993
  }
3871
- function trimTrailingSlashes(s) {
3872
- let end = s.length;
3873
- while (end > 0 && s.charCodeAt(end - 1) === 47) end--;
3874
- return s.slice(0, end);
3875
- }
3876
3994
  function probeSummary(p) {
3877
3995
  if (!p) return null;
3878
3996
  return {
@@ -4139,4 +4257,3 @@ export {
4139
4257
  toSnapshot,
4140
4258
  unshuffle
4141
4259
  };
4142
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mushi-mushi/ux",
3
- "version": "0.1.2",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "description": "Local visual UX loop: maps a running app's pages, tabs and dialogs, runs your coding agent on each one against screenshot baselines, and shows before/after diffs, regressions and a pairwise judge.",
6
6
  "type": "module",
@@ -54,7 +54,7 @@
54
54
  "pixelmatch": "^7.2.0",
55
55
  "playwright": "^1.61.1",
56
56
  "pngjs": "^7.0.0",
57
- "zod": "^4.4.3"
57
+ "zod": "^4.6.7"
58
58
  },
59
59
  "devDependencies": {
60
60
  "@types/node": "^22.20.0",