Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- **Orphaned Refs Scan Scope** — `theme-orphaned-refs` skips dependency, build and agent folders (with `--exclude` for more), checks `border-radius` presets, suggests the nearest step for numeric ladders, and is now TypeScript with Jest tests (`find-orphaned-presets.ts`). ([GIT-2774](https://linear.app/lightspeedwp/issue/GIT-2774))
- **Site Tokens Palette Order** — `site-to-design-tokens` exports the colour ramps in the LightSpeed order (neutral, primary, brand, cta), so the theme palette follows the convention. ([GIT-2773](https://linear.app/lightspeedwp/issue/GIT-2773))
- **Figma Tokens Layout Widths** — `figma-to-block-theme` maps the content and wide width variables to `settings.layout` in px, instead of unitless values in `settings.custom.layout`, so the theme gets the design's widths. ([GIT-2772](https://linear.app/lightspeedwp/issue/GIT-2772))
- **Figma Tokens Monospace Stack** — `figma-to-block-theme` keeps the declared system stack for a generic family such as Monospace, and falls back to `monospace` for the monospace role, instead of writing `Monospace, sans-serif`. ([GIT-2771](https://linear.app/lightspeedwp/issue/GIT-2771))
- **Figma Tokens Font Stacks** — `figma-to-block-theme` starts each font stack with the clean family name and keeps the declared fallbacks, instead of the live site's own `@font-face` name, so the stack matches the theme's `fontFace` entries. ([GIT-2770](https://linear.app/lightspeedwp/issue/GIT-2770))
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@
"test:js": "jest --config .jest.config.cjs --coverage --forceExit --detectOpenHandles",
"test:figma-to-block-theme": "jest --config skills/figma-to-block-theme/scripts/jest.config.cjs",
"test:site-to-design-tokens": "jest --config skills/site-to-design-tokens/scripts/jest.config.cjs",
"test:theme-orphaned-refs": "jest --config skills/theme-orphaned-refs/scripts/jest.config.cjs",
"test:theme-orphaned-refs": "jest --config skills/theme-orphaned-refs/scripts/jest.config.cjs",
"test:site-to-figma-components": "jest --config skills/site-to-figma-components/scripts/jest.config.cjs",
"test:agent-spec-validation": "node .github/scripts/__tests__/validate-agent-specs.test.js",
"test:index-generator": "node .github/scripts/__tests__/generate-agent-index.test.js",
Expand Down
2 changes: 1 addition & 1 deletion skills/site-to-design-tokens/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ npx tsx ${CLAUDE_SKILL_DIR}/scripts/propose-tokens.ts site-styles.json --out pro

The proposal follows the structure in [references/target-structure.md](references/target-structure.md):

- `base`, `contrast`, and `brand`, `primary`, `cta` and `neutral` ramps from 100 to 900, each built around a live colour that keeps its exact value
- `base`, `contrast`, and `neutral`, `primary`, `brand` and `cta` ramps from 100 to 900 (in that order), each built around a live colour that keeps its exact value
- the 44 semantic roles, taken from what elements use where the site shows it, and from the TSP defaults otherwise
- type, spacing, radius, shadow, layout and breakpoint scales, with Max (1440px) and Min (390px) values

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ The proposal and the Figma script follow the TSP design system file (The Safari

| Collection | Modes | Holds | Code syntax |
| ------------------- | -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Theme - Colour | Value | Primitives: `Theme/base`, `Theme/contrast`, `brand/100` … `900`, `primary/…`, `cta/…`, `neutral/…`, `system/<kind>/<foreground or background>`, `custom/overlay`, `shadow/<alpha>` | `--wp--preset--color--<slug>`; overlay and shadows `--wp--custom--color--…` |
| Theme - Colour | Value | Primitives: `Theme/base`, `Theme/contrast`, `neutral/100` … `900`, `primary/…`, `brand/…`, `cta/…` (in that order), `system/<kind>/<foreground or background>`, `custom/overlay`, `shadow/<alpha>` | `--wp--preset--color--<slug>`; overlay and shadows `--wp--custom--color--…` |
| Theme - Semantic | Value | Aliases of the primitives, by role | `--wp--custom--color--<role>--<name>` |
| Theme - Typography | Max, Min | `Sizes/<Name>`, `Font-Families/Primary` (heading), `Secondary` (body), `Tertiary` (accent, only with a third family) and `Monospace`, `Line-Heights/<Name>`, `Weights/<role>` | `--wp--preset--font-size--<slug>` (`100` … `900`), `--wp--preset--font-family--heading`, `body`, `accent` and `monospace`, `--wp--custom--line-height--<slug>`, `--wp--custom--font-weight--<role>` |
| Theme - Spacing | Max, Min | `Padding/None`, `Padding/XXS`, `Padding/XS` … `Padding/Colossal` | `--wp--preset--spacing--<slug>` (`5` … `100`) |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ describe('TokenPlanBuilder', () => {
expect(collection('Theme - Semantic').variables).toHaveLength(44);
});

it('creates the ramps in the LightSpeed palette order', () => {
const families = collection('Theme - Colour')
.variables.map((v) => v.name.split('/')[0])
.filter((family, i, all) => all.indexOf(family) === i);
expect(families.slice(0, 5)).toEqual(['Theme', 'neutral', 'primary', 'brand', 'cta']);
});

it('names and code syntax match the TSP file and the mapper', () => {
const colour = collection('Theme - Colour').variables;
expect(colour.find((v) => v.key === 'brand-600')).toMatchObject({
Expand Down
3 changes: 2 additions & 1 deletion skills/site-to-design-tokens/scripts/write-token-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ export class TokenPlanBuilder {
values: { Value: rgba(p.colour.primitives.contrast) },
},
];
for (const family of ['brand', 'primary', 'cta', 'neutral'] as Family[]) {
// The LightSpeed palette order: neutral, primary, brand, cta.
for (const family of ['neutral', 'primary', 'brand', 'cta'] as Family[]) {
for (const step of RAMP_STEPS) {
const slug = `${family}-${step}`;
colour.push({
Expand Down
11 changes: 7 additions & 4 deletions skills/theme-orphaned-refs/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ This skill guides an agent to walk a WordPress block theme sequentially, detect

## Workflow (sequential)

1. Load theme.json and build the preset registry for `color`, `font-family`, `font-size`, `spacing`, `shadow`, `gradient`, `duotone`.
2. Scan the theme in path order (root → subfolders) for:
1. Load theme.json and build the preset registry for `color`, `font-family`, `font-size`, `spacing`, `shadow`, `border-radius`, `gradient`, `duotone`.
2. Scan the theme's own files in path order (root → subfolders), skipping `node_modules`, `vendor`, `build`, `dist`, `coverage`, `.git`, `.agents`, `.claude` and `.github`, for:
- `var:preset|<type>|<slug>`
- `--wp--preset--<type>--<slug>`
3. For each reference whose slug is not defined in theme.json, replace it with the closest match.
Expand All @@ -24,6 +24,7 @@ This skill guides an agent to walk a WordPress block theme sequentially, detect

- **Exact match**: keep as-is.
- **Numeric slugs** (e.g., `accent-4`): choose the nearest numeric slug with the same prefix from theme.json.
- **Bare numeric ladders** (font sizes `100`–`900`, radius `0`–`700`, spacing `5`–`100`): choose the nearest step. Check what the old value was for: a pill button radius belongs on `Round`, even when another step is nearer by size.
- **Accent/CTA/Brand 1–9**: map to `*-100`, `*-200`, etc. when present.
- **Font sizes by name**:
- `small` → `300`, `medium` → `400`, `large` → `500`, `x-large` → `600`, `xx-large` → `700` (fallback to nearest numeric).
Expand All @@ -36,9 +37,11 @@ This skill guides an agent to walk a WordPress block theme sequentially, detect

Use the bundled script to find orphaned references and suggested replacements:

```bash
npx tsx ${CLAUDE_SKILL_DIR}/scripts/find-orphaned-presets.ts --root <theme-root> --report <path outside the theme>
```
python scripts/find_orphaned_presets.py --root <theme-root>
```

Add `--exclude <folder>` (repeatable) to skip another folder. Run `npm ci` in the `.github` checkout first. Tests: `npm run test:theme-orphaned-refs` from the repository root.

Then apply replacements with minimal, localized edits.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
import { join } from 'node:path';
import {
FileSystem,
OrphanScanner,
PresetRegistryLoader,
runOrphanedRefsCli,
SKIP_DIRS,
SlugSuggester,
} from '../find-orphaned-presets';

const ROOT = '/theme';

const THEME = JSON.stringify({
settings: {
color: { palette: [{ slug: 'base' }, { slug: 'brand-600' }, {}], gradients: [{ slug: 'g' }] },
typography: { fontSizes: [{ slug: '200' }, { slug: '300' }], fontFamilies: [{ slug: 'body' }] },
spacing: { spacingSizes: [{ slug: '5' }, { slug: '10' }] },
shadow: { presets: [{ slug: '100' }] },
border: { radiusSizes: [{ slug: '0' }, { slug: '400' }, { slug: '700' }] },
},
});

/** An in-memory theme folder. Keys are paths relative to ROOT. */
class MemoryFileSystem implements FileSystem {
readonly written = new Map<string, string>();
readonly listed: string[] = [];

constructor(private readonly files: Record<string, string | undefined>) {}

readText(path: string): string | undefined {
const key = path.slice(ROOT.length + 1);
return key in this.files ? this.files[key] : undefined;
}

listDir(path: string): { name: string; isDirectory: boolean }[] {
this.listed.push(path);
const prefix = path === ROOT ? '' : `${path.slice(ROOT.length + 1)}/`;
const entries = new Map<string, boolean>();
for (const file of Object.keys(this.files)) {
if (file.startsWith(prefix)) {
const [name, ...rest] = file.slice(prefix.length).split('/');
entries.set(name, rest.length > 0);
}
}
return [...entries].map(([name, isDirectory]) => ({ name, isDirectory }));
}

writeText(path: string, content: string): void {
this.written.set(path, content);
}
}

function scan(files: Record<string, string | undefined>, skip?: string[]) {
const fs = new MemoryFileSystem({ 'theme.json': THEME, ...files });
const presets = new PresetRegistryLoader().load(THEME);
const orphans = new OrphanScanner(fs).scan(ROOT, presets, skip).map((o) => ({
...o,
file: o.file.slice(ROOT.length + 1),
}));
return { orphans, fs };
}

describe('PresetRegistryLoader', () => {
it('reads every preset type, including radius, and drops entries without a slug', () => {
const presets = new PresetRegistryLoader().load(THEME);
expect(presets.color).toEqual(['base', 'brand-600']);
expect(presets['border-radius']).toEqual(['0', '400', '700']);
expect(presets.duotone).toEqual([]);
});

it('copes with a theme.json that has no settings', () => {
expect(new PresetRegistryLoader().load('{}').spacing).toEqual([]);
});
});

describe('OrphanScanner', () => {
it('reports orphans in the theme files with suggestions', () => {
const { orphans } = scan({
'patterns/hero.php':
'style="color:var(--wp--preset--color--brand-500)" {"fontSize":"var:preset|font-size|small"}',
});
expect(orphans).toEqual([
{ file: 'patterns/hero.php', type: 'font-size', slug: 'small', suggestion: '300' },
{ file: 'patterns/hero.php', type: 'color', slug: 'brand-500', suggestion: 'brand-600' },
]);
});

it('checks border-radius presets and suggests the nearest step', () => {
const { orphans } = scan({
'styles/blocks/button/rounded.json':
'{"radius":"var(--wp--preset--border-radius--600)","r2":"var:preset|border-radius|400"}',
});
expect(orphans).toEqual([
{
file: 'styles/blocks/button/rounded.json',
type: 'border-radius',
slug: '600',
suggestion: '700',
},
]);
});

it('never enters dependency, build or agent folders', () => {
const bad = 'var(--wp--preset--color--vivid-purple)';
const files: Record<string, string> = { 'templates/index.html': bad };
for (const folder of SKIP_DIRS) {
files[`${folder}/deep/file.js`] = bad;
}
const { orphans, fs } = scan(files);
expect(orphans.map((o) => o.file)).toEqual(['templates/index.html']);
expect(fs.listed).not.toContain(join(ROOT, 'node_modules'));
});

it('honours extra excludes and skips binary and unreadable files', () => {
const bad = 'var(--wp--preset--color--vivid-purple)';
const { orphans } = scan(
{ 'tmp/file.css': bad, 'assets/logo.SVG': bad, 'parts/gone.html': undefined },
[...SKIP_DIRS, 'tmp']
);
expect(orphans).toEqual([]);
});

it('ignores preset types it does not know', () => {
expect(scan({ 'parts/header.html': 'var(--wp--preset--aspect-ratio--wide)' }).orphans).toEqual(
[]
);
});
});

describe('SlugSuggester', () => {
const suggester = new SlugSuggester();

it.each([
['x', 'color', [], 'x'],
['base', 'color', ['base'], 'base'],
['medium', 'font-size', ['300', '400'], '400'],
['huge', 'font-size', ['300', '400'], '300'],
['brand-6', 'color', ['brand-600', 'brand-100'], 'brand-600'],
['cta-450', 'color', ['cta-400', 'cta-900'], 'cta-400'],
['primary-450', 'color', ['primary-500', 'primary-400'], 'primary-400'],
['50', 'spacing', ['40', '60', 'base'], '40'],
['600', 'border-radius', ['none'], 'none'],
['contrast', 'color', ['base', 'contrast-alt'], 'contrast-alt'],
['zzz', 'color', ['base', 'brand'], 'base'],
] as const)('suggests for %s (%s)', (slug, type, candidates, expected) => {
expect(suggester.suggest(slug, type, [...candidates])).toBe(expected);
});
});

describe('runOrphanedRefsCli', () => {
function run(argv: string[], files: Record<string, string> = {}) {
const fs = new MemoryFileSystem({ 'theme.json': THEME, ...files });
const out: string[] = [];
const err: string[] = [];
const code = runOrphanedRefsCli(argv, {
fs,
stdout: (t) => out.push(t),
stderr: (t) => err.push(t),
});
return { code, fs, out: out.join(''), err: err.join('') };
}

it('writes a report of the orphans, relative to the theme', () => {
const { code, fs, out } = run(
['--root', ROOT, '--report', 'report.txt', '--exclude', 'scratch'],
{
'patterns/a.php': 'var(--wp--preset--shadow--600)',
'scratch/b.php': 'var(--wp--preset--shadow--600)',
}
);
expect(code).toBe(0);
expect(fs.written.get(join(ROOT, 'report.txt'))).toBe('patterns/a.php\tshadow\t600\t100\n');
expect(out).toContain('Orphaned count: 1');
});

it('writes an absolute report path as given', () => {
const { fs } = run(['--root', ROOT, '--report', '/tmp/out.txt', '--theme', 'theme.json']);
expect(fs.written.get('/tmp/out.txt')).toBe('');
});

it('prints help', () => {
const { code, out } = run(['--help']);
expect(code).toBe(0);
expect(out).toContain('Always skips: node_modules');
});

it('rejects unknown or incomplete arguments', () => {
expect(run(['--nope', 'x']).code).toBe(1);
expect(run(['--root']).err).toContain('Unknown or incomplete argument: --root');
});

it('fails when theme.json cannot be read', () => {
const { code, err } = run(['--root', ROOT, '--theme', 'missing.json']);
expect(code).toBe(1);
expect(err).toContain('Cannot read');
});
});
Loading
Loading