mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-02 02:07:25 +08:00
## Thinking Path > - Paperclip is the open source app people use to manage AI agents for work > - Its UI is the operator's daily surface: task lists, boards, budgets, agent status — all built on shadcn components and Tailwind > - Visual values (colors, spacing, type sizes, radii) were hardcoded at ~1,600 call sites: the same "small gray label" was 9/10/11px depending on the file, charts disagreed with chips about status colors, two toggle-switch implementations coexisted in two greens, and there was no visual regression coverage > - This made the UI drift-prone and made any restyle a hundreds-of-files project, which discourages design iteration > - This pull request extracts visual values into a single token layer in `ui/src/index.css`, adds a Storybook visual regression suite backed by external immutable baseline archives, and then applies a deliberate retune reviewed change-by-change on screenshot diffs > - The benefit is that Paperclip's look becomes a config surface: retheming is a token edit reviewed as a snapshot diff, drift is blocked by a token gate, and future UI PRs can prove exactly what changed visually without committing hundreds of PNGs ## Linked Issues or Issue Description No existing public issue covers this work (searched "design tokens", "visual regression", "design system" across issues and PRs). Related in spirit: Refs #8982 (theming a hardcoded panel — a one-off instance of the same problem class this PR addresses systematically). **Problem (feature-request form):** UI visual values are hardcoded per call site with no source of truth and no regression coverage; consistency depends on reviewer memory, and restyling requires mass file edits. **Proposed solution (this PR):** a single token layer + enforcement gate + externally stored visual snapshot suite, then an intentional restyle on top of that foundation. ## What Changed - **Token extraction (zero visual change, machine-verified during development):** committed codemods (`scripts/codemod-*.mjs`) moved ~1,600 hardcoded color/type/spacing/radius/shadow/misc values into named tokens in a non-inline `:root` block of `ui/src/index.css`. - **Visual regression suite:** `pnpm test:storybook-visual` covers 255 stories × light/dark = 510 Playwright screenshots at `maxDiffPixels: 0`, plus new primitive-coverage stories and deterministic-render fixes. - **External visual baselines:** committed PNG snapshots were removed. `tests/storybook-visual/baseline-manifest.json` pins an immutable archive URL/hash/size/count, and `scripts/storybook-visual-baseline.mjs` handles `download`, `verify`, `pack`, and trusted maintainer `upload` flows. - **Opt-in visual CI artifacts:** added a `Storybook Visual` workflow that runs on manual dispatch or PRs labeled `storybook-visual`, downloads/verifies the baseline, runs Playwright, and uploads Playwright report/test-result artifacts for review. Normal PR runs do not mutate baseline objects. - **Token gate:** `pnpm check:token-gates` — zero hex literals, zero arbitrary bracket values, zero raw font-sizes in `ui/src/components/**` and `ui/src/pages/**`, with a documented inline allowlist for legitimate opt-outs. - **Theme retune (intentional, snapshot-reviewed):** new base theme values; radius ladder derived from a single `--radius` knob; micro-type cluster collapsed to a named ladder (`--text-nano/micro/compact` + Tailwind `text-xs`/`text-sm`); letter-spacing collapsed to named steps. - **One status-color vocabulary:** charts, quota/budget bar fills, RUNNING/live chips, and liveness indicators all use the canonical `--status-*` hues. Light-mode legibility fixes for red alert surfaces that used dark-tuned text classes. - **One switch:** `ToggleSwitch` restyled to the registry capsule form, second hand-rolled implementation removed, and all call sites unified. - **Docs:** `DESIGN.md` is the design contract; `doc/design/` holds audit reports, decision logs, and updated guidance for external baseline review/update workflows. - Dead code removed (`agentStatusBadge` duplicate map), byte-identical contrast constants consolidated, semantic renames (`--project-seed`/`--project-none`, `--liveness-blue`). ## Verification - `pnpm check:token-gates` — 3/3 gates CLEAN during the design-system run - `pnpm typecheck` && `pnpm --filter @paperclipai/ui build` — green during the design-system run - `node --test scripts/__tests__/storybook-visual-baseline.test.mjs` — pass after external-baseline rework - `pnpm exec tsc --noEmit --pretty false --module NodeNext --moduleResolution NodeNext --target ES2022 --types node,@playwright/test tests/storybook-visual/playwright.config.ts tests/storybook-visual/storybook-visual.spec.ts` — pass after external-baseline rework - `git diff --check origin/pr/9134..HEAD` — pass after external-baseline rework - `find tests/storybook-visual -type f -name '*.png' -print | wc -l` — `0` - `node scripts/storybook-visual-baseline.mjs verify` — intentionally fails closed until the first trusted maintainer publishes the baseline archive and updates `baseline-manifest.json` ## Risks - **Large but shallow:** the PR still touches many UI files due to mechanical token extraction and retune work, but committed PNG snapshot churn has been removed from the branch. - **Baseline publication required before the visual suite can pass in clean clones:** the manifest currently has placeholder archive metadata. A trusted maintainer must publish the first immutable archive, then update `baseline-manifest.json`. - **Rendering platform variance:** the external baseline should be captured in the documented Linux/Chromium environment. Future CI runs verify against the pinned archive and fail closed on checksum/count mismatch. - **Visual CI is opt-in while stabilizing:** add the `storybook-visual` label or dispatch the workflow manually to produce downloadable Playwright report/test-result artifacts. - **Scheduled follow-ups, deliberately out of scope:** Tailwind palette classes map to semantic tokens in a dedicated pass; card/pill component consolidation; ESLint ratchet. Tracked in `doc/design/DECISION-SHEET.md`. ## Model Used Claude Fable 5 (Anthropic, `claude-fable-5`, Mythos-class tier) with extended thinking, running in Claude Code with tool use; mechanical phases delegated to Claude Sonnet subagents. Follow-up external-baseline rework assisted by OpenAI Codex (`gpt-5` coding agent with repository, terminal, and GitHub tool use). All bulk rewrites executed via deterministic, idempotent scripts committed in `scripts/`; intentional visual changes were human-reviewed on screenshot contact sheets. ## Checklist - [x] I have included a thinking path that traces from project context to this change - [x] I have specified the model used (with version and capability details) - [x] I have checked ROADMAP.md and confirmed this PR does not duplicate planned core work - [x] I have searched GitHub for duplicate or related PRs and linked them above - [x] I have either (a) linked existing issues with `Fixes: #` / `Closes #` / `Refs #` OR (b) described the issue in-PR following the relevant issue template - [x] I have not referenced internal/instance-local Paperclip issues or links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip` URLs) - [x] My branch name describes the change (e.g. `docs/...`, `fix/...`) and contains no internal Paperclip ticket id or instance-derived details - [x] I have run targeted local verification and documented the intentional baseline-publication failure above - [x] I have added or updated tests where applicable - [x] I have updated relevant documentation to reflect my changes - [x] I have considered and documented any risks above - [ ] All Paperclip CI gates are green *(pending new CI run after this rework)* - [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups *(pending review)* - [x] I will address all Greptile and reviewer comments before requesting merge 🤖 Generated with [Claude Code](https://claude.com/claude-code) and OpenAI Codex --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com> Co-authored-by: Dotta <bippadotta@protonmail.com> Co-authored-by: Paperclip <noreply@paperclip.ing>
198 lines
9.0 KiB
JavaScript
198 lines
9.0 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* codemod-type-ladder.mjs
|
|
*
|
|
* DECISION-SHEET.md B3 (user-locked, preset-tune session): collapse the
|
|
* Batch 2 verbatim type tokens into the named ladder.
|
|
*
|
|
* FONT SIZES (8 --fs-* tokens -> 3 named tokens + 2 Tailwind scale classes):
|
|
* --fs-9, --fs-10 -> --text-nano: 10px (9 -> 10 bump)
|
|
* --fs-11, --fs-0_7rem -> --text-micro: 11px (0.7rem = 11.2px -> 11px)
|
|
* --fs-12 -> Tailwind `text-xs` (12px exact match;
|
|
* scale class preferred over token per DESIGN.md)
|
|
* --fs-13 -> --text-compact: 13px
|
|
* --fs-14, --fs-15 -> Tailwind `text-sm` (14px; 15 -> 14)
|
|
*
|
|
* LETTER-SPACING (9 --ls-* tokens -> 3 named steps, nearest-step mapping):
|
|
* 0.08em, 0.1em -> --tracking-label: 0.08em
|
|
* 0.12em, 0.14em, 0.16em -> --tracking-eyebrow: 0.14em
|
|
* 0.18em, 0.2em, 0.22em, 0.24em -> --tracking-caps: 0.2em
|
|
*
|
|
* The codemod rewrites every site under ui/src (components, pages, lib,
|
|
* context, plugins — all .ts/.tsx/.js/.jsx), replaces the --fs-* / --ls-*
|
|
* definitions in ui/src/index.css with the named-ladder block, and fails
|
|
* loudly if any --fs-* / --ls-* reference survives (e.g. a var(--fs-12) site,
|
|
* which has no token replacement because that bucket maps to a Tailwind
|
|
* scale class and would need a manual decision).
|
|
*
|
|
* Replacements are exact strings INCLUDING the closing paren, so prefix
|
|
* collisions (--ls-0_1 vs --ls-0_12, --fs-1* families) cannot mis-match.
|
|
*
|
|
* IDEMPOTENT: a second run finds no old references and the ladder marker
|
|
* already present in index.css, and changes nothing.
|
|
*
|
|
* Usage: node scripts/codemod-type-ladder.mjs
|
|
*/
|
|
|
|
import { readFileSync, writeFileSync, readdirSync } from "node:fs";
|
|
import { resolve, dirname, join, relative } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
const REPO_ROOT = resolve(__dirname, "..");
|
|
const UI_SRC = resolve(REPO_ROOT, "ui/src");
|
|
const CSS_PATH = resolve(UI_SRC, "index.css");
|
|
|
|
// ── Site replacement map (exact strings, closing paren included) ─────────
|
|
const SITE_MAP = new Map([
|
|
// font sizes — Tailwind utility form (Batch 2 syntax)
|
|
["text-(length:--fs-9)", "text-(length:--text-nano)"],
|
|
["text-(length:--fs-10)", "text-(length:--text-nano)"],
|
|
["text-(length:--fs-11)", "text-(length:--text-micro)"],
|
|
["text-(length:--fs-0_7rem)", "text-(length:--text-micro)"],
|
|
["text-(length:--fs-12)", "text-xs"],
|
|
["text-(length:--fs-13)", "text-(length:--text-compact)"],
|
|
["text-(length:--fs-14)", "text-sm"],
|
|
["text-(length:--fs-15)", "text-sm"],
|
|
// font sizes — inline-style var() form
|
|
["var(--fs-9)", "var(--text-nano)"],
|
|
["var(--fs-10)", "var(--text-nano)"],
|
|
["var(--fs-11)", "var(--text-micro)"],
|
|
["var(--fs-0_7rem)", "var(--text-micro)"],
|
|
["var(--fs-13)", "var(--text-compact)"],
|
|
// (var(--fs-12/14/15) intentionally absent: those buckets map to Tailwind
|
|
// scale classes; any such site trips the leftover guard for manual review)
|
|
// letter-spacing — Tailwind utility form
|
|
["tracking-(--ls-0_08)", "tracking-(--tracking-label)"],
|
|
["tracking-(--ls-0_1)", "tracking-(--tracking-label)"],
|
|
["tracking-(--ls-0_12)", "tracking-(--tracking-eyebrow)"],
|
|
["tracking-(--ls-0_14)", "tracking-(--tracking-eyebrow)"],
|
|
["tracking-(--ls-0_16)", "tracking-(--tracking-eyebrow)"],
|
|
["tracking-(--ls-0_18)", "tracking-(--tracking-caps)"],
|
|
["tracking-(--ls-0_2)", "tracking-(--tracking-caps)"],
|
|
["tracking-(--ls-0_22)", "tracking-(--tracking-caps)"],
|
|
["tracking-(--ls-0_24)", "tracking-(--tracking-caps)"],
|
|
// letter-spacing — inline-style var() form
|
|
["var(--ls-0_08)", "var(--tracking-label)"],
|
|
["var(--ls-0_1)", "var(--tracking-label)"],
|
|
["var(--ls-0_12)", "var(--tracking-eyebrow)"],
|
|
["var(--ls-0_14)", "var(--tracking-eyebrow)"],
|
|
["var(--ls-0_16)", "var(--tracking-eyebrow)"],
|
|
["var(--ls-0_18)", "var(--tracking-caps)"],
|
|
["var(--ls-0_2)", "var(--tracking-caps)"],
|
|
["var(--ls-0_22)", "var(--tracking-caps)"],
|
|
["var(--ls-0_24)", "var(--tracking-caps)"],
|
|
]);
|
|
|
|
const LADDER_MARKER = "Named type ladder (DECISION-SHEET.md B3";
|
|
const LADDER_BLOCK = ` /* ── Named type ladder (DECISION-SHEET.md B3, preset-tune session) ──
|
|
Collapses the 8 verbatim --fs-* font-size tokens and 9 --ls-*
|
|
letter-spacing tokens (extracted in Batch 2 above) into named steps.
|
|
Codemod: scripts/codemod-type-ladder.mjs. Mapping:
|
|
9px + 10px -> --text-nano (9 -> 10 bump per locked ladder)
|
|
11px + 0.7rem -> --text-micro (0.7rem = 11.2px -> 11px)
|
|
12px -> Tailwind \`text-xs\` class (12px exact match; scale
|
|
class preferred over a redundant token per DESIGN.md)
|
|
13px -> --text-compact (PRIOR-ART named this tier "sm 13",
|
|
but that collides with Tailwind text-sm = 14px,
|
|
hence "compact")
|
|
14px + 15px -> Tailwind \`text-sm\` class (14px; 15 -> 14)
|
|
Letter-spacing, nearest-step mapping:
|
|
0.08em, 0.1em -> --tracking-label
|
|
0.12em, 0.14em, 0.16em -> --tracking-eyebrow
|
|
0.18em, 0.2em, 0.22em, 0.24em -> --tracking-caps
|
|
NOTE: sites moved to text-xs/text-sm also pick up the Tailwind scale
|
|
line-height (text-(length:--x) set font-size only) — intentional,
|
|
reviewed on the post-preset contact sheet. */
|
|
--text-nano: 10px;
|
|
--text-micro: 11px;
|
|
--text-compact: 13px;
|
|
--tracking-label: 0.08em;
|
|
--tracking-eyebrow: 0.14em;
|
|
--tracking-caps: 0.2em;`;
|
|
|
|
// ── Walk ui/src ───────────────────────────────────────────────────────────
|
|
function walk(dir, out) {
|
|
for (const entry of readdirSync(dir, { withFileTypes: true })) {
|
|
const p = join(dir, entry.name);
|
|
if (entry.isDirectory()) walk(p, out);
|
|
else if (/\.(tsx?|jsx?)$/.test(entry.name)) out.push(p);
|
|
}
|
|
}
|
|
|
|
const files = [];
|
|
walk(UI_SRC, files);
|
|
files.sort();
|
|
|
|
// ── Pass 1: rewrite sites ─────────────────────────────────────────────────
|
|
const bucketCounts = new Map();
|
|
let filesTouched = 0;
|
|
for (const f of files) {
|
|
const before = readFileSync(f, "utf8");
|
|
let after = before;
|
|
for (const [oldStr, newStr] of SITE_MAP) {
|
|
if (!after.includes(oldStr)) continue;
|
|
const n = after.split(oldStr).length - 1;
|
|
after = after.split(oldStr).join(newStr);
|
|
bucketCounts.set(oldStr, (bucketCounts.get(oldStr) ?? 0) + n);
|
|
}
|
|
if (after !== before) {
|
|
writeFileSync(f, after);
|
|
filesTouched++;
|
|
}
|
|
}
|
|
|
|
// ── Pass 2: index.css — swap definitions for the ladder block ────────────
|
|
let css = readFileSync(CSS_PATH, "utf8");
|
|
if (!css.includes(LADDER_MARKER)) {
|
|
const lines = css.split("\n");
|
|
const DEF_RE = /^\s*--(?:fs-[0-9a-z_]+|ls-[0-9_]+):/;
|
|
const firstDef = lines.findIndex((l) => DEF_RE.test(l));
|
|
if (firstDef === -1) {
|
|
console.error("ERROR: no --fs-* / --ls-* definitions found and ladder marker absent — index.css in unexpected state.");
|
|
process.exit(1);
|
|
}
|
|
const kept = lines.filter((l) => !DEF_RE.test(l));
|
|
// Insert the ladder block at the position of the first removed definition:
|
|
// count how many kept lines precede the first definition line.
|
|
let precede = 0;
|
|
for (let i = 0; i < firstDef; i++) if (!DEF_RE.test(lines[i])) precede++;
|
|
kept.splice(precede, 0, LADDER_BLOCK);
|
|
css = kept.join("\n");
|
|
writeFileSync(CSS_PATH, css);
|
|
console.log("index.css: --fs-* / --ls-* definitions replaced with named ladder block");
|
|
} else {
|
|
console.log("index.css: ladder marker already present — skipped (idempotent)");
|
|
}
|
|
|
|
// ── Guard: no survivors anywhere in ui/src (incl. index.css) ─────────────
|
|
const SURVIVOR_RE = /--(?:fs-[0-9a-z_]+|ls-[0-9_]+)/;
|
|
const survivors = [];
|
|
for (const f of [...files, CSS_PATH]) {
|
|
const content = readFileSync(f, "utf8");
|
|
const lines = content.split("\n");
|
|
lines.forEach((l, i) => {
|
|
if (SURVIVOR_RE.test(l)) survivors.push(`${relative(REPO_ROOT, f)}:${i + 1}: ${l.trim()}`);
|
|
});
|
|
}
|
|
|
|
// ── Report ────────────────────────────────────────────────────────────────
|
|
const bucketTotals = {};
|
|
for (const [oldStr, n] of bucketCounts) {
|
|
const target = SITE_MAP.get(oldStr);
|
|
bucketTotals[target] = (bucketTotals[target] ?? 0) + n;
|
|
}
|
|
console.log("Sites rewritten per source form:");
|
|
for (const [oldStr, n] of [...bucketCounts.entries()].sort()) {
|
|
console.log(` ${oldStr} -> ${SITE_MAP.get(oldStr)} (${n})`);
|
|
}
|
|
console.log("Totals per target bucket:", JSON.stringify(bucketTotals, null, 2));
|
|
console.log(`Files touched: ${filesTouched}`);
|
|
|
|
if (survivors.length > 0) {
|
|
console.error(`\nERROR: ${survivors.length} leftover --fs-* / --ls-* reference(s) need manual review:`);
|
|
for (const s of survivors) console.error(" " + s);
|
|
process.exit(1);
|
|
}
|
|
console.log("No leftover --fs-* / --ls-* references. Done.");
|