Skip to content

Clone any website into a pixel-accurate Next.js app with AI — Playwright-measured extraction (no eyeballing), spec-gated parallel builder agents, and scored pixel-diff QA at phone/tablet/desktop. Works with Claude Code, Cursor, Copilot + 9 more.

perf(workflow): probe whole routes in one call, typecheck per merge

Mahanaicoach71a9f835c22c
diff --git a/.claude/skills/clone-website/SKILL.md b/.claude/skills/clone-website/SKILL.md
index b12c32a..6c562c5 100644
--- a/.claude/skills/clone-website/SKILL.md
+++ b/.claude/skills/clone-website/SKILL.md
@@ -37,10 +37,10 @@ The scripts do the mechanical work — **use them instead of hand-measuring via
| **`node scripts/extract/page.mjs <url> [--no-site-files]`** | **THE WORKHORSE — one call, 3 page loads total.** Auto-detects sections, then produces `tokens.json` + `css.json` (skip on later pages with `--no-site-files`), `assets.json` + downloads to `public/`, `responsive.json` (all 3 viewports), a full computed-style walk per section (`sections/<name>.json`), and full-page **and** per-section screenshots at phone/iPad/PC. Accepts explicit `--selector "css" --name x` pairs to override detection. Everything is measured from the SAME page state, so numbers, walks and screenshots can never disagree |
| `node scripts/extract/crawl.mjs <url> [--max 25]` | Discover pages (sitemap + nav links) → `docs/research/<host>/sitemap.json` |
| `node scripts/extract/section.mjs <url> --selector "css" [--name x] --state scroll:600\|click:sel\|hover:sel [--viewport pc\|ipad\|phone]` | **State captures** (page.mjs covers the default state). Captures a second state and diffs them (element styles *and* `::before`/`::after`), waiting for the section's real transition duration. `--selector`/`--name` repeat — one page load for all |
-| `node scripts/extract/probe.mjs <url> --selector "css" [--selector "css2"] [--props a,b,c]` | Exact computed values for specific selectors at all 3 viewports, as a markdown table with a **varies** column — paste straight into a spec's Responsive section |
+| `node scripts/extract/probe.mjs <url> --selector "css" [--selector "css2"] [--props a,b,c]` / `probe.mjs --route </r>` | Exact computed values for specific selectors at all 3 viewports, as a markdown table with a **varies** column — paste straight into a spec's Responsive section. **`--route` probes EVERY registered section of a page in one call (3 loads total, plus a `probe-<section>.json` per section) — never probe section-by-section** |
| `node scripts/extract/screenshot.mjs <url> [--selector css --name x ...]` | Extra screenshots at phone/iPad/PC (page.mjs already shot everything once). `--selector`/`--name` repeat — one call, 3 loads, N sections |
| `node scripts/extract/tokens.mjs` / `css.mjs` / `assets.mjs` / `responsive.mjs` | Single-purpose re-runs of one page.mjs output when something needs refreshing |
-| `node scripts/diff.mjs --original <url> --clone <url> [--selector css] --viewport all [--threshold 95]` | Scored pixel diff, original vs clone. **`--viewport all` scores pc+ipad+phone in one call**, and the per-viewport **band breakdown names the y-range where the mismatch lives** — read it before guessing at causes |
+| `node scripts/diff.mjs --original <url> --clone <url> [--selector css] --viewport all [--threshold 95]` | Scored pixel diff, original vs clone. **`--viewport all` scores pc+ipad+phone in one call**, and the per-viewport **band breakdown names the y-range where the mismatch lives** — read it before guessing at causes. **Batched sweep: `--route </r>` (or repeated `--section name=css`) scores every section of a page from ONE load per side per viewport.** Original-side shots are cached 24h, so fix-iteration re-diffs only re-render the clone (`--fresh-original` to override) |
| `node scripts/lint-spec.mjs <spec.md\|dir>` | Mechanical spec-completeness gate — must pass before ANY builder dispatch |
| `node scripts/manifest.mjs <cmd>` | Pipeline state: init / add-page / add-section / set / status / next |
@@ -58,7 +58,7 @@ Browser MCP (Chrome MCP, Playwright MCP — if available) is for **judgment work
8. **The extraction JSON is ground truth; the spec is a summary of it.** If a builder finds the spec disagreeing with `sections/<name>.json` or `responsive.json`, the JSON wins — say so explicitly in every builder prompt and have the builder report the discrepancy so you can correct the spec.
9. **Spec files are the contract.** No spec → no builder. lint-spec must pass → then dispatch.
-10. **The build must always compile.** Builders verify `npx tsc --noEmit`; you verify `npm run build` after every merge.
+10. **The build must always compile.** Builders verify `npx tsc --noEmit`; you verify `npm run typecheck && npm run lint` after every merge. Full `npm run build` runs only at checkpoints (Phase 0, end of Phase 2, once mid-way through Phase 3, Phase 4, completion) — it takes 30–60s and running it per merge serializes otherwise-parallel builders.
11. **The manifest is updated at every stage transition.** That's what makes the run resumable.
## Phase 0 — Crawl & Scope
@@ -101,13 +101,22 @@ Work through `manifest.mjs next` until no sections remain. For each section:
### 3a. Extract
**The default state is already extracted** — Phase 1's page.mjs run wrote
-`sections/<name>.json`, `responsive.json`, and all screenshots. Per section, only two
-things remain:
+`sections/<name>.json`, `responsive.json`, and all screenshots.
+
+**First time you enter Phase 3 for a page, probe ALL its sections in ONE call** (3
+page loads total instead of 3 per section — never probe section-by-section):
+
+```bash
+node scripts/extract/probe.mjs --route <r> # every registered section + probe-<section>.json each
+# add key children in the same call when a spec will need them:
+node scripts/extract/probe.mjs --route <r> --selector "<sel> h2" --selector "<sel> .card"
+```
+
+Slice the per-section tables into each spec's Responsive section as you write it.
+Per section, only one thing remains:
```bash
-# 1. Per-viewport probe table for the spec's Responsive section (batch several selectors)
-node scripts/extract/probe.mjs <page-url> --selector "<sel>" --selector "<sel> h2"
-# 2. Per discovered behavior — one call per state (batch selectors sharing a trigger):
+# Per discovered behavior — one call per state (batch selectors sharing a trigger):
node scripts/extract/section.mjs <page-url> --selector "<sel>" --name <name>-hover --state hover:".card"
node scripts/extract/section.mjs <page-url> --selector "<sel>" --name <name>-scrolled --state scroll:600
# per tab/pill state: --state click:".tab-2" etc. EVERY state, not just the default.
@@ -179,7 +188,9 @@ Every builder receives IN ITS PROMPT (never "go read the file"):
Complex section (3+ distinct sub-components) → one builder per sub-component + one for the wrapper, sub-components first. **Don't wait** — while builders run, extract the next section.
### 3e. Merge
-As builders finish: merge worktree → `npm run build` → fix type errors immediately → `manifest.mjs set … --stage merged`.
+As builders finish: merge worktree → `npm run typecheck && npm run lint` → fix errors immediately → `manifest.mjs set … --stage merged`. tsc catches the cross-worktree breaks (imports, prop types) that per-merge builds used to catch, in a fraction of the time.
+
+**Once, after roughly half the page's sections are merged: run a full `npm run build` checkpoint.** It catches build-only failures (server/client component violations, route exports, metadata) while they're still cheap to bisect. Don't build after every merge.
## Phase 4 — Page Assembly
@@ -187,11 +198,17 @@ Per page: create `src/app/<route>/page.tsx` importing its section components wit
## Phase 5 — Scored QA Loop
-Start the clone: `npm run dev` (background). Then **one call per section scores all three viewports**:
+Start the clone: `npm run dev` (background). Then **score the whole page's sections in ONE batched call** (one load per side per viewport instead of one per section):
+
+```bash
+node scripts/diff.mjs --original <orig-page-url> --clone http://localhost:3000<route> --route <r> --viewport all
+node scripts/manifest.mjs set --route <r> --section <name> --score pc=<match> # per section × viewport
+```
+
+**Fix iterations stay single-section** — the original-side shots captured by the sweep are cached, so a re-diff only re-renders the clone:
```bash
node scripts/diff.mjs --original <orig-page-url> --clone http://localhost:3000<route> --selector "<sel>" --viewport all --name <name>
-node scripts/manifest.mjs set --route <r> --section <name> --score pc=<match> # per viewport
```
- **Pass = ≥95% on all three viewports** → `--stage qa_passed`
diff --git a/scripts/extract/probe.mjs b/scripts/extract/probe.mjs
index 6dd43ad..c75b5d2 100644
--- a/scripts/extract/probe.mjs
+++ b/scripts/extract/probe.mjs
@@ -9,8 +9,15 @@
// Usage:
// node scripts/extract/probe.mjs <url> --selector "section#two" [--selector "h2" ...]
// node scripts/extract/probe.mjs <url> --selector "#two" --props fontSize,paddingTop,marginBottom
+// node scripts/extract/probe.mjs --route / # every section of that manifest route, 3 loads TOTAL
+//
+// --route pulls each registered section's selector from docs/research/manifest.json
+// (and the page URL, if no url argument is given), so one invocation probes the
+// whole page instead of paying 3 page loads per section. Combines with --selector.
//
// Output: a markdown table per selector (stdout) + docs/research/<host>/probe-<name>.json
+// (--route additionally writes one probe-<section>.json per section, for specs to cite)
+import { readFileSync } from "node:fs";
import {
VIEWPORTS,
forEachViewport,
@@ -25,12 +32,34 @@ import {
} from "../lib.mjs";
const args = parseArgs(process.argv.slice(2));
-const url = args._[0];
-const selectors = toList(args.selector);
+const explicitSelectors = toList(args.selector);
const props = args.props ? String(args.props).split(",") : null;
const name = typeof args.name === "string" ? args.name : null;
+
+// --route: probe every registered section of a manifest route in this one call.
+let routeSections = [];
+let routeUrl = null;
+if (typeof args.route === "string") {
+ let manifest;
+ try {
+ manifest = JSON.parse(readFileSync("docs/research/manifest.json", "utf8"));
+ } catch {
+ console.error("No readable docs/research/manifest.json — --route needs an initialized manifest");
+ process.exit(1);
+ }
+ const p = manifest.pages.find((p) => p.route === args.route);
+ if (!p) {
+ console.error(`Route ${args.route} not in manifest. Routes: ${manifest.pages.map((p) => p.route).join(", ")}`);
+ process.exit(1);
+ }
+ routeSections = p.sections.map((s) => ({ name: s.name, selector: s.selector }));
+ routeUrl = p.url;
+}
+
+const url = args._[0] || routeUrl;
+const selectors = [...new Set([...explicitSelectors, ...routeSections.map((s) => s.selector)])];
if (!url || !selectors.length) {
- console.error('Usage: node scripts/extract/probe.mjs <url> --selector "css" [--selector "css2"] [--props a,b,c]');
+ console.error('Usage: node scripts/extract/probe.mjs <url> --selector "css" [--selector "css2"] [--props a,b,c] OR probe.mjs --route </r>');
process.exit(1);
}
@@ -81,9 +110,24 @@ for (const sel of selectors) {
}
}
-writeJson(`docs/research/${hostOf(url)}/probe-${name || slugify(selectors[0])}.json`, {
- url,
- selectors,
- generatedAt: new Date().toISOString(),
- results,
-});
+// One stable file per manifest section (specs cite these), plus the combined
+// file when explicit selectors were passed — unchanged behavior for old callers.
+for (const s of routeSections) {
+ const per = Object.fromEntries(
+ Object.entries(results).map(([vp, bySel]) => [vp, { [s.selector]: bySel[s.selector] }])
+ );
+ writeJson(`docs/research/${hostOf(url)}/probe-${slugify(s.name)}.json`, {
+ url,
+ selectors: [s.selector],
+ generatedAt: new Date().toISOString(),
+ results: per,
+ });
+}
+if (explicitSelectors.length || !routeSections.length) {
+ writeJson(`docs/research/${hostOf(url)}/probe-${name || slugify(selectors[0])}.json`, {
+ url,
+ selectors,
+ generatedAt: new Date().toISOString(),
+ results,
+ });
+}