recanica 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/package.json +2 -2
- package/src/audit-browser.js +18 -6
- package/src/audit.js +30 -15
- package/src/config.js +1 -0
- package/src/guard.js +67 -5
- package/src/index.js +47 -2
- package/src/kickoff.js +151 -47
- package/src/report.js +87 -0
- package/src/review.js +3 -1
- package/src/test.mjs +65 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "recanica",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Add Recanica (UI framework by Aturanica Labs) to any project: npx recanica init",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Aturanica Labs",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"README.md"
|
|
28
28
|
],
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@recanica/mcp": "0.
|
|
30
|
+
"@recanica/mcp": "0.2.0"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|
package/src/audit-browser.js
CHANGED
|
@@ -20,13 +20,24 @@ export function auditPage() {
|
|
|
20
20
|
const r = el.getBoundingClientRect();
|
|
21
21
|
return cs.display !== "none" && cs.visibility !== "hidden" && r.width > 0 && r.height > 0;
|
|
22
22
|
};
|
|
23
|
+
// A deliberate sideways scroller: a table or code wrapper, a carousel, a tab strip, a row of chips, or one marked
|
|
24
|
+
// data-scroll="x". Anything else that scrolls sideways is a bug: usually overflow-y:auto (a sidebar, a panel) quietly
|
|
25
|
+
// turning overflow-x to auto too, so one long label scrolls the whole column.
|
|
26
|
+
const scrollsX = (p) => { const o = getComputedStyle(p).overflowX; return o === "auto" || o === "scroll"; };
|
|
27
|
+
const intendedScroller = (p) => {
|
|
28
|
+
if (p.matches("pre, code, [data-scroll=x], [role=tablist], [data-slot*=carousel], [data-slot*=scroll-area], [data-slot=table-container]") || p.querySelector(":scope > table, :scope > * > table")) return true;
|
|
29
|
+
const cs = getComputedStyle(p);
|
|
30
|
+
if (/mono/i.test(cs.fontFamily)) return true; // a code block
|
|
31
|
+
return /flex/.test(cs.display) && cs.flexDirection.startsWith("row") && cs.flexWrap === "nowrap";
|
|
32
|
+
};
|
|
23
33
|
const insideScroller = (el) => {
|
|
24
|
-
for (let p = el.parentElement; p; p = p.parentElement)
|
|
25
|
-
const o = getComputedStyle(p).overflowX;
|
|
26
|
-
if (o === "auto" || o === "scroll") return true;
|
|
27
|
-
}
|
|
34
|
+
for (let p = el.parentElement; p; p = p.parentElement) if (scrollsX(p) && intendedScroller(p)) return true;
|
|
28
35
|
return false;
|
|
29
36
|
};
|
|
37
|
+
for (const p of Array.from(document.querySelectorAll("body *"))) {
|
|
38
|
+
if (!visible(p) || p.closest("svg, [data-audit-ignore], nextjs-portal") || !scrollsX(p) || intendedScroller(p)) continue;
|
|
39
|
+
if (p.scrollWidth > p.clientWidth + 2) issues.push({ rule: "sideways-scroll", detail: `${describe(p)} scrolls sideways (${p.scrollWidth}px of content in ${p.clientWidth}px)` });
|
|
40
|
+
}
|
|
30
41
|
|
|
31
42
|
if (document.documentElement.scrollWidth > window.innerWidth + 1) {
|
|
32
43
|
issues.push({ rule: "page-overflow", detail: `${document.documentElement.scrollWidth}px wide in a ${window.innerWidth}px viewport` });
|
|
@@ -53,6 +64,7 @@ export function auditPage() {
|
|
|
53
64
|
if (hasOwnText && isBlockish && el.scrollWidth > el.clientWidth + 2 && !insideScroller(el)) {
|
|
54
65
|
const clipped = cs.overflowX === "hidden" || cs.overflowX === "clip";
|
|
55
66
|
if (clipped && cs.textOverflow !== "ellipsis") issues.push({ rule: "clipped-text", detail: describe(el) });
|
|
67
|
+
else if (clipped && el.closest("[data-slot=nav-item], .rc-nav-item, [role=tab], button")) issues.push({ rule: "truncated-label", detail: `${describe(el)} ends in … (${el.scrollWidth}px of text in ${el.clientWidth}px)` });
|
|
56
68
|
else if (!clipped) issues.push({ rule: "text-overflow", detail: `${describe(el)} (${el.scrollWidth}px in ${el.clientWidth}px)` });
|
|
57
69
|
}
|
|
58
70
|
|
|
@@ -164,7 +176,7 @@ export function auditPage() {
|
|
|
164
176
|
return [...layout, ...ux, ...surfaces];
|
|
165
177
|
}
|
|
166
178
|
|
|
167
|
-
export const LAYOUT_RULES = ["page-overflow", "text-overflow", "clipped-text", "wrapped-label", "overlap", "table-edges", "surface-padding", "stretched-rows"];
|
|
179
|
+
export const LAYOUT_RULES = ["page-overflow", "sideways-scroll", "truncated-label", "text-overflow", "clipped-text", "wrapped-label", "overlap", "table-edges", "surface-padding", "stretched-rows"];
|
|
168
180
|
export const UX_RULES = ["unnamed-control", "small-target", "dead-link", "unlabelled-field", "duplicate-id"];
|
|
169
181
|
|
|
170
182
|
/**
|
|
@@ -590,7 +602,7 @@ export function auditQuality() {
|
|
|
590
602
|
* Everything else (brand colour, font, locale, density, thresholds) is a project choice, set in tokens or config.
|
|
591
603
|
*/
|
|
592
604
|
export const RULE_LEVELS = {
|
|
593
|
-
must: ["page-overflow", "text-overflow", "clipped-text", "overlap", "wrapped-label", "contrast", "unnamed-control", "unlabelled-field",
|
|
605
|
+
must: ["page-overflow", "sideways-scroll", "truncated-label", "text-overflow", "clipped-text", "overlap", "wrapped-label", "contrast", "unnamed-control", "unlabelled-field",
|
|
594
606
|
"small-target", "dead-link", "duplicate-id", "focus-visible", "spec-copy", "tiny-text", "no-title", "error-wiring", "broken-page", "runtime-error"],
|
|
595
607
|
should: ["spec-color", "spec-weight", "spec-font", "spec-button", "spec-radius", "inconsistent", "table-edges", "surface-padding", "stretched-rows",
|
|
596
608
|
"busy-primary", "busy-actions", "busy-type", "busy-surfaces", "busy-lines", "busy-nesting", "busy-badges", "busy-icons", "busy-text",
|
package/src/audit.js
CHANGED
|
@@ -16,36 +16,37 @@ import { COPY_RULES_SOURCE } from "./copy-rules.js";
|
|
|
16
16
|
|
|
17
17
|
// Resolve Playwright from the project being audited (cwd), not from this package.
|
|
18
18
|
async function loadPlaywright() {
|
|
19
|
-
|
|
20
|
-
for (const
|
|
21
|
-
|
|
19
|
+
// The project first; then wherever this CLI is installed (a monorepo, a global install).
|
|
20
|
+
for (const req of [createRequire(join(process.cwd(), "package.json")), createRequire(import.meta.url)]) {
|
|
21
|
+
for (const name of ["playwright", "@playwright/test"]) {
|
|
22
|
+
try { return await import(pathToFileURL(req.resolve(name)).href); } catch {}
|
|
23
|
+
}
|
|
22
24
|
}
|
|
23
25
|
return null;
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
/**
|
|
29
|
+
* Audit pages in a real browser. Returns null when Playwright isn't installed in the project.
|
|
30
|
+
* urls: full URLs. Results are classified must / should / accepted against recanica.config.json.
|
|
31
|
+
*/
|
|
32
|
+
export async function auditPages(urls, { widths = [375, 900, 1280], crawl = false, maxPages = 200 } = {}) {
|
|
27
33
|
const pw = await loadPlaywright();
|
|
28
|
-
if (!pw)
|
|
29
|
-
log("recanica audit needs Playwright in this project:\n npm i -D playwright && npx playwright install chromium");
|
|
30
|
-
return 2;
|
|
31
|
-
}
|
|
32
|
-
if (!args.length) { log("Usage: npx recanica audit <url> [--paths /,/pricing] [--widths 375,900,1280] [--crawl] [--json]"); return 2; }
|
|
33
|
-
const widths = String(flags.widths ?? "375,900,1280").split(",").map(Number).filter(Boolean);
|
|
34
|
-
const paths = flags.paths ? String(flags.paths).split(",") : [""];
|
|
35
|
-
const crawl = !!flags.crawl;
|
|
34
|
+
if (!pw) return null;
|
|
36
35
|
const chromium = pw.chromium ?? pw.default?.chromium;
|
|
37
36
|
const browser = await chromium.launch();
|
|
38
37
|
const results = [];
|
|
38
|
+
const pages = new Set();
|
|
39
39
|
try {
|
|
40
40
|
for (const width of widths) {
|
|
41
41
|
const ctx = await browser.newContext({ viewport: { width, height: 900 }, hasTouch: width < 768, isMobile: width < 768 });
|
|
42
42
|
const page = await ctx.newPage();
|
|
43
|
-
const queue =
|
|
43
|
+
const queue = [...urls];
|
|
44
44
|
const seen = new Set();
|
|
45
|
-
while (queue.length && seen.size <
|
|
45
|
+
while (queue.length && seen.size < maxPages) {
|
|
46
46
|
const url = queue.shift();
|
|
47
47
|
if (seen.has(url)) continue;
|
|
48
48
|
seen.add(url);
|
|
49
|
+
pages.add(url);
|
|
49
50
|
const errors = [];
|
|
50
51
|
page.removeAllListeners("pageerror");
|
|
51
52
|
page.on("pageerror", (e) => errors.push(e.message));
|
|
@@ -66,12 +67,26 @@ export async function runAudit(args, flags, log) {
|
|
|
66
67
|
} finally {
|
|
67
68
|
await browser.close();
|
|
68
69
|
}
|
|
69
|
-
// Must-rules fail
|
|
70
|
+
// Must-rules fail. Should-rules are reported (deviate with a reason in recanica.config.json "allow").
|
|
70
71
|
const config = loadConfig();
|
|
71
72
|
for (const r of results) Object.assign(r, classify(r.issues, new URL(r.url).pathname, config, levelOf));
|
|
72
73
|
const must = results.reduce((n, r) => n + r.must.length, 0);
|
|
73
74
|
const should = results.reduce((n, r) => n + r.should.length, 0);
|
|
74
75
|
const accepted = results.reduce((n, r) => n + r.accepted.length, 0);
|
|
76
|
+
return { must, should, accepted, results, pages: pages.size };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function runAudit(args, flags, log) {
|
|
80
|
+
if (!args.length) { log("Usage: npx recanica audit <url> [--paths /,/pricing] [--widths 375,900,1280] [--crawl] [--json]"); return 2; }
|
|
81
|
+
const widths = String(flags.widths ?? "375,900,1280").split(",").map(Number).filter(Boolean);
|
|
82
|
+
const paths = flags.paths ? String(flags.paths).split(",") : [""];
|
|
83
|
+
const urls = args.flatMap((base) => paths.map((p) => new URL(p || "/", base).href));
|
|
84
|
+
const r = await auditPages(urls, { widths, crawl: !!flags.crawl });
|
|
85
|
+
if (!r) {
|
|
86
|
+
log("recanica audit needs Playwright in this project:\n npm i -D playwright && npx playwright install chromium");
|
|
87
|
+
return 2;
|
|
88
|
+
}
|
|
89
|
+
const { must, should, accepted, results } = r;
|
|
75
90
|
if (flags.json) process.stdout.write(JSON.stringify({ must, should, accepted, results }, null, 2) + "\n");
|
|
76
91
|
else {
|
|
77
92
|
for (const r of results) {
|
package/src/config.js
CHANGED
|
@@ -72,6 +72,7 @@ export function loadConfig(root = process.cwd()) {
|
|
|
72
72
|
decisions: c.decisions ?? "docs/ui/DECISIONS.md",
|
|
73
73
|
ignore: c.ignore ?? [],
|
|
74
74
|
thresholds: c.thresholds ?? {},
|
|
75
|
+
devUrl: typeof c.devUrl === "string" ? c.devUrl : null, // where the dev server runs; the guard audits changed pages there
|
|
75
76
|
allow: (c.allow ?? []).filter((a) => a && a.rule && a.reason && String(a.reason).trim().length >= 8),
|
|
76
77
|
};
|
|
77
78
|
}
|
package/src/guard.js
CHANGED
|
@@ -5,6 +5,12 @@
|
|
|
5
5
|
* npx recanica guard --staged staged files (git pre-commit hook)
|
|
6
6
|
* npx recanica guard --hook claude Claude Code Stop hook: blocks the agent from finishing until the
|
|
7
7
|
* files it changed pass (exit 2, findings on stderr)
|
|
8
|
+
* npx recanica guard --render also audit the changed pages in a browser (on by default for the hook)
|
|
9
|
+
*
|
|
10
|
+
* Rendered check: when the dev server is running (recanica.config.json "devUrl", or the stack's usual port) and
|
|
11
|
+
* Playwright is installed, the pages behind the changed files are opened at 375 and 1280px and must-level layout
|
|
12
|
+
* findings block too (sideways scroll, cut-off labels, overflow, overlap, dead links). Up to 3 pages, so it stays quick.
|
|
13
|
+
* No dev server or no Playwright: the code check still runs, and the agent is told the pages weren't looked at.
|
|
8
14
|
*
|
|
9
15
|
* What fails:
|
|
10
16
|
* - pre-commit and plain runs: must-level findings (the same as `recanica check`).
|
|
@@ -18,6 +24,7 @@ import { existsSync, readFileSync, writeFileSync } from "node:fs";
|
|
|
18
24
|
import { tmpdir } from "node:os";
|
|
19
25
|
import { join } from "node:path";
|
|
20
26
|
import { check } from "./check.js";
|
|
27
|
+
import { loadConfig } from "./config.js";
|
|
21
28
|
|
|
22
29
|
const git = (root, args) => {
|
|
23
30
|
const r = spawnSync("git", args, { cwd: root, encoding: "utf8" });
|
|
@@ -33,11 +40,44 @@ export function changedFiles(root, { staged = false } = {}) {
|
|
|
33
40
|
return [...new Set([...tracked, ...untracked])].filter((f) => existsSync(join(root, f)));
|
|
34
41
|
}
|
|
35
42
|
|
|
43
|
+
/** The routes behind changed files (Next app/pages router, SvelteKit, Astro, plain HTML). Dynamic routes are skipped. */
|
|
44
|
+
export function routesFor(files) {
|
|
45
|
+
const routes = new Set();
|
|
46
|
+
let ui = false;
|
|
47
|
+
for (const f of files) {
|
|
48
|
+
if (/\.(tsx|jsx|vue|svelte|astro|html|css|scss|mdx)$/.test(f)) ui = true;
|
|
49
|
+
let m, r = null;
|
|
50
|
+
if ((m = f.match(/(?:^|\/)app\/(.*?)\/?page\.(?:tsx|jsx|ts|js|mdx)$/))) r = m[1];
|
|
51
|
+
else if ((m = f.match(/(?:^|\/)pages\/(?!api\/|_)(.*?)\.(?:tsx|jsx|astro|vue)$/))) r = m[1].replace(/(?:^|\/)index$/, "");
|
|
52
|
+
else if ((m = f.match(/(?:^|\/)routes\/(.*?)\/?\+page\.svelte$/))) r = m[1];
|
|
53
|
+
else if ((m = f.match(/^(?:public\/)?(.*?)\.html$/))) r = m[1] === "index" ? "" : m[1].replace(/\/index$/, "") + (m[1].endsWith("index") ? "" : ".html");
|
|
54
|
+
if (r === null) continue;
|
|
55
|
+
r = r.split("/").filter((seg) => !/^\(.*\)$/.test(seg)).join("/"); // route groups (marketing) don't appear in the URL
|
|
56
|
+
if (/\[|\]/.test(r)) continue; // [id]: we don't know a real value
|
|
57
|
+
routes.add("/" + r);
|
|
58
|
+
}
|
|
59
|
+
if (!routes.size && ui) routes.add("/"); // a shared part changed: at least look at the home page
|
|
60
|
+
return [...routes].slice(0, 3);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const DEFAULT_PORTS = { nextjs: 3000, "vite-react": 5173, vue: 5173, svelte: 5173, astro: 4321, angular: 4200 };
|
|
64
|
+
async function devServer(root, cfg) {
|
|
65
|
+
const cands = cfg.devUrl ? [cfg.devUrl] : [...new Set([DEFAULT_PORTS[cfg.project?.stack], 3000, 5173, 4321].filter(Boolean))].map((p) => `http://localhost:${p}`);
|
|
66
|
+
if (!cfg.devUrl && !existsSync(join(root, "package.json"))) return null;
|
|
67
|
+
for (const url of cands) {
|
|
68
|
+
try {
|
|
69
|
+
const res = await fetch(url, { signal: AbortSignal.timeout(800), redirect: "manual" });
|
|
70
|
+
if (res.status < 500) return url;
|
|
71
|
+
} catch {}
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
36
76
|
function readHookInput() {
|
|
37
77
|
try { return JSON.parse(readFileSync(0, "utf8") || "{}"); } catch { return {}; }
|
|
38
78
|
}
|
|
39
79
|
|
|
40
|
-
export function runGuard(root, flags, log) {
|
|
80
|
+
export async function runGuard(root, flags, log) {
|
|
41
81
|
const hook = flags.hook === "claude";
|
|
42
82
|
const input = hook ? readHookInput() : {};
|
|
43
83
|
const files = changedFiles(root, { staged: !!flags.staged });
|
|
@@ -46,9 +86,31 @@ export function runGuard(root, flags, log) {
|
|
|
46
86
|
// The kickoff reminder is for the start of a session (recanica start), not a reason to block a finished turn.
|
|
47
87
|
const relevant = hits.filter((h) => h.rule !== "kickoff");
|
|
48
88
|
const failing = hook ? relevant : relevant.filter((h) => h.level === "error");
|
|
49
|
-
if (!failing.length) { if (!hook) log(`recanica guard: ${files ? files.length : "all"} files · clean.`); return 0; }
|
|
50
89
|
|
|
51
|
-
|
|
90
|
+
// The rendered pages: what code can't show (sideways scroll, cut-off labels, overflow, overlap, dead links).
|
|
91
|
+
const rendered = [];
|
|
92
|
+
let renderNote = "";
|
|
93
|
+
if ((hook || flags.render) && !flags.staged && files) {
|
|
94
|
+
const routes = routesFor(files);
|
|
95
|
+
const base = routes.length ? await devServer(root, loadConfig(root)) : null;
|
|
96
|
+
if (routes.length && !base) renderNote = "Pages not looked at: no dev server running. Start it so the guard can check the rendered pages too.";
|
|
97
|
+
if (base) {
|
|
98
|
+
const { auditPages } = await import("./audit.js");
|
|
99
|
+
const r = await auditPages(routes.map((p) => new URL(p, base).href), { widths: [375, 1280], maxPages: 3 }).catch(() => null);
|
|
100
|
+
if (!r) renderNote = "Pages not looked at: Playwright isn't installed (npm i -D playwright && npx playwright install chromium).";
|
|
101
|
+
else for (const res of r.results) for (const i of res.must) rendered.push(`✗ ${new URL(res.url).pathname} @ ${res.width}px ${i.rule}: ${i.detail}`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!failing.length && !rendered.length) {
|
|
106
|
+
if (!hook) log(`recanica guard: ${files ? files.length : "all"} files · clean.${renderNote ? `\n${renderNote}` : ""}`);
|
|
107
|
+
return 0;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const lines = [
|
|
111
|
+
...failing.slice(0, 40).map((h) => `${h.level === "error" ? "✗" : "!"} ${h.file}:${h.line} ${h.message}: “${h.match.slice(0, 60)}”\n → ${h.fix}`),
|
|
112
|
+
...(rendered.length ? ["", "On the rendered pages (npx recanica audit for details):", ...rendered.slice(0, 20)] : []),
|
|
113
|
+
];
|
|
52
114
|
const more = failing.length > 40 ? `\n… and ${failing.length - 40} more (npx recanica check)` : "";
|
|
53
115
|
|
|
54
116
|
if (hook) {
|
|
@@ -60,7 +122,7 @@ export function runGuard(root, flags, log) {
|
|
|
60
122
|
return 0;
|
|
61
123
|
}
|
|
62
124
|
writeFileSync(key, String(n + 1));
|
|
63
|
-
process.stderr.write(`Recanica:
|
|
125
|
+
process.stderr.write(`Recanica: what you changed breaks the design rules (${failing.length + rendered.length} findings). Fix them before you finish:
|
|
64
126
|
use the Recanica parts and tokens instead of hand-built elements, literal values, gradients or pixel spacing,
|
|
65
127
|
and plain copy instead of AI phrasing. If one is a deliberate exception, add \`recanica-ignore: <reason>\` on that line.
|
|
66
128
|
|
|
@@ -69,6 +131,6 @@ ${lines.join("\n")}${more}
|
|
|
69
131
|
return 2;
|
|
70
132
|
}
|
|
71
133
|
log(lines.join("\n") + more);
|
|
72
|
-
log(`\nrecanica guard: ${failing.length} must-fix in ${files ? files.length : "all"} files. Fix with tokens and parts, or add \`recanica-ignore\` with a reason.`);
|
|
134
|
+
log(`\nrecanica guard: ${failing.length + rendered.length} must-fix in ${files ? files.length : "all"} files. Fix with tokens and parts, or add \`recanica-ignore\` with a reason.`);
|
|
73
135
|
return 1;
|
|
74
136
|
}
|
package/src/index.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { spawnSync } from "node:child_process";
|
|
20
20
|
import { existsSync, mkdirSync, readFileSync, readdirSync, writeFileSync } from "node:fs";
|
|
21
|
+
import { tmpdir } from "node:os";
|
|
21
22
|
import { createRequire } from "node:module";
|
|
22
23
|
import { dirname, join, relative } from "node:path";
|
|
23
24
|
import { createInterface } from "node:readline/promises";
|
|
@@ -31,6 +32,7 @@ import { appendEntries, briefDecisions, lintDecisions, loadDecisions } from "./d
|
|
|
31
32
|
import { runKickoff } from "./kickoff.js";
|
|
32
33
|
import { runSlop } from "./slop.js";
|
|
33
34
|
import { runGuard } from "./guard.js";
|
|
35
|
+
import { runReport } from "./report.js";
|
|
34
36
|
|
|
35
37
|
const require = createRequire(import.meta.url);
|
|
36
38
|
// The rules/tokens data ships with @recanica/mcp. Run from a clone of this repo (e.g. a git
|
|
@@ -171,7 +173,7 @@ Install Recanica's parts; never copy components, CSS or pages out of the Recanic
|
|
|
171
173
|
**Build from the parts, never by hand:**
|
|
172
174
|
${NATIVE_STACKS.has(stack) ? "- Every colour, radius, spacing and text size comes from the generated Recanica tokens. No literal values in widgets." : `- **Page structure:** ${partsLine(stack)}.
|
|
173
175
|
- **Controls:** ${react ? "`Button`, `NavItem`, `ChoiceCard`, `Input`, `NativeSelect`, `Table`" : "`rc-btn`, `rc-nav-item`, `rc-choice`, `rc-input`, `rc-table`"}. No hand-styled buttons, inputs, selects or cards.`}
|
|
174
|
-
- **
|
|
176
|
+
- **Anything used twice is a shared part.** Don't ask which things to share: all of them. A missing part is added first (React and rc-* forms), never patched on one page.
|
|
175
177
|
- **Spacing and width:** owned by the container. Blocks carry no margins. Rhythm tokens by role: group · flow · stack · section · inset. No pixel values.
|
|
176
178
|
- **Only what the reader needs:** no badge, pill, label, eyebrow or button unless it carries information or an action the reader needs here. No status, request or report framing on a page that isn't a report.
|
|
177
179
|
|
|
@@ -226,6 +228,7 @@ jobs:
|
|
|
226
228
|
- run: npx -y recanica check
|
|
227
229
|
- run: npx -y recanica slop
|
|
228
230
|
- run: npx -y recanica decisions lint
|
|
231
|
+
- run: npx -y recanica report --offline
|
|
229
232
|
`, { onlyIfMissing: true });
|
|
230
233
|
const pkgPath = join(cwd, "package.json");
|
|
231
234
|
const pkg = readJson(pkgPath);
|
|
@@ -274,9 +277,44 @@ function writeGuards() {
|
|
|
274
277
|
if (target === ".githooks/pre-commit") { spawnSync("git", ["config", "core.hooksPath", ".githooks"], { cwd }); changes.push("git config core.hooksPath .githooks"); }
|
|
275
278
|
}
|
|
276
279
|
|
|
280
|
+
/* ---------- versions: projects keep up with Recanica ---------- */
|
|
281
|
+
const newer = (a, b) => { const p = (v) => String(v).split("-")[0].split(".").map(Number); const [x, y] = [p(a), p(b)]; for (let i = 0; i < 3; i++) if ((x[i] ?? 0) !== (y[i] ?? 0)) return (x[i] ?? 0) > (y[i] ?? 0); return false; };
|
|
282
|
+
/** The latest published version, cached for a day so start stays fast and works offline. */
|
|
283
|
+
function latestVersion() {
|
|
284
|
+
const cache = join(tmpdir(), "recanica-latest.json");
|
|
285
|
+
const c = readJson(cache);
|
|
286
|
+
if (c && Date.now() - c.at < 86_400_000) return c.version;
|
|
287
|
+
const r = spawnSync("npm", ["view", "recanica", "version"], { encoding: "utf8", timeout: 4000, shell: process.platform === "win32" });
|
|
288
|
+
const v = r.status === 0 ? r.stdout.trim() : null;
|
|
289
|
+
if (v) try { writeFileSync(cache, JSON.stringify({ at: Date.now(), version: v })); } catch {}
|
|
290
|
+
return v;
|
|
291
|
+
}
|
|
292
|
+
/** The version this project has installed (falls back to the running CLI). */
|
|
293
|
+
function projectVersion() { return readJson(join(cwd, "node_modules/recanica/package.json"))?.version ?? VERSION; }
|
|
294
|
+
|
|
295
|
+
function upgrade() {
|
|
296
|
+
const pm = detectPm();
|
|
297
|
+
const pkgPath = join(cwd, "package.json");
|
|
298
|
+
const pkg = readJson(pkgPath);
|
|
299
|
+
const before = projectVersion();
|
|
300
|
+
if (pkg) {
|
|
301
|
+
const deps = Object.keys(pkg.dependencies ?? {}).filter((n) => /^(@recanica\/|recanica$)/.test(n));
|
|
302
|
+
const dev = Object.keys(pkg.devDependencies ?? {}).filter((n) => /^(@recanica\/|recanica$)/.test(n));
|
|
303
|
+
if (!dev.includes("recanica") && !deps.includes("recanica")) dev.push("recanica");
|
|
304
|
+
if (deps.length) install(pm, deps.map((n) => `${n}@latest`));
|
|
305
|
+
install(pm, dev.map((n) => `${n}@latest`), true);
|
|
306
|
+
}
|
|
307
|
+
// Re-run init with the new version so AGENTS.md, skills, hooks and CI pick up the new rules. Your own config is kept.
|
|
308
|
+
const args = ["-y", "recanica@latest", "init", "--yes", "--skip-install", ...(flags.stack ? ["--stack", flags.stack] : [])];
|
|
309
|
+
log(c.dim(` npx ${args.join(" ")}`));
|
|
310
|
+
if (!dry) spawnSync("npx", args, { cwd, stdio: "inherit", shell: process.platform === "win32" });
|
|
311
|
+
log(`\n${c.bold("Recanica upgraded")} ${before} → ${projectVersion()}. Run ${c.bold("npx recanica report")} to see what the new rules find.`);
|
|
312
|
+
}
|
|
313
|
+
|
|
277
314
|
/* ---------- start: the one place every project and agent begins ---------- */
|
|
278
315
|
const START_RULES = `Rules that matter most (full set: npx recanica rules):
|
|
279
316
|
- Use the installed Recanica parts and tokens. Never hand-build a button, input, table or card, never copy code from the Recanica repo, never write your own version of a part that exists.
|
|
317
|
+
- Anything used twice is a shared part, built once and reused. Don't ask the person which things to share: all of them.
|
|
280
318
|
- No gradients, glass, glows, emoji icons or hard-coded colours. One brand colour; status colours only for status. Light/regular type.
|
|
281
319
|
- Spacing comes from the container and the rhythm tokens, never pixel values or margins on blocks.
|
|
282
320
|
- Show only what the reader needs: no badge, pill, label, eyebrow or extra button that carries no information or action. No status/request/report framing unless the page is a report.
|
|
@@ -288,6 +326,8 @@ const START_RULES = `Rules that matter most (full set: npx recanica rules):
|
|
|
288
326
|
function start() {
|
|
289
327
|
const cfg = loadConfig(cwd);
|
|
290
328
|
const out = [`Recanica · ${relative(process.env.HOME ?? "", cwd) || cwd}`];
|
|
329
|
+
const latest = flags.offline ? null : latestVersion();
|
|
330
|
+
if (latest && newer(latest, projectVersion())) out.push(`Recanica ${latest} is out (this project has ${projectVersion()}). Tell the human; with their OK run: npx recanica upgrade`);
|
|
291
331
|
if (!cfg.exists) {
|
|
292
332
|
out.push("", "Recanica is not set up in this project yet. Step 1, before any UI work:",
|
|
293
333
|
" npx recanica init (inside a bigger build: --role guest --owns \"src/ui/**\")",
|
|
@@ -468,6 +508,8 @@ const help = `recanica v${VERSION} · UI framework by Aturanica Labs
|
|
|
468
508
|
Usage
|
|
469
509
|
npx recanica start where every project and agent begins: says the next step (init, kickoff, build)
|
|
470
510
|
npx recanica guard [--staged] check the files you changed (pre-commit; --hook claude for the Stop hook)
|
|
511
|
+
npx recanica upgrade update the Recanica packages and refresh AGENTS.md, skills and hooks
|
|
512
|
+
npx recanica report [--url <dev url>] how closely this project follows Recanica: score, must-fix, slop, pages
|
|
471
513
|
npx recanica init [--stack <s>] [--role guest --owns "src/ui/**"] [--yes] [--dry-run] [--skip-install] [--pm <pm>]
|
|
472
514
|
stacks: ${Object.keys(STACKS).join(", ")} (auto-detected)
|
|
473
515
|
npx recanica add <pattern-or-block> copy a pattern/block into your app (shadcn registry)
|
|
@@ -486,7 +528,10 @@ Usage
|
|
|
486
528
|
|
|
487
529
|
switch (cmd) {
|
|
488
530
|
case "start": start(); break;
|
|
489
|
-
case "
|
|
531
|
+
case "upgrade": upgrade(); break;
|
|
532
|
+
case "report": process.exitCode = await runReport(cwd, flags, log, { version: projectVersion(), latest: flags.offline ? null : latestVersion(),
|
|
533
|
+
knownRules: new Set([...CHECK_RULES.map((r) => r[0]), "repeated-classes", "kickoff", ...RULE_LEVELS.must, ...RULE_LEVELS.should]) }); break;
|
|
534
|
+
case "guard": process.exitCode = await runGuard(cwd, flags, log); break;
|
|
490
535
|
case "init": await init(); break;
|
|
491
536
|
case "add": add(); break;
|
|
492
537
|
case "tokens": tokens(); break;
|
package/src/kickoff.js
CHANGED
|
@@ -21,41 +21,128 @@ import { FLEXIBILITY, loadConfig } from "./config.js";
|
|
|
21
21
|
import { appendEntries, loadDecisions } from "./decisions.js";
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
|
-
* The questions. Each: id, group, q (
|
|
25
|
-
*
|
|
24
|
+
* The questions, in plain words. Each: id, group, q (ask it exactly like this), why (one plain line), type, options, default.
|
|
25
|
+
* Every question has fixed options, so no agent has to invent people, teams or choices. An option with `free: true`
|
|
26
|
+
* means "the person types their own answer". `when` skips a question that doesn't apply; `askIf` says the same in words.
|
|
27
|
+
* Defaults are what Recanica recommends when the person has no opinion; `defaultFor` adjusts them to earlier answers.
|
|
26
28
|
*/
|
|
29
|
+
const solo = (a) => (a.team ?? "solo") === "solo";
|
|
27
30
|
export const QUESTIONS = [
|
|
28
|
-
{ id: "
|
|
29
|
-
{ id: "purpose", group: "Project", q: "In one sentence: what is it for, and who uses it?", why: "Every page brief starts from this reader.", type: "text", default: "" },
|
|
30
|
-
{ id: "surfaces", group: "Project", q: "What will the UI work produce?", why: "Each surface has its own patterns and checks.", type: "multi",
|
|
31
|
-
options: ["app", "site", "docs", "email", "mobile", "marketing assets"], default: ["app"] },
|
|
32
|
-
{ id: "locale", group: "Project", q: "Main locale for money, dates and names?", why: "Sample data and formats follow it.", type: "text", default: "en-MY" },
|
|
33
|
-
|
|
34
|
-
{ id: "role", group: "Role", q: "Does the UI work own this codebase, or is it one part of a bigger build?", why: "A guest changes only its own paths and proposes everything else.", type: "choice",
|
|
35
|
-
options: [{ value: "owner", label: "Owner: the UI team runs this codebase" }, { value: "guest", label: "Guest: we're the UI/UX part of someone else's build" }], default: "owner" },
|
|
36
|
-
{ id: "owns", group: "Role", q: "Guest only: which paths does the UI work own? (comma-separated globs)", why: "Checks block only here; elsewhere they're advice.", type: "list",
|
|
37
|
-
when: (a) => a.role === "guest", default: ["src/components/**", "src/styles/**"] },
|
|
38
|
-
{ id: "approver", group: "Role", q: "Who approves changes outside the UI scope (name or role)?", why: "Proposals go to them.", type: "text", when: (a) => a.role === "guest", default: "the tech lead" },
|
|
39
|
-
|
|
40
|
-
{ id: "stack", group: "Stack", q: "Which stack? (or 'unknown' if it isn't decided yet)", why: "Unknown starts CSS-first, so nothing has to be rewritten when the stack is chosen.", type: "choice",
|
|
41
|
-
options: ["nextjs", "vite-react", "react-other", "vue", "svelte", "astro", "angular", "html", "tailwind-v3", "flutter", "swiftui", "compose", "unknown"], default: "detected" },
|
|
42
|
-
|
|
43
|
-
{ id: "flexibility", group: "Flexibility", q: "How strict should the system be?", why: "Tokens are fixed in every mode; this sets how hard the composition and reuse rules push.", type: "choice",
|
|
31
|
+
{ id: "team", group: "You", q: "Who's building this?", why: "So we only ask what matters for how you work.", type: "choice",
|
|
44
32
|
options: [
|
|
45
|
-
{ value: "
|
|
46
|
-
{ value: "
|
|
47
|
-
{ value: "
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
33
|
+
{ value: "solo", label: "Just me, with AI helping" },
|
|
34
|
+
{ value: "small", label: "Me and a few other people" },
|
|
35
|
+
{ value: "team", label: "A bigger team" },
|
|
36
|
+
{ value: "guest", label: "I'm doing the design part of someone else's project" },
|
|
37
|
+
], default: "solo" },
|
|
38
|
+
|
|
39
|
+
{ id: "name", group: "The project", q: "What's the project called?", why: "Used as the title of the project notes.", type: "text", default: "" },
|
|
40
|
+
{ id: "purpose", group: "The project", q: "What is it, and who is it for? One sentence is enough.", why: "Every page is written for this person.", type: "text",
|
|
41
|
+
example: "A booking app for clinic patients in the Klang Valley.", default: "" },
|
|
42
|
+
{ id: "surfaces", group: "The project", q: "What are you making? Pick all that apply.", why: "Each kind has its own building blocks and checks.", type: "multi",
|
|
43
|
+
options: [
|
|
44
|
+
{ value: "app", label: "A web app people log into" },
|
|
45
|
+
{ value: "site", label: "A website" },
|
|
46
|
+
{ value: "mobile", label: "A phone app" },
|
|
47
|
+
{ value: "docs", label: "Help pages or documentation" },
|
|
48
|
+
{ value: "email", label: "Emails" },
|
|
49
|
+
{ value: "marketing assets", label: "Ads, social posts or slides" },
|
|
50
|
+
], default: ["app"] },
|
|
51
|
+
{ id: "locale", group: "The project", q: "Where are most of the people who'll use it?", why: "Money, dates and sample names follow it.", type: "choice",
|
|
52
|
+
options: [
|
|
53
|
+
{ value: "en-MY", label: "Malaysia, in English" },
|
|
54
|
+
{ value: "ms-MY", label: "Malaysia, in Bahasa Melayu" },
|
|
55
|
+
{ value: "en-SG", label: "Singapore" },
|
|
56
|
+
{ value: "id-ID", label: "Indonesia" },
|
|
57
|
+
{ value: "", label: "Somewhere else (type the country and language)", free: true },
|
|
58
|
+
], default: "en-MY" },
|
|
59
|
+
|
|
60
|
+
{ id: "owns", group: "Your part", q: "Which parts of the project are yours to change?", why: "Recanica only enforces its rules in your part. Elsewhere it gives advice.", type: "list",
|
|
61
|
+
when: (a) => a.team === "guest", askIf: "they're doing the design part of someone else's project",
|
|
62
|
+
options: [
|
|
63
|
+
{ value: ["src/components/**", "src/styles/**"], label: "The screens' building blocks and the styling" },
|
|
64
|
+
{ value: ["src/**"], label: "Everything on screen, but not the server side" },
|
|
65
|
+
{ value: null, label: "I'll name the folders", free: true },
|
|
66
|
+
], default: ["src/components/**", "src/styles/**"] },
|
|
67
|
+
{ id: "approver", group: "Your part", q: "Who do you ask before changing anything outside your part?", why: "Suggestions for their code go to them instead of being changed.", type: "text",
|
|
68
|
+
when: (a) => a.team === "guest", askIf: "they're doing the design part of someone else's project",
|
|
69
|
+
options: [
|
|
70
|
+
{ value: "the tech lead", label: "The project's tech lead" },
|
|
71
|
+
{ value: "the client", label: "The client" },
|
|
72
|
+
{ value: "", label: "Someone else (type their name)", free: true },
|
|
73
|
+
], default: "the tech lead" },
|
|
51
74
|
|
|
52
|
-
{ id: "
|
|
53
|
-
|
|
54
|
-
|
|
75
|
+
{ id: "stack", group: "How it's built", q: "What is it being built with?", why: "If it isn't decided, we start in a way that works with anything later.", type: "choice",
|
|
76
|
+
options: [
|
|
77
|
+
{ value: "detected", label: "What's already in the project (Recanica found it)" },
|
|
78
|
+
{ value: "nextjs", label: "Next.js" },
|
|
79
|
+
{ value: "vite-react", label: "React with Vite" },
|
|
80
|
+
{ value: "react-other", label: "Another React setup" },
|
|
81
|
+
{ value: "vue", label: "Vue or Nuxt" },
|
|
82
|
+
{ value: "svelte", label: "Svelte" },
|
|
83
|
+
{ value: "astro", label: "Astro" },
|
|
84
|
+
{ value: "angular", label: "Angular" },
|
|
85
|
+
{ value: "html", label: "Plain HTML, WordPress, Laravel or similar" },
|
|
86
|
+
{ value: "tailwind-v3", label: "An older Tailwind (version 3) setup" },
|
|
87
|
+
{ value: "flutter", label: "Flutter" },
|
|
88
|
+
{ value: "swiftui", label: "iPhone app (SwiftUI)" },
|
|
89
|
+
{ value: "compose", label: "Android app (Jetpack Compose)" },
|
|
90
|
+
{ value: "unknown", label: "Not decided yet" },
|
|
91
|
+
], default: "detected" },
|
|
92
|
+
|
|
93
|
+
{ id: "flexibility", group: "How strict", q: "How strict should Recanica be?", why: "Colours and type stay fixed either way. This is about how much freedom pages get.", type: "choice",
|
|
94
|
+
options: [
|
|
95
|
+
{ value: "guided", label: "Balanced (recommended): the basics are enforced; small exceptions are fine with a reason" },
|
|
96
|
+
{ value: "locked", label: "Very strict: every exception needs a written reason. Good for big teams." },
|
|
97
|
+
{ value: "open", label: "Relaxed: for campaign or one-off creative pages. Layout is free." },
|
|
98
|
+
], default: "guided" },
|
|
99
|
+
{ id: "openZones", group: "How strict", q: "Is there a part that should be more relaxed than the rest, like campaign pages?", why: "That part can be art-directed while the rest stays consistent.", type: "list",
|
|
100
|
+
when: (a) => !solo(a), askIf: "more than one person is building it",
|
|
101
|
+
options: [
|
|
102
|
+
{ value: [], label: "No" },
|
|
103
|
+
{ value: null, label: "Yes (name the folder, e.g. src/campaigns)", free: true },
|
|
104
|
+
], default: [] },
|
|
105
|
+
{ id: "brand", group: "How strict", q: "Do you have a brand colour and font yet?", why: "The brand colour is the one colour meant to change.", type: "text",
|
|
106
|
+
options: [
|
|
107
|
+
{ value: "later", label: "Not yet, use the defaults for now" },
|
|
108
|
+
{ value: "", label: "Yes (type the colour code and the font)", free: true },
|
|
109
|
+
], default: "later" },
|
|
55
110
|
|
|
56
|
-
{ id: "
|
|
111
|
+
{ id: "reviewTarget", group: "When it's done", q: "How polished must a page be before it counts as done?", why: "Recanica scores each page; this is the bar.", type: "number",
|
|
112
|
+
options: [
|
|
113
|
+
{ value: 85, label: "Polished (recommended)" },
|
|
114
|
+
{ value: 75, label: "Good enough for a first version" },
|
|
115
|
+
{ value: 95, label: "Very polished" },
|
|
116
|
+
], default: 85 },
|
|
117
|
+
{ id: "reviewer", group: "When it's done", q: "Who checks a page before it counts as finished?", why: "The automatic checks catch broken rules. A person judges whether it feels right.", type: "text",
|
|
118
|
+
options: [
|
|
119
|
+
{ value: "me", label: "Me" },
|
|
120
|
+
{ value: "the client", label: "The client" },
|
|
121
|
+
{ value: "", label: "Someone else (type their name)", free: true },
|
|
122
|
+
{ value: "nobody", label: "Nobody for now, just the automatic checks" },
|
|
123
|
+
], default: "me" },
|
|
124
|
+
{ id: "references", group: "When it's done", q: "Any apps or websites you like the look of, and any you don't?", why: "Knowing why you like them helps every new page.", type: "text",
|
|
125
|
+
options: [
|
|
126
|
+
{ value: "later", label: "Later" },
|
|
127
|
+
{ value: "", label: "Yes (name them, with a few words on why)", free: true },
|
|
128
|
+
], default: "later" },
|
|
129
|
+
{ id: "scale", group: "When it's done", q: "Roughly how big will it be?", why: "A small project can rely on checking each page; a big one needs templates.", type: "text",
|
|
130
|
+
options: [
|
|
131
|
+
{ value: "small: up to 10 pages or screens", label: "Small: up to 10 pages or screens" },
|
|
132
|
+
{ value: "medium: 10 to 50 pages or screens", label: "Medium: 10 to 50" },
|
|
133
|
+
{ value: "large: more than 50 pages or screens", label: "Large: more than 50" },
|
|
134
|
+
], default: "" },
|
|
57
135
|
];
|
|
58
136
|
|
|
137
|
+
/** The default for a question, given the answers so far. */
|
|
138
|
+
export function defaultFor(q, a = {}) {
|
|
139
|
+
if (q.id === "flexibility" && a.team === "team") return "locked";
|
|
140
|
+
if (q.id === "reviewer" && a.team === "guest") return "the client";
|
|
141
|
+
return q.default;
|
|
142
|
+
}
|
|
143
|
+
const optLabel = (o) => (typeof o === "string" ? o : o.label);
|
|
144
|
+
const optValue = (o) => (typeof o === "string" ? o : o.value);
|
|
145
|
+
|
|
59
146
|
const SURFACE_CHECKS = {
|
|
60
147
|
app: "page anatomy + recanica-page briefs", site: "web recipes + WebSection parts", docs: "reading column + reference tables",
|
|
61
148
|
email: "table-based HTML (inline hex is an accepted deviation)", mobile: "tokens for Flutter / SwiftUI / Compose", "marketing assets": "open zone + slop check on every headline",
|
|
@@ -65,28 +152,41 @@ export function questionsFor(answers = {}) { return QUESTIONS.filter((q) => !q.w
|
|
|
65
152
|
|
|
66
153
|
function normalise(a, detected) {
|
|
67
154
|
const out = { ...a };
|
|
155
|
+
// Older answer files set role directly; newer ones answer "who's building this".
|
|
156
|
+
if (!out.team) out.team = out.role === "guest" ? "guest" : "solo";
|
|
68
157
|
for (const q of QUESTIONS) {
|
|
69
158
|
let v = out[q.id];
|
|
70
|
-
if (v === undefined || v === ""
|
|
159
|
+
if (v === undefined || v === "" || v === null) { const d = defaultFor(q, out); v = d === "detected" ? detected : d; }
|
|
160
|
+
if (v === "detected") v = detected;
|
|
71
161
|
if (q.type === "list" && typeof v === "string") v = v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
72
162
|
if (q.type === "multi" && typeof v === "string") v = v.split(",").map((s) => s.trim()).filter(Boolean);
|
|
73
163
|
if (q.type === "number") v = Number(v) || q.default;
|
|
74
164
|
out[q.id] = v;
|
|
75
165
|
}
|
|
166
|
+
out.role = out.team === "guest" || out.role === "guest" ? "guest" : "owner";
|
|
76
167
|
if (!FLEXIBILITY[out.flexibility]) out.flexibility = "guided";
|
|
77
|
-
if (out.role !== "guest") {
|
|
168
|
+
if (out.role !== "guest") { delete out.owns; delete out.approver; }
|
|
78
169
|
return out;
|
|
79
170
|
}
|
|
80
171
|
|
|
172
|
+
const ASK_RULES = `How to ask (for AI agents):
|
|
173
|
+
- Ask in these exact words, one group at a time, and offer exactly these options. Use your multiple-choice tool where you have one.
|
|
174
|
+
- Never invent options, people, teams or roles. Don't guess names from the codebase or git history.
|
|
175
|
+
- "(type …)" options mean the person types their own answer.
|
|
176
|
+
- Skip a question whose "ask only if" doesn't hold. Never answer for the person.
|
|
177
|
+
- Save the answers as JSON keyed by id (use the option's value), then run \`npx recanica kickoff --answers <file>\`.`;
|
|
178
|
+
|
|
179
|
+
export { ASK_RULES };
|
|
81
180
|
export function printQuestions(log, json) {
|
|
82
|
-
|
|
181
|
+
const pub = QUESTIONS.map(({ when, ...q }) => ({ ...q, options: q.options?.map((o) => ({ value: optValue(o), label: optLabel(o), ...(o.free ? { free: true } : {}) })) }));
|
|
182
|
+
if (json) { process.stdout.write(JSON.stringify({ howToAsk: ASK_RULES, questions: pub }, null, 2) + "\n"); return; }
|
|
183
|
+
log(`Recanica kickoff\n\n${ASK_RULES}`);
|
|
83
184
|
let g = "";
|
|
84
|
-
|
|
85
|
-
log("keyed by id, then run `npx recanica kickoff --answers <file>`.\n");
|
|
86
|
-
for (const q of QUESTIONS) {
|
|
185
|
+
for (const q of pub) {
|
|
87
186
|
if (q.group !== g) { g = q.group; log(`\n## ${g}`); }
|
|
88
|
-
|
|
89
|
-
|
|
187
|
+
log(`- ${q.id}: ${q.q}${q.askIf ? ` (ask only if ${q.askIf})` : ""}\n why: ${q.why}${q.example ? `\n e.g. ${q.example}` : ""}`);
|
|
188
|
+
for (const o of q.options ?? []) log(` · ${o.label}${o.free ? "" : ` → ${JSON.stringify(o.value)}`}`);
|
|
189
|
+
log(` default: ${JSON.stringify(q.default)}`);
|
|
90
190
|
}
|
|
91
191
|
}
|
|
92
192
|
|
|
@@ -97,13 +197,17 @@ async function ask(detected) {
|
|
|
97
197
|
for (const q of QUESTIONS) {
|
|
98
198
|
if (q.when && !q.when(a)) continue;
|
|
99
199
|
if (q.group !== g) { g = q.group; console.log(`\n\x1b[1m${g}\x1b[0m`); }
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
const
|
|
200
|
+
let def = defaultFor(q, a);
|
|
201
|
+
if (def === "detected") def = detected;
|
|
202
|
+
const opts = q.options ?? [];
|
|
203
|
+
opts.forEach((o, i) => console.log(` ${i + 1}. ${optLabel(o)}${optValue(o) === "detected" ? ` (${detected})` : ""}`));
|
|
204
|
+
const defIdx = opts.findIndex((o) => JSON.stringify(optValue(o)) === JSON.stringify(def) || (optValue(o) === "detected" && def === detected));
|
|
205
|
+
const shown = defIdx >= 0 ? String(defIdx + 1) : Array.isArray(def) ? def.join(", ") : def;
|
|
103
206
|
const r = (await rl.question(`${q.q} \x1b[2m${q.why}\x1b[0m\n> ${shown !== "" ? `[${shown}] ` : ""}`)).trim();
|
|
104
207
|
if (!r) { a[q.id] = def; continue; }
|
|
105
|
-
|
|
106
|
-
if (q.type === "multi" && /^[\d,\s]+$/.test(r)) { a[q.id] = r.split(",").map((n) =>
|
|
208
|
+
const pick = async (o) => (o?.free ? (await rl.question(" Type it: ")).trim() : optValue(o));
|
|
209
|
+
if (opts.length && q.type === "multi" && /^[\d,\s]+$/.test(r)) { a[q.id] = r.split(",").map((n) => optValue(opts[Number(n.trim()) - 1])).filter((v) => v != null); continue; }
|
|
210
|
+
if (opts.length && /^\d+$/.test(r) && opts[Number(r) - 1]) { const v = await pick(opts[Number(r) - 1]); a[q.id] = v === "detected" ? detected : v; continue; }
|
|
107
211
|
a[q.id] = r;
|
|
108
212
|
}
|
|
109
213
|
rl.close();
|
|
@@ -131,7 +235,7 @@ ${a.role === "guest"
|
|
|
131
235
|
- Inside those paths, Recanica's checks block the build.
|
|
132
236
|
- Outside them, findings are advice: raise them in \`docs/ui/PROPOSALS.md\` for ${a.approver || "the code owners"} to decide. Don't change that code.
|
|
133
237
|
- Build config, routing, data, state, dependencies and CI belong to the wider team.`
|
|
134
|
-
:
|
|
238
|
+
: `**Owner** (${{ solo: "just you, with AI helping", small: "you and a few others", team: "a bigger team" }[a.team] ?? "you"}). The checks apply to the whole project.`}
|
|
135
239
|
|
|
136
240
|
## Stack
|
|
137
241
|
**${a.stack}.** ${a.stack === "unknown" ? "Start CSS-first: tokens + `@recanica/css` (`rc-*` classes) in plain HTML or Vite. The classes are the contract, so moving to React, Vue or Svelte later swaps the adapter, not the design. See docs/STACKS.md." : "See docs/STACKS.md for what Recanica ships for this stack."}
|
|
@@ -146,7 +250,7 @@ ${(a.openZones ?? []).length ? `Open zones (tokens fixed, composition free): ${a
|
|
|
146
250
|
## Done means
|
|
147
251
|
- A brief exists (recanica-page skill) and the page was looked at at 375px and 1280px.
|
|
148
252
|
- \`recanica review\` scores ${a.reviewTarget}+ with nothing under 70; \`recanica audit\` and \`recanica check\` show 0 must-fix; \`recanica slop\` shows 0 must-fix.
|
|
149
|
-
- ${a.reviewer || "_someone other than the author_"} has looked at it
|
|
253
|
+
- ${a.reviewer === "me" ? "You have looked at it (the AI built it; you judge it)." : a.reviewer === "nobody" ? "_Nobody reviews by eye yet: only the automatic checks. Taste isn't checked._" : `${a.reviewer || "_someone other than the author_"} has looked at it.`}
|
|
150
254
|
- Any UI/UX decision made on the way is in \`docs/ui/DECISIONS.md\`.
|
|
151
255
|
|
|
152
256
|
**References (right / wrong, and why):** ${a.references}
|
|
@@ -192,7 +296,7 @@ export async function runKickoff(root, flags, log, { detectStack }) {
|
|
|
192
296
|
const before = cfg.project ?? null;
|
|
193
297
|
cfg.project = {
|
|
194
298
|
name: a.name || before?.name || "", kickoffDate: date, kickoff: "docs/ui/KICKOFF.md",
|
|
195
|
-
role: a.role, flexibility: a.flexibility, stack: a.stack, surfaces: a.surfaces, locale: a.locale,
|
|
299
|
+
team: a.team, role: a.role, flexibility: a.flexibility, stack: a.stack, surfaces: a.surfaces, locale: a.locale,
|
|
196
300
|
...((a._assumed ?? []).length ? { assumed: a._assumed } : {}),
|
|
197
301
|
done: { reviewTarget: a.reviewTarget, reviewer: a.reviewer || null },
|
|
198
302
|
};
|
|
@@ -225,9 +329,9 @@ export async function runKickoff(root, flags, log, { detectStack }) {
|
|
|
225
329
|
const prev = [...entries].reverse().find((e) => e.active && e.fields["kickoff"] === key);
|
|
226
330
|
seeds.push({ kind: "decision", title, date, area: key === "stack" ? "stack" : "process", decision, why, rejected, guard, prev, extra: { Kickoff: key, Supersedes: prev?.id } });
|
|
227
331
|
};
|
|
228
|
-
seed("role", a.role === "guest" ? "The UI work is a guest in this codebase" : "
|
|
332
|
+
seed("role", a.role === "guest" ? "The UI work is a guest in this codebase" : "We own this whole codebase",
|
|
229
333
|
a.role === "guest" ? `Change only ${a.owns.join(", ")}; propose everything else in docs/ui/PROPOSALS.md for ${a.approver}.` : "Recanica's checks apply to the whole codebase.",
|
|
230
|
-
a.role === "guest" ? "The UI is one part of a bigger build; changing other teams' code from a UI task breaks their work and their trust." : "
|
|
334
|
+
a.role === "guest" ? "The UI is one part of a bigger build; changing other teams' code from a UI task breaks their work and their trust." : "The people building it decide the UI end to end, so one set of rules can apply everywhere.",
|
|
231
335
|
a.role === "guest" ? "Applying the checks everywhere (would fail other teams' builds); no scope at all (UI changes leak into routing and data code)." : "Guest mode (nobody else owns the UI code).");
|
|
232
336
|
seed("flexibility", `Flexibility is ${a.flexibility}`, `Run Recanica in ${a.flexibility} mode${(a.openZones ?? []).length ? `, with open zones ${a.openZones.join(", ")}` : ""}.`,
|
|
233
337
|
a.flexibility === "locked" ? "Many contributors and agents build pages; every deviation needs to be a visible, reviewable decision." : a.flexibility === "open" ? "The work is art-directed per piece; composition has to be free while tokens keep it on brand." : "Reuse and structure must hold from day one; style deviations happen and need a reason, not a fight.",
|
|
@@ -251,7 +355,7 @@ export async function runKickoff(root, flags, log, { detectStack }) {
|
|
|
251
355
|
if (a.role === "guest") put("docs/ui/PROPOSALS.md", PROPOSALS, true);
|
|
252
356
|
|
|
253
357
|
if (flags.json) { process.stdout.write(JSON.stringify({ answers: a, changes }, null, 2) + "\n"); return 0; }
|
|
254
|
-
log(`\nKickoff recorded (${a.
|
|
358
|
+
log(`\nKickoff recorded (${a.team}, ${a.flexibility}, ${a.stack}).`);
|
|
255
359
|
for (const ch of changes) log(` • ${ch}`);
|
|
256
360
|
log(`\nNext: build the shared parts the kickoff skill lists, then start pages with the recanica-page skill.`);
|
|
257
361
|
return 0;
|
package/src/report.js
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* recanica report — how closely a project follows Recanica, in one page.
|
|
3
|
+
*
|
|
4
|
+
* npx recanica report code: must-fix, slop, shared parts, kickoff, decisions, version
|
|
5
|
+
* npx recanica report --url http://localhost:3000 also the rendered pages (crawls up to 30 pages at 375 / 1280px)
|
|
6
|
+
* npx recanica report --out recanica-report.md write it to a file (CI artifact, weekly check)
|
|
7
|
+
* npx recanica report --json
|
|
8
|
+
*
|
|
9
|
+
* Status: on track (nothing must-fix, kickoff done, current version) · needs attention · off track (must-fix found).
|
|
10
|
+
* Always exits 0 so it can run on a schedule; add --strict to fail when the status is off track.
|
|
11
|
+
*/
|
|
12
|
+
import { writeFileSync } from "node:fs";
|
|
13
|
+
import { join } from "node:path";
|
|
14
|
+
import { check } from "./check.js";
|
|
15
|
+
import { loadConfig } from "./config.js";
|
|
16
|
+
import { lintDecisions, loadDecisions } from "./decisions.js";
|
|
17
|
+
import { SLOP } from "./slop-list.js";
|
|
18
|
+
|
|
19
|
+
const SLOP_IDS = new Set(["copy", "design-slop", "gradient", ...SLOP.map((s) => s.id)]);
|
|
20
|
+
const SHARED_IDS = new Set(["hand-built", "structure", "repeated-classes"]);
|
|
21
|
+
|
|
22
|
+
export async function runReport(root, flags, log, { version, latest, knownRules }) {
|
|
23
|
+
const cfg = loadConfig(root);
|
|
24
|
+
const { files, hits } = check(root, flags._ ?? [], { all: true });
|
|
25
|
+
const must = hits.filter((h) => h.level === "error");
|
|
26
|
+
const should = hits.filter((h) => h.level !== "error" && h.rule !== "kickoff");
|
|
27
|
+
const slop = hits.filter((h) => SLOP_IDS.has(h.rule));
|
|
28
|
+
const shared = hits.filter((h) => SHARED_IDS.has(h.rule));
|
|
29
|
+
const byRule = new Map();
|
|
30
|
+
for (const h of hits) if (h.rule !== "kickoff") byRule.set(h.rule, (byRule.get(h.rule) ?? 0) + 1);
|
|
31
|
+
const top = [...byRule].sort((a, b) => b[1] - a[1]).slice(0, 8);
|
|
32
|
+
const decisions = loadDecisions(cfg);
|
|
33
|
+
const decisionErrors = lintDecisions(cfg, knownRules).filter((p) => p.level === "error").length;
|
|
34
|
+
|
|
35
|
+
let rendered = null;
|
|
36
|
+
const url = typeof flags.url === "string" ? flags.url : cfg.devUrl;
|
|
37
|
+
if (url) {
|
|
38
|
+
const { auditPages } = await import("./audit.js");
|
|
39
|
+
const r = await auditPages([new URL("/", url).href], { widths: [375, 1280], crawl: true, maxPages: Number(flags.pages) || 30 }).catch(() => null);
|
|
40
|
+
rendered = r ? { pages: r.pages, must: r.must, should: r.should, failingPages: new Set(r.results.filter((x) => x.must.length).map((x) => new URL(x.url).pathname)).size,
|
|
41
|
+
top: [...r.results.flatMap((x) => x.must.map((i) => i.rule)).reduce((m, k) => m.set(k, (m.get(k) ?? 0) + 1), new Map())].sort((a, b) => b[1] - a[1]).slice(0, 6) } : { error: "Playwright isn't installed, or the site didn't respond" };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const outdated = latest && version && latest !== version;
|
|
45
|
+
const offTrack = must.length > 0 || (rendered?.must ?? 0) > 0 || decisionErrors > 0;
|
|
46
|
+
const attention = !cfg.project || outdated || should.length > 20 || shared.length > 0;
|
|
47
|
+
const status = offTrack ? "off track" : attention ? "needs attention" : "on track";
|
|
48
|
+
|
|
49
|
+
const data = {
|
|
50
|
+
status, version, latest, kickoff: !!cfg.project, files, must: must.length, should: should.length,
|
|
51
|
+
slop: { must: slop.filter((h) => h.level === "error").length, should: slop.filter((h) => h.level !== "error").length },
|
|
52
|
+
sharedParts: { findings: shared.length, handBuilt: shared.filter((h) => h.rule === "hand-built").length, repeated: shared.filter((h) => h.rule === "repeated-classes").length },
|
|
53
|
+
decisions: { entries: decisions.entries.length, errors: decisionErrors }, top, rendered,
|
|
54
|
+
};
|
|
55
|
+
if (flags.json) { process.stdout.write(JSON.stringify(data, null, 2) + "\n"); return flags.strict && offTrack ? 1 : 0; }
|
|
56
|
+
|
|
57
|
+
const next = [];
|
|
58
|
+
if (!cfg.project) next.push("Run the kickoff: `npx recanica kickoff`.");
|
|
59
|
+
if (outdated) next.push(`Upgrade Recanica (${version} → ${latest}): \`npx recanica upgrade\`.`);
|
|
60
|
+
if (must.length) next.push(`Fix the ${must.length} must-fix findings in the code: \`npx recanica check\`.`);
|
|
61
|
+
if (rendered?.must) next.push(`Fix the ${rendered.failingPages} page${rendered.failingPages === 1 ? "" : "s"} that fail on screen: \`npx recanica audit ${url} --crawl\`.`);
|
|
62
|
+
if (shared.length) next.push(`Replace ${shared.length} hand-built or copied pieces with shared parts.`);
|
|
63
|
+
if (slop.length) next.push(`Clear the slop: \`npx recanica slop\` (list: \`npx recanica slop --list\`).`);
|
|
64
|
+
if (decisionErrors) next.push("Fix the decision log: `npx recanica decisions lint`.");
|
|
65
|
+
|
|
66
|
+
const md = `# Recanica report · ${cfg.project?.name || root.split("/").pop()}
|
|
67
|
+
|
|
68
|
+
**Status: ${status}.** ${new Date().toISOString().slice(0, 10)}
|
|
69
|
+
|
|
70
|
+
| | |
|
|
71
|
+
|---|---|
|
|
72
|
+
| Recanica version | ${version}${outdated ? ` (latest ${latest})` : latest ? " (latest)" : ""} |
|
|
73
|
+
| Kickoff | ${cfg.project ? "done" : "not done"} |
|
|
74
|
+
| Must-fix in code | ${must.length} (${files} files) |
|
|
75
|
+
| Should-fix in code | ${should.length} |
|
|
76
|
+
| AI slop | ${data.slop.must} must-fix · ${data.slop.should} should |
|
|
77
|
+
| Shared parts | ${shared.length ? `${data.sharedParts.handBuilt} hand-built · ${data.sharedParts.repeated} copied class strings` : "all pages use shared parts"} |
|
|
78
|
+
| Decision log | ${decisions.entries.length} entries${decisionErrors ? ` · ${decisionErrors} problems` : ""} |
|
|
79
|
+
${rendered ? (rendered.error ? `| Rendered pages | not checked: ${rendered.error} |\n` : `| Rendered pages | ${rendered.pages} checked at 375 / 1280px · ${rendered.failingPages} failing · ${rendered.must} must-fix |\n`) : "| Rendered pages | not checked (add --url, or set devUrl in recanica.config.json) |\n"}
|
|
80
|
+
${top.length ? `## Most frequent findings\n\n${top.map(([r, n]) => `- ${r}: ${n}`).join("\n")}\n` : ""}${rendered?.top?.length ? `\n## On screen\n\n${rendered.top.map(([r, n]) => `- ${r}: ${n}`).join("\n")}\n` : ""}
|
|
81
|
+
## Next
|
|
82
|
+
${next.length ? next.map((n) => `- ${n}`).join("\n") : "- Nothing. Keep the guards on."}
|
|
83
|
+
`;
|
|
84
|
+
if (typeof flags.out === "string") { writeFileSync(join(root, flags.out), md); log(`Wrote ${flags.out} · status: ${status}`); }
|
|
85
|
+
else log(md);
|
|
86
|
+
return flags.strict && offTrack ? 1 : 0;
|
|
87
|
+
}
|
package/src/review.js
CHANGED
|
@@ -45,6 +45,8 @@ const FIXES = {
|
|
|
45
45
|
"page-overflow": "The page scrolls sideways: find the element wider than the screen (a table, a long word, a fixed width) and let it wrap, scroll inside its own box, or shrink.",
|
|
46
46
|
"text-overflow": "Text runs out of its box: let it wrap, or give the box room; don't fix widths on text.",
|
|
47
47
|
"clipped-text": "Text is cut off without an ellipsis: let it wrap, or add text-overflow: ellipsis with the full text in a title.",
|
|
48
|
+
"sideways-scroll": "A column scrolls sideways (usually a sidebar or panel with overflow-y: auto, which turns overflow-x to auto too). Use the Recanica sidebar part, or set overflow-x: hidden and let menu labels wrap. Mark a deliberate sideways strip with data-scroll=\"x\".",
|
|
49
|
+
"truncated-label": "A menu or button label is cut off with …: menu labels wrap onto the next line (the Recanica sidebar part does); a button label that doesn't fit needs fewer words.",
|
|
48
50
|
"wrapped-label": "A short label breaks onto two lines: keep labels on one line (shorter words, white-space: nowrap, or more room).",
|
|
49
51
|
"overlap": "One item paints into the next: give the row room, let items wrap, or truncate the long one.",
|
|
50
52
|
"table-edges": "The first and last cells sit at different distances from the table edge: use equal padding on both ends.",
|
|
@@ -56,7 +58,7 @@ const FIXES = {
|
|
|
56
58
|
"unlabelled-field": "A field has no label: add a <label for> (or aria-label), not just a placeholder.",
|
|
57
59
|
"duplicate-id": "Two elements share an id: ids must be unique, or labels and links point at the wrong one.",
|
|
58
60
|
};
|
|
59
|
-
const LAYOUT_RULES = new Set(["overlap", "table-edges", "surface-padding", "stretched-rows", "text-overflow", "clipped-text", "page-overflow", "wrapped-label"]);
|
|
61
|
+
const LAYOUT_RULES = new Set(["sideways-scroll", "truncated-label", "overlap", "table-edges", "surface-padding", "stretched-rows", "text-overflow", "clipped-text", "page-overflow", "wrapped-label"]);
|
|
60
62
|
|
|
61
63
|
export function scorePage(p, config = { rules: {}, allow: [] }) {
|
|
62
64
|
const by = Object.fromEntries(Object.keys(DIMENSIONS).map((d) => [d, []]));
|
package/src/test.mjs
CHANGED
|
@@ -202,6 +202,21 @@ console.log("✓ check");
|
|
|
202
202
|
await faq.setContent(`<html><body style="margin:0;background:#000">${grad("#f0e6ff, #111111")}</body></html>`);
|
|
203
203
|
assert.ok((await faq.evaluate(auditQuality)).findings.some((f) => f.rule === "contrast"), "quality: a near-black gradient stop fails contrast");
|
|
204
204
|
console.log("✓ closed FAQ links are not unnamed; ragged sections and lone words fire; gradient text measured by its stops");
|
|
205
|
+
// A sidebar with overflow-y:auto and a long label scrolls sideways; the Recanica sidebar part doesn't, and says the label is too long.
|
|
206
|
+
const css = readFileSync(join(import.meta.dirname, "../../css/src/components.css"), "utf8");
|
|
207
|
+
const side = (cls) => `<html><body style="margin:0"><style>${css}</style><nav class="${cls}" style="height:300px;width:180px"><a class="rc-nav-item" href="/n"><span>Nav item</span></a><a class="rc-nav-item" href="/b"><span>Breadcrumb and pagination with a much longer label</span></a></nav><div data-scroll="x" style="display:block;overflow-x:auto;width:200px"><div style="width:600px">wide strip</div></div></body></html>`;
|
|
208
|
+
await faq.setContent(side("x").replace('class="x" style="', 'style="overflow-y:auto;').replaceAll('class="rc-nav-item"', 'style="display:block;white-space:nowrap"'));
|
|
209
|
+
const handMade = (await faq.evaluate(auditPage)).map((i) => i.rule);
|
|
210
|
+
assert.ok(handMade.includes("sideways-scroll"), "audit: a hand-made sidebar that scrolls sideways fires");
|
|
211
|
+
assert.equal(handMade.filter((r) => r === "sideways-scroll").length, 1, "audit: a data-scroll=x strip is not flagged");
|
|
212
|
+
await faq.setContent(side("rc-sidebar"));
|
|
213
|
+
const part = (await faq.evaluate(auditPage)).map((i) => i.rule);
|
|
214
|
+
assert.ok(!part.includes("sideways-scroll") && !part.includes("truncated-label") && !part.includes("text-overflow"), `audit: the rc-sidebar part keeps long labels whole (${part})`);
|
|
215
|
+
const lines = await faq.evaluate(() => { const s = document.querySelectorAll(".rc-nav-item span")[1]; return Math.round(s.getBoundingClientRect().height / parseFloat(getComputedStyle(s).lineHeight || "20")); });
|
|
216
|
+
assert.ok(lines >= 2, "audit: the long label wraps onto a second line");
|
|
217
|
+
await faq.setContent(side("rc-sidebar").replace("</style>", "</style><style>.rc-nav-item span{white-space:nowrap;overflow:hidden;text-overflow:ellipsis}</style>"));
|
|
218
|
+
assert.ok((await faq.evaluate(auditPage)).some((i) => i.rule === "truncated-label"), "audit: a menu label cut off with … fails");
|
|
219
|
+
console.log("✓ sideways-scrolling columns fire; sidebar labels wrap, and cut-off labels fail");
|
|
205
220
|
const layout = new Set((await page.evaluate(auditPage)).map((i) => i.rule));
|
|
206
221
|
await browser.close();
|
|
207
222
|
for (const r of ["spec-color", "spec-weight", "spec-button", "spec-radius", "spec-copy", "inconsistent"]) assert.ok(spec.has(r), `audit: ${r} should fire`);
|
|
@@ -381,3 +396,53 @@ console.log("✓ check");
|
|
|
381
396
|
assert.match(run(d, "slop", "--list"), /01, 02, 03[\s\S]*Tabs/, "slop --list prints the list");
|
|
382
397
|
console.log("✓ AI-slop list: caught and not over-caught");
|
|
383
398
|
}
|
|
399
|
+
|
|
400
|
+
// Kickoff in plain words: "who's building this" decides what else is asked and the defaults.
|
|
401
|
+
{
|
|
402
|
+
const { QUESTIONS, questionsFor } = await import("./kickoff.js");
|
|
403
|
+
for (const q of QUESTIONS) {
|
|
404
|
+
assert.ok(q.type === "text" && !q.options ? ["name", "purpose"].includes(q.id) : q.options?.length, `kickoff: ${q.id} has fixed options`);
|
|
405
|
+
assert.doesNotMatch(q.q, /\b(glob|token|flexib|owner|guest|stack|locale|scope|UI work)\b/i, `kickoff: ${q.id} asks without jargon`);
|
|
406
|
+
}
|
|
407
|
+
const soloAsked = questionsFor({ team: "solo" }).map((q) => q.id);
|
|
408
|
+
for (const id of ["owns", "approver", "openZones"]) assert.ok(!soloAsked.includes(id), `kickoff: solo isn't asked ${id}`);
|
|
409
|
+
assert.ok(questionsFor({ team: "guest" }).some((q) => q.id === "owns"), "kickoff: guest is asked which parts are theirs");
|
|
410
|
+
const d = fixture({ "pubspec.yaml": "name: app\n" });
|
|
411
|
+
writeFileSync(join(d, "a.json"), JSON.stringify({ team: "solo", name: "Klinik app" }));
|
|
412
|
+
run(d, "kickoff", "--answers", "a.json");
|
|
413
|
+
const p = JSON.parse(readFileSync(join(d, "recanica.config.json"), "utf8")).project;
|
|
414
|
+
assert.equal(p.role, "owner"); assert.equal(p.done.reviewer, "me", "kickoff: solo → you check the pages");
|
|
415
|
+
assert.match(readFileSync(join(d, "docs/ui/KICKOFF.md"), "utf8"), /You have looked at it/);
|
|
416
|
+
writeFileSync(join(d, "a.json"), JSON.stringify({ team: "team" }));
|
|
417
|
+
run(d, "kickoff", "--answers", "a.json");
|
|
418
|
+
assert.equal(JSON.parse(readFileSync(join(d, "recanica.config.json"), "utf8")).project.flexibility, "locked", "kickoff: a bigger team defaults to very strict");
|
|
419
|
+
console.log("✓ kickoff: plain questions, fixed options, team-aware defaults");
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// Consistency over time: the guard looks at changed pages on the dev server; report and upgrade exist.
|
|
423
|
+
{
|
|
424
|
+
const { routesFor } = await import("./guard.js");
|
|
425
|
+
assert.deepEqual(routesFor(["app/(marketing)/pricing/page.tsx", "app/orders/[id]/page.tsx", "src/routes/blog/+page.svelte"]), ["/pricing", "/blog"], "guard: routes from changed files, groups dropped, dynamic skipped");
|
|
426
|
+
assert.deepEqual(routesFor(["src/components/Button.tsx"]), ["/"], "guard: a changed shared part → look at the home page");
|
|
427
|
+
const { createServer } = await import("node:http");
|
|
428
|
+
const d = fixture({ ".gitignore": "node_modules\n", "package.json": "{}", "index.html": '<html><body style="margin:0"><nav style="width:180px;height:300px;overflow-y:auto"><a href="/a" style="display:block;white-space:nowrap">Breadcrumb and pagination with a long label</a></nav></body></html>' });
|
|
429
|
+
const server = createServer((req, res) => { res.setHeader("content-type", "text/html"); res.end(readFileSync(join(d, "index.html"))); });
|
|
430
|
+
await new Promise((r) => server.listen(0, r));
|
|
431
|
+
writeFileSync(join(d, "recanica.config.json"), JSON.stringify({ devUrl: `http://localhost:${server.address().port}` }));
|
|
432
|
+
execFileSync("git", ["init", "-q"], { cwd: d });
|
|
433
|
+
// The fixture uses the repo's Playwright (apps/docs), as a project would use its own.
|
|
434
|
+
const { symlinkSync, realpathSync } = await import("node:fs");
|
|
435
|
+
try { mkdirSync(join(d, "node_modules/@playwright"), { recursive: true }); symlinkSync(realpathSync(join(import.meta.dirname, "../../../apps/docs/node_modules/@playwright/test")), join(d, "node_modules/@playwright/test")); } catch {}
|
|
436
|
+
let code = 0, out = "";
|
|
437
|
+
// Async: the test's own web server has to keep answering while the guard runs.
|
|
438
|
+
const { execFile } = await import("node:child_process");
|
|
439
|
+
await new Promise((r) => execFile(process.execPath, [cli, "guard", "--render"], { cwd: d, encoding: "utf8" }, (e, so) => { code = e ? e.code : 0; out = so; r(); }));
|
|
440
|
+
server.close();
|
|
441
|
+
if (/Playwright isn't installed/.test(out)) console.log(" (skipped rendered guard: no Playwright)");
|
|
442
|
+
else { assert.equal(code, 1, `guard --render: a sideways-scrolling page fails (${out})`); assert.match(out, /sideways-scroll/, "guard --render: names the rule"); }
|
|
443
|
+
const rep = JSON.parse(run(d, "report", "--offline", "--json"));
|
|
444
|
+
assert.equal(rep.kickoff, false); assert.notEqual(rep.status, "on track", "report: no kickoff is not on track");
|
|
445
|
+
assert.match(run(d, "report", "--offline"), /## Next[\s\S]*kickoff/, "report: says what to do next");
|
|
446
|
+
assert.match(run(d, "help"), /recanica upgrade/, "help lists upgrade");
|
|
447
|
+
console.log("✓ guard looks at changed pages; report scores the project; upgrade is available");
|
|
448
|
+
}
|