Skip to content

Commit 6fefd08

Browse files
paolomozclaude
andcommitted
refactor(stardust): reskin's canon bridge records canon and modules in stardust/migration.json
canon-from-reskin.mjs (the reskin -> migrate bridge) wrote canon and the module catalog into DESIGN.json extensions; they are migration settings and now go to stardust/migration.json like the rest of the prep cascade's (other keys of the file are kept). reskin-preflight reads them there. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 8b918c0 commit 6fefd08

6 files changed

Lines changed: 48 additions & 40 deletions

File tree

‎plugins/stardust/skills/reskin/reference/mapping-json.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ the EDS block `donor-modules.md` records for it — `deploy` Step 2
4747
([`../../deploy/SKILL.md` § 2](../../deploy/SKILL.md#2-decide-names--reuse--lock-before-writing-any-code)) applied by `scripts/figma/eds-map.mjs`: Q&A → `accordion`, Teaser →
4848
`cards` (variant `teaser`), Button → default content (no block), Chips → `chips` — else its id lower-cased
4949
(`M4` → `m4`). Several modules on one block are its variants; set an entry only to override Step 2's
50-
choice. `canon-from-reskin` records the result per module in `DESIGN.json` `extensions.modules[].eds`. Not
50+
choice. `canon-from-reskin` records the result per module in `stardust/migration.json` `modules[].eds`. Not
5151
read by the renderer.
5252

5353
## `pages.<slug>`

‎plugins/stardust/skills/reskin/scripts/canon-from-reskin.mjs‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
* uses, rendered from the first page that maps them
2020
* (findings: mapped modules with no skeleton, modules the
2121
* mapping composes more than one way)
22-
* <root>/DESIGN.md, DESIGN.json fresh from donor-tokens.json; extensions.canon / modules
23-
* (each module's eds: the EDS block it becomes, deploy Step 2 —
24-
* mapping.json blocks, else donor-modules.md's EDS block column)
22+
* <root>/DESIGN.md, DESIGN.json fresh from donor-tokens.json (the donor's tokens and source)
23+
* <dir>/migration.json canon (files, pinned, moves, history) and modules (each module's
24+
* eds: the EDS block it becomes, deploy Step 2 — mapping.json
25+
* blocks, else donor-modules.md's EDS block column); other keys kept
2526
* <dir>/direction.md "Active <ISO>": the direction is the donor (reskin has no direct)
2627
* <dir>/dynamic-features.md one F row per page with form controls (triage.md shape)
2728
*
@@ -31,7 +32,7 @@
3132
*
3233
* Stale flagging (state-machine.md § Stale flagging, "Canon changes"): when a canon already existed
3334
* (re-authoring with --force), each canon file and module skeleton is compared with the previous
34-
* DESIGN.json extensions.canon. Content-aware: a migrated page is flagged only when its sidecar's
35+
* migration.json canon. Content-aware: a migrated page is flagged only when its sidecar's
3536
* canonShas / archetypeSha / modules no longer match; an approved page (not the archetype) is flagged
3637
* when anything changed. `stale: true` + staleReason "canon changed at <ts>; affected: …" — the status
3738
* does not move. Re-authoring identical content keeps a file byte-for-byte (its provenance stamp
@@ -40,7 +41,7 @@
4041
* Visual record: on a first approval and on every re-approval that changes the canon, the archetype is
4142
* captured with replica's stitch-shot.mjs into <dir>/reskin/approvals/<slug>.<ts>.png; a re-approval is
4243
* then pixel-compared (replica's pixel-compare.mjs) with that archetype's previous capture and the % lands in the
43-
* DESIGN.json canon history entry. Informational: above --visual-threshold it prints a FINDING, never
44+
* migration.json canon history entry. Informational: above --visual-threshold it prints a FINDING, never
4445
* refuses. Without the replica scripts, playwright, pngjs or pixelmatch it is skipped as a finding.
4546
*
4647
* Usage:
@@ -50,7 +51,7 @@
5051
*
5152
* Reads: <dir>/state.json, the archetype's prototypePath (and the other types' approved archetypes'),
5253
* the tokens, mapping, content models, the module
53-
* table, the previous <root>/DESIGN.json and migrate sidecars (stale flagging).
54+
* table, the previous <dir>/migration.json and migrate sidecars (stale flagging).
5455
* Siblings (flow reskin only): per page type with an approved/migrated page, every `extracted` page of that
5556
* type advances to `directed` through state.mjs (_provenance writtenBy stardust:reskin) — the status migrate
5657
* renders at the sibling tier, which `direct` would write but refuses under reskin. Stale and `prototyped`
@@ -388,10 +389,11 @@ async function main(argv) {
388389
const findings = [];
389390

390391
const designJsonFile = join(root, 'DESIGN.json');
391-
const prevDesign = existsSync(designJsonFile) ? (() => { try { return readJson(designJsonFile); } catch { return null; } })() : null;
392-
const prevCanon = prevDesign?.extensions?.canon?.files ? {
393-
files: prevDesign.extensions.canon.files,
394-
modules: Object.fromEntries((prevDesign.extensions.modules || []).filter((m) => m.canonicalRendering?.sha).map((m) => [m.id, m.canonicalRendering.sha])),
392+
const migrationFile = join(opt.dir, 'migration.json');
393+
const prevMigration = existsSync(migrationFile) ? (() => { try { return readJson(migrationFile); } catch { return null; } })() : null;
394+
const prevCanon = prevMigration?.canon?.files ? {
395+
files: prevMigration.canon.files,
396+
modules: Object.fromEntries((prevMigration.modules || []).filter((m) => m.canonicalRendering?.sha).map((m) => [m.id, m.canonicalRendering.sha])),
395397
} : null;
396398

397399
// 1. chrome
@@ -480,7 +482,7 @@ async function main(argv) {
480482
}));
481483
const next = { files, modules: Object.fromEntries(Object.entries(moduleRefs).map(([id, m]) => [id, m.sha])), archetypeSha: fsha(page.prototypePath) };
482484
const changed = canonDelta(prevCanon, next);
483-
const prevHistory = prevDesign?.extensions?.canon?.history || [];
485+
const prevHistory = prevMigration?.canon?.history || [];
484486
const entry = { at, from: slug, kind: prevCanon ? 're-approval' : 'first-approval', via: 'reskin' };
485487
const prevShotEntry = previousShot(prevHistory, slug);
486488
if (!prevShotEntry || (changed && changed.length)) {
@@ -492,11 +494,12 @@ async function main(argv) {
492494
$schema: 'stardust:DESIGN.json',
493495
source: { kind: 'donor', designSource: state.designSource ?? null, tokens: rel(opt.tokens), generatedAt: at, generatedBy: 'stardust:reskin/canon-from-reskin' },
494496
tokens,
495-
extensions: { canon: { sourceSlug: slug, approvedAt, files, pinned, compositionalMoves: moves, history }, modules: extModules },
496497
};
498+
const migration = { ...(prevMigration || {}), canon: { sourceSlug: slug, approvedAt, files, pinned, compositionalMoves: moves, history }, modules: extModules };
497499
const donorUrl = state.designSource?.url ?? 'see state.json designSource';
498500
const designMd = `# DESIGN\n\n> Generated by stardust:reskin/canon-from-reskin at ${at} from \`${rel(opt.tokens)}\` (donor: \`${donorUrl}\`). The donor is the design authority; this file restates its tokens for migrate. Do not hand-edit — re-run the bridge.\n\n## Tokens\n\n| token | value |\n|---|---|\n${flat.map(([k, v]) => `| \`${k}\` | \`${v}\` |`).join('\n')}\n\n## Canon\n\n- Source archetype: \`${slug}\` (approved ${approvedAt})\n- Files: ${Object.entries(files).map(([k, f]) => `${k} \`${f.path}\``).join(' · ')}\n- Pinned: ${Object.entries(pinned).map(([k, v]) => `\`${k}\`=${v}`).join(' · ')}\n\n## Compositional moves\n\n${moves.map((m) => `- ${m}`).join('\n')}\n`;
499501
writeFileSync(designJsonFile, `${JSON.stringify(designJson, null, 2)}\n`);
502+
writeFileSync(migrationFile, `${JSON.stringify(migration, null, 2)}\n`);
500503
writeFileSync(join(root, 'DESIGN.md'), designMd);
501504

502505
// direction.md

‎plugins/stardust/skills/reskin/scripts/reskin-preflight.mjs‎

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414
* (its merged :root or any rule), in a style attribute of the canon markup, or one of
1515
* stream-render's MARKUP_VARS; WARN for undefined ones read only with a fallback
1616
* FAIL DESIGN.json source.kind is "donor" (written by the bridge, not by direct)
17-
* FAIL DESIGN.json extensions.canon.files match the canon files on disk (no hand edit, no overwrite)
17+
* FAIL stardust/migration.json canon.files match the canon files on disk (no hand edit, no overwrite)
1818
* FAIL direction.md carries an "## Active" direction
1919
* FAIL dynamic-features.md exists and every feature row has a disposition
20-
* FAIL every module a typed page's mapping uses has a canon skeleton (DESIGN.json extensions.modules)
20+
* FAIL every module a typed page's mapping uses has a canon skeleton (stardust/migration.json modules)
2121
* FAIL no agent approval outside hands-off (approvedBy hands-off/autopilot/agent needs state.handsOff and "hands-off")
2222
* FAIL the reskin predicate: each type's archetype is gated in reskin/ledger.json (reskin-ledger.mjs) —
2323
* its deployed evidence's codeStamp still the project's code (deployed-gate stamp) —
@@ -156,15 +156,18 @@ export function preflight(read, { dir = 'stardust', stamp = null } = {}) {
156156
else ok('canon', `${dir}/canon/canon.css opens with :root`);
157157

158158
const design = json('DESIGN.json');
159+
const migration = json(`${dir}/migration.json`);
159160
if (!design) fail('design', `DESIGN.json ${design === undefined ? 'is missing' : 'is not valid JSON'} — run canon-from-reskin.mjs`);
160161
else {
161162
if (design.source?.kind === 'donor') ok('design', 'DESIGN.json is donor-sourced');
162163
else fail('design', `DESIGN.json source.kind is ${design.source?.kind ? `"${design.source.kind}"` : 'unset'} — something other than the bridge wrote it (direct / extract --prep?); re-run canon-from-reskin.mjs --force`);
163-
const files = design.extensions?.canon?.files;
164-
if (!files) fail('canon-record', 'DESIGN.json has no extensions.canon.files');
164+
}
165+
{
166+
const files = migration?.canon?.files;
167+
if (!files) fail('canon-record', `${dir}/migration.json has no canon.files — run canon-from-reskin.mjs`);
165168
else {
166169
const drift = Object.entries(files).filter(([, f]) => { const s = read(f.path); return s == null || sha(s) !== f.sha; }).map(([k]) => k);
167-
if (drift.length) fail('canon-record', `canon file(s) differ from DESIGN.json: ${drift.join(', ')} — re-run canon-from-reskin.mjs --force`);
170+
if (drift.length) fail('canon-record', `canon file(s) differ from migration.json: ${drift.join(', ')} — re-run canon-from-reskin.mjs --force`);
168171
else ok('canon-record', `${Object.keys(files).length} canon file(s) match`);
169172
}
170173
}
@@ -174,8 +177,8 @@ export function preflight(read, { dir = 'stardust', stamp = null } = {}) {
174177
// siblings without it; with a fallback it is a WARN (the sibling takes the literal, not the donor value).
175178
if (css != null && /^\s*:root\s*\{/.test(css.replace(/\/\*[\s\S]*?\*\//g, ''))) {
176179
const markup = [
177-
...Object.entries(design?.extensions?.canon?.files || {}).filter(([k]) => k !== 'css').map(([, f]) => f?.path),
178-
...(design?.extensions?.modules || []).map((m) => m.canonicalRendering?.path),
180+
...Object.entries(migration?.canon?.files || {}).filter(([k]) => k !== 'css').map(([, f]) => f?.path),
181+
...(migration?.modules || []).map((m) => m.canonicalRendering?.path),
179182
].filter(Boolean).map((p) => read(p)).filter((s) => s != null);
180183
const { missing: undef, soft } = canonTokenGaps(css, markup);
181184
if (undef.length) fail('canon-tokens', `${dir}/canon/canon.css reads ${undef.length} custom propert${undef.length === 1 ? 'y' : 'ies'} defined nowhere, without a fallback: ${undef.join(', ')} — re-run canon-from-reskin.mjs --force (it merges every :root block of the archetype into canon.css's :root)`);
@@ -206,8 +209,8 @@ export function preflight(read, { dir = 'stardust', stamp = null } = {}) {
206209

207210
// Every module a typed page's mapping uses needs a canon skeleton, or migrate has nothing to render it with.
208211
const mapping = json(`${dir}/reskin/mapping.json`);
209-
if (mapping && design) {
210-
const canonMods = new Set((design.extensions?.modules || []).filter((m) => m.canonicalRendering?.path && read(m.canonicalRendering.path) != null).map((m) => m.id));
212+
if (mapping && migration) {
213+
const canonMods = new Set((migration.modules || []).filter((m) => m.canonicalRendering?.path && read(m.canonicalRendering.path) != null).map((m) => m.id));
211214
const typed = new Set(state.pages.filter((p) => p.type).map((p) => p.slug));
212215
const used = new Map();
213216
for (const [ps, pm] of Object.entries(mapping.pages || {})) {

‎plugins/stardust/skills/reskin/scripts/test/canon-from-reskin.test.mjs‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -198,17 +198,18 @@ write('stardust/prototypes/login-proposed.html', page());
198198
check('refuses an archetype that is not approved (exit 1)', () => {
199199
const r = run(['login']); assert.equal(r.status, 1); assert.match(r.err, /refused: login is directed/);
200200
});
201-
check('full run: canon files, :root first in canon.css, DESIGN.json canon + modules; re-run refuses without --force', () => {
201+
check('full run: canon files, :root first in canon.css, migration.json canon + modules; re-run refuses without --force', () => {
202202
write('stardust/state.json', JSON.stringify(state()));
203203
const r = run(['login']); assert.equal(r.status, 0, r.err);
204204
assert.match(read('stardust/canon/canon.css'), /^:root \{ --a: red; \}/);
205205
assert.match(read('stardust/canon/header.html'), /<header class="site-header" data-canon="header">/);
206-
const d = JSON.parse(read('DESIGN.json'));
207-
assert.equal(d.source.kind, 'donor'); assert.equal(d.extensions.canon.sourceSlug, 'login');
208-
assert.deepEqual(Object.keys(d.extensions.canon.files), ['header', 'footer', 'css']);
209-
assert.equal(d.extensions.modules.find((m) => m.id === 'M2').canonicalRendering.path, 'stardust/canon/modules/M2.html');
210-
assert.deepEqual(d.extensions.modules.find((m) => m.id === 'M2').eds, { block: 'form', variant: 'login' }, 'the EDS block of deploy Step 2, from donor-modules.md');
211-
const first = d.extensions.canon.history.at(-1); assert.equal(first.kind, 'first-approval');
206+
assert.equal(JSON.parse(read('DESIGN.json')).source.kind, 'donor');
207+
const d = JSON.parse(read('stardust/migration.json'));
208+
assert.equal(d.canon.sourceSlug, 'login');
209+
assert.deepEqual(Object.keys(d.canon.files), ['header', 'footer', 'css']);
210+
assert.equal(d.modules.find((m) => m.id === 'M2').canonicalRendering.path, 'stardust/canon/modules/M2.html');
211+
assert.deepEqual(d.modules.find((m) => m.id === 'M2').eds, { block: 'form', variant: 'login' }, 'the EDS block of deploy Step 2, from donor-modules.md');
212+
const first = d.canon.history.at(-1); assert.equal(first.kind, 'first-approval');
212213
// captured when playwright and the replica scripts resolve; otherwise a finding, never a failure
213214
if (first.shot) assert.match(first.shot, /^stardust\/reskin\/approvals\/login\..*\.png$/); else assert.match(r.out, /FINDING visual record skipped/);
214215
assert.equal(run(['login']).status, 1);
@@ -227,7 +228,7 @@ check('--force after the archetype changed: delta named, approved sibling flagge
227228
const s = JSON.parse(read('stardust/state.json'));
228229
assert.equal(s.pages[1].stale, true); assert.match(s.pages[1].staleReason, /^canon changed at .*; affected: css$/);
229230
assert.equal(s.pages[0].stale, undefined); assert.equal(s.pages[1].status, 'approved');
230-
assert.equal(JSON.parse(read('DESIGN.json')).extensions.canon.history.at(-1).kind, 're-approval');
231+
assert.equal(JSON.parse(read('stardust/migration.json')).canon.history.at(-1).kind, 're-approval');
231232
});
232233
check('--force after a sibling maps a module no archetype renders: skeleton rendered from that page\'s content model, nothing newly stale', () => {
233234
const m = JSON.parse(read('stardust/reskin/mapping.json'));
@@ -239,7 +240,7 @@ check('--force after a sibling maps a module no archetype renders: skeleton rend
239240
assert.match(r.out, /canon delta: module:M6; stale flagged: none/);
240241
assert.doesNotMatch(r.out, /no canon skeleton/);
241242
assert.match(read('stardust/canon/modules/M6.html'), /<section\b[^>]*data-module="M6"/);
242-
assert.equal(JSON.parse(read('DESIGN.json')).extensions.modules.find((x) => x.id === 'M6').canonicalRendering.from, 'reg');
243+
assert.equal(JSON.parse(read('stardust/migration.json')).modules.find((x) => x.id === 'M6').canonicalRendering.from, 'reg');
243244
});
244245

245246

‎plugins/stardust/skills/reskin/scripts/test/reskin-preflight.test.mjs‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ function project(over = {}) {
2828
'stardust/state.json': JSON.stringify({ flow: 'reskin', pages: [{ slug: 'login', type: 'form', status: 'approved' }, { slug: 'registration', type: 'form', status: 'extracted' }] }),
2929
'stardust/canon/canon.css': CSS,
3030
'stardust/canon/header.html': HEADER,
31-
'DESIGN.json': JSON.stringify({ source: { kind: 'donor' }, extensions: { canon: { files: { css: { path: 'stardust/canon/canon.css', sha: sha(CSS) }, header: { path: 'stardust/canon/header.html', sha: sha(HEADER) } } } } }),
31+
'DESIGN.json': JSON.stringify({ source: { kind: 'donor' } }),
32+
'stardust/migration.json': JSON.stringify({ canon: { files: { css: { path: 'stardust/canon/canon.css', sha: sha(CSS) }, header: { path: 'stardust/canon/header.html', sha: sha(HEADER) } } } }),
3233
'stardust/direction.md': '# Direction\n\n## Active\n\nDonor reskin.\n',
3334
'stardust/dynamic-features.md': DYN,
3435
'stardust/reskin/ledger.json': LEDGER,
@@ -67,9 +68,9 @@ check('canon-tokens: a var read without a fallback and defined nowhere fails and
6768
.site-main .inset > .container { padding: 0 var(--band-inset); }
6869
.site-main .hero { margin: var(--hero-m); }`;
6970
const mod = '<section class="hero" style="color: red; --hero-m: 2px" data-module="M1"></section>';
70-
const d = JSON.parse(project()('DESIGN.json'));
71-
d.extensions.modules = [{ id: 'M1', canonicalRendering: { path: 'stardust/canon/modules/M1.html', sha: 'x' } }];
72-
const res = preflight(project({ 'stardust/canon/canon.css': css, 'DESIGN.json': JSON.stringify(d), 'stardust/canon/modules/M1.html': mod }));
71+
const d = JSON.parse(project()('stardust/migration.json'));
72+
d.modules = [{ id: 'M1', canonicalRendering: { path: 'stardust/canon/modules/M1.html', sha: 'x' } }];
73+
const res = preflight(project({ 'stardust/canon/canon.css': css, 'stardust/migration.json': JSON.stringify(d), 'stardust/canon/modules/M1.html': mod }));
7374
assert.deepEqual(levels(res, 'canon-tokens'), ['fail', 'warn']);
7475
const [f, w] = res.filter((r) => r.check === 'canon-tokens');
7576
assert.match(f.detail, /2 custom properties defined nowhere, without a fallback: --palette-accent, --type-body-font-size/);
@@ -100,10 +101,10 @@ check('stale and untyped pages warn but do not fail', () => {
100101
assert.match(res.find((r) => r.check === 'stale').detail, /login: canon changed/);
101102
});
102103
check('a mapped module with no canon skeleton fails canon-modules; untyped pages are ignored', () => {
103-
const d = JSON.parse(project()('DESIGN.json'));
104-
d.extensions.modules = [{ id: 'M1', canonicalRendering: { path: 'stardust/canon/modules/M1.html', sha: 'x' } }, { id: 'M2', canonicalRendering: null }];
104+
const d = JSON.parse(project()('stardust/migration.json'));
105+
d.modules = [{ id: 'M1', canonicalRendering: { path: 'stardust/canon/modules/M1.html', sha: 'x' } }, { id: 'M2', canonicalRendering: null }];
105106
const mapping = JSON.stringify({ pages: { login: { slots: { s01: { module: 'M1' }, s02: { module: 'M2' } } }, misc: { slots: { s01: { module: 'M7' } } } } });
106-
const base = { 'DESIGN.json': JSON.stringify(d), 'stardust/reskin/mapping.json': mapping, 'stardust/canon/modules/M1.html': '<section data-module="M1"></section>' };
107+
const base = { 'stardust/migration.json': JSON.stringify(d), 'stardust/reskin/mapping.json': mapping, 'stardust/canon/modules/M1.html': '<section data-module="M1"></section>' };
107108
const r = preflight(project(base)).find((x) => x.check === 'canon-modules');
108109
assert.equal(r.level, 'fail'); assert.match(r.detail, /M2 \(login\)/); assert.doesNotMatch(r.detail, /M1|M7/);
109110
const okMap = JSON.stringify({ pages: { login: { slots: { s01: { module: 'M1' } } } } });
@@ -196,7 +197,7 @@ check('usage errors exit 2', () => {
196197
check('CLI exits 0 on a ready project and 1 after breaking it', () => {
197198
const root = mkdtempSync(join(tmpdir(), 'rp-'));
198199
const read = project();
199-
for (const rel of ['stardust/state.json', 'stardust/canon/canon.css', 'stardust/canon/header.html', 'DESIGN.json', 'stardust/direction.md', 'stardust/dynamic-features.md', 'stardust/reskin/ledger.json']) {
200+
for (const rel of ['stardust/state.json', 'stardust/canon/canon.css', 'stardust/canon/header.html', 'DESIGN.json', 'stardust/migration.json', 'stardust/direction.md', 'stardust/dynamic-features.md', 'stardust/reskin/ledger.json']) {
200201
mkdirSync(dirname(join(root, rel)), { recursive: true }); writeFileSync(join(root, rel), read(rel));
201202
}
202203
const ok = run(['--root', root, '--json']);

0 commit comments

Comments
 (0)