@1agh/maude 2.0.4 → 2.0.6

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.
Files changed (129) hide show
  1. package/apps/hub/src/project-transactions/kernel.mjs +10 -1
  2. package/apps/studio/access/filters.ts +12 -5
  3. package/apps/studio/access/known-canvases.ts +24 -1
  4. package/apps/studio/access/refused-inputs.ts +89 -0
  5. package/apps/studio/actions/agents.ts +5 -0
  6. package/apps/studio/actions/defs/app.ts +12 -0
  7. package/apps/studio/actions.manifest.json +13 -1
  8. package/apps/studio/actions.parity.json +7 -1
  9. package/apps/studio/annotations/ui/element-node.tsx +139 -54
  10. package/apps/studio/annotations/ui/lod.tsx +1 -1
  11. package/apps/studio/annotations/ui/text-style.ts +1 -1
  12. package/apps/studio/annotations-layer.tsx +0 -12
  13. package/apps/studio/api.ts +42 -0
  14. package/apps/studio/artboard-live-gate.tsx +267 -0
  15. package/apps/studio/artboard-live.ts +336 -0
  16. package/apps/studio/artboard-webgl.ts +668 -0
  17. package/apps/studio/bin/_agent-browser-bin.mjs +8 -0
  18. package/apps/studio/bin/_agent-browser-safe.mjs +2 -1
  19. package/apps/studio/bin/_canvas-reasons.mjs +34 -0
  20. package/apps/studio/bin/_ds-check-live.mjs +37 -0
  21. package/apps/studio/bin/_ds-check.mjs +4 -1
  22. package/apps/studio/bin/_ds-prove-judge.mjs +167 -0
  23. package/apps/studio/bin/_ds-prove-playwright.mjs +183 -105
  24. package/apps/studio/bin/_import-asset.mjs +2 -1
  25. package/apps/studio/bin/_perf-probe.mjs +2 -1
  26. package/apps/studio/bin/_studio-verb.mjs +24 -3
  27. package/apps/studio/bin/_thumb-blank.mjs +70 -0
  28. package/apps/studio/bin/_thumb-cover.mjs +35 -0
  29. package/apps/studio/bin/_thumbs-playwright.mjs +89 -12
  30. package/apps/studio/bin/ds-check.sh +5 -1
  31. package/apps/studio/bin/perf.sh +11 -1
  32. package/apps/studio/bin/server-up.sh +7 -2
  33. package/apps/studio/bin/smoke.sh +19 -0
  34. package/apps/studio/canvas-lib.tsx +131 -12
  35. package/apps/studio/client/canvas-url.js +13 -0
  36. package/apps/studio/client/home/HomeAccounts.jsx +262 -0
  37. package/apps/studio/client/home/Shelves.jsx +4 -3
  38. package/apps/studio/client/home/home-accounts-model.js +121 -0
  39. package/apps/studio/client/home/home-api.js +6 -0
  40. package/apps/studio/client/home/home-app.jsx +141 -40
  41. package/apps/studio/client/home/home-model.js +172 -6
  42. package/apps/studio/client/home/home.css +169 -5
  43. package/apps/studio/client/home/shell-mode.js +8 -1
  44. package/apps/studio/client/hooks/use-project-data.jsx +2 -0
  45. package/apps/studio/client/panels/ChatPanel.jsx +27 -20
  46. package/apps/studio/client/panels/CreateProject.jsx +19 -5
  47. package/apps/studio/client/panels/caps-cache.js +46 -0
  48. package/apps/studio/client/shell/viewport.jsx +36 -8
  49. package/apps/studio/client/v2/access/access-client.js +2 -0
  50. package/apps/studio/client/v2/access/access-host.jsx +12 -1
  51. package/apps/studio/client/v2/access/trashed-banner.jsx +6 -3
  52. package/apps/studio/client/v2/ai/Advanced.jsx +12 -0
  53. package/apps/studio/client/v2/ai/Composer.jsx +27 -10
  54. package/apps/studio/client/v2/code/canvas-imports-card.jsx +15 -14
  55. package/apps/studio/client/v2/code/canvas-imports-words.js +44 -0
  56. package/apps/studio/client/v2/code/code-bus.js +5 -0
  57. package/apps/studio/client/v2/ds/advanced-host.jsx +11 -26
  58. package/apps/studio/client/v2/ds/ds-refresh.js +161 -0
  59. package/apps/studio/client/v2/ds/library-host.jsx +45 -45
  60. package/apps/studio/client/v2/ds/make-host.jsx +13 -15
  61. package/apps/studio/client/v2/ds/off-system-host.jsx +18 -19
  62. package/apps/studio/client/v2/ds/review-host.jsx +7 -1
  63. package/apps/studio/client/v2/ds/truth-host.jsx +15 -17
  64. package/apps/studio/client/v2/ds/upgrade-host.jsx +26 -10
  65. package/apps/studio/client/v2/history/branch-actions.js +13 -9
  66. package/apps/studio/client/v2/history/git-advanced.jsx +8 -1
  67. package/apps/studio/client/v2/history/git-model.js +3 -1
  68. package/apps/studio/client/v2/history/git-parts.jsx +16 -1
  69. package/apps/studio/client/v2/presence/faces.jsx +42 -14
  70. package/apps/studio/client/v2/shell/account-card.jsx +10 -4
  71. package/apps/studio/client/v2/shell/canvas-crash-guard.js +137 -0
  72. package/apps/studio/client/v2/shell/github-signin-host.jsx +42 -0
  73. package/apps/studio/client/v2/shell/menu-runner.js +11 -0
  74. package/apps/studio/client/v2/shell/project-account-card.jsx +203 -0
  75. package/apps/studio/client/v2/shell/project-account-model.js +182 -0
  76. package/apps/studio/client/v2/shell/share-cluster-host.jsx +137 -10
  77. package/apps/studio/client/v2/shell/share-cluster.css +58 -0
  78. package/apps/studio/client/v2/shell/share-cluster.jsx +26 -7
  79. package/apps/studio/client/v2/shell/team-switch.js +94 -0
  80. package/apps/studio/client/v2/shell/too-heavy-card.jsx +38 -0
  81. package/apps/studio/client/v2/shell/use-account.js +8 -1
  82. package/apps/studio/collab/persistence.ts +9 -1
  83. package/apps/studio/collab/registry.ts +32 -0
  84. package/apps/studio/collab/room.ts +8 -0
  85. package/apps/studio/config-reload-wire.ts +53 -0
  86. package/apps/studio/dist/client.bundle.js +1232 -1232
  87. package/apps/studio/dist/styles.css +1 -1
  88. package/apps/studio/ds/board/specimen.tsx +12 -1
  89. package/apps/studio/ds/canvas-cli.ts +58 -2
  90. package/apps/studio/ds/check.ts +26 -1
  91. package/apps/studio/ds/cli.ts +7 -3
  92. package/apps/studio/ds/convert.ts +34 -6
  93. package/apps/studio/ds/ds-verb.ts +13 -0
  94. package/apps/studio/ds/post-build.ts +38 -0
  95. package/apps/studio/ds/upgrade-apply.ts +27 -5
  96. package/apps/studio/ds/upgrade-cli.ts +22 -2
  97. package/apps/studio/ds/upgrade-prove.ts +198 -15
  98. package/apps/studio/ds/upgrade-stage.ts +4 -1
  99. package/apps/studio/history/trash.ts +6 -0
  100. package/apps/studio/home/accounts.ts +87 -0
  101. package/apps/studio/home/index-reader.ts +24 -2
  102. package/apps/studio/home/routes.ts +19 -0
  103. package/apps/studio/http.ts +14 -2
  104. package/apps/studio/routes/ds-convert.ts +18 -0
  105. package/apps/studio/routes/trash.ts +16 -1
  106. package/apps/studio/server.ts +8 -10
  107. package/apps/studio/sync/accepted-cold-start.ts +28 -13
  108. package/apps/studio/sync/asset-push.ts +146 -23
  109. package/apps/studio/sync/asset-state.ts +3 -2
  110. package/apps/studio/sync/file-membership.ts +28 -3
  111. package/apps/studio/sync/file-plane.ts +40 -9
  112. package/apps/studio/sync/file-pull.ts +304 -33
  113. package/apps/studio/sync/hub-link.ts +1 -2
  114. package/apps/studio/sync/index.ts +308 -150
  115. package/apps/studio/sync/journal-client.ts +94 -5
  116. package/apps/studio/sync/pending-deletes.ts +100 -0
  117. package/apps/studio/sync/projection.ts +77 -12
  118. package/apps/studio/sync/seed-progress.ts +12 -1
  119. package/apps/studio/sync/status.ts +3 -1
  120. package/apps/studio/thumbs/service.ts +12 -2
  121. package/apps/studio/thumbs/validate.ts +7 -0
  122. package/apps/studio/ui-prefs-migrate.ts +4 -0
  123. package/apps/studio/video-comp.tsx +23 -0
  124. package/apps/studio/whats-new.json +72 -0
  125. package/cli/lib/bash-guard.mjs +13 -1
  126. package/cli/lib/design-help.gen.mjs +1 -1
  127. package/cli/lib/design-hook.mjs +20 -0
  128. package/cli/lib/studio-locate.mjs +35 -10
  129. package/package.json +8 -8
@@ -10,7 +10,7 @@
10
10
  // `Section`). Without them the system's `.<root>[data-theme]` token blocks never matched this wrapper, so a
11
11
  // specimen page stayed in Light while the seven sections switched.
12
12
 
13
- import { DSRoot } from '@maude/canvas-lib';
13
+ import { DSRoot, useArtboardSeen } from '@maude/canvas-lib';
14
14
  import { Component, type ComponentType, type ReactNode } from 'react';
15
15
  import { getSpecimen, useBoardMode, useBoardModel } from './state.ts';
16
16
  import { themeFor } from './types.ts';
@@ -43,6 +43,17 @@ function Missing({ src, why }: { src: string; why: string }) {
43
43
  export function Specimen({ src, mode: modeProp }: { src: string; mode?: 'light' | 'dark' }) {
44
44
  const model = useBoardModel();
45
45
  const stored = useBoardMode();
46
+ // 2.0.5 — a specimen page mounts once its artboard first comes near the viewport (a board of 58 built
47
+ // every page at open). The artboard keeps its size meanwhile; captures and exports mount all of them.
48
+ const seen = useArtboardSeen();
49
+ if (!seen)
50
+ return (
51
+ <div
52
+ className="ds-board ds-specimen ds-specimen-pending"
53
+ data-ds-specimen={src}
54
+ aria-hidden="true"
55
+ />
56
+ );
46
57
  const mod = getSpecimen(src) as { default?: ComponentType } | ComponentType | undefined;
47
58
  const Comp = (typeof mod === 'function' ? mod : mod?.default) as ComponentType | undefined;
48
59
  if (!Comp) return <Missing src={src} why="is not loaded" />;
@@ -3,7 +3,11 @@
3
3
 
4
4
  import { readdirSync, readFileSync, renameSync, writeFileSync } from 'node:fs';
5
5
  import { join, relative, resolve } from 'node:path';
6
+ import { canvasImportsReport } from '../access/closure.ts';
7
+ import { closureConfigFor } from '../access/known-canvases.ts';
8
+ import { diskProjectReader } from '../access/request.ts';
6
9
  import { claimWritesSync } from '../bin/_write-claim.mjs';
10
+ import { canvasImportsLines } from '../client/v2/code/canvas-imports-words.js';
7
11
  import {
8
12
  type CanvasContext,
9
13
  type CanvasReport,
@@ -15,6 +19,7 @@ import {
15
19
  } from './canvas-check.ts';
16
20
  import { checkSystem, type SystemReport } from './check.ts';
17
21
  import type { DsCheckArgs, Project, RunResult } from './cli.ts';
22
+ import { NO_STUDIO_NOTE, type PostBuild } from './post-build.ts';
18
23
  import { indexRegistry, loadRegistry } from './registry.ts';
19
24
  import { diskFs, loadSystem, type SystemModel } from './system.ts';
20
25
 
@@ -196,7 +201,8 @@ export function runCanvasModes(
196
201
  project: Project,
197
202
  systemsSelected: SystemReport[] | null,
198
203
  t0: number,
199
- hookInput: string | null
204
+ hookInput: string | null,
205
+ post: PostBuild | null = null
200
206
  ): RunResult {
201
207
  const ctx = canvasContext(project);
202
208
  if (args.cheatsheet) {
@@ -326,6 +332,8 @@ export function runCanvasModes(
326
332
  registry: 1,
327
333
  durationMs: Math.round(performance.now() - t0),
328
334
  systems: systemsSelected ?? [],
335
+ studio: post?.live ?? null,
336
+ refusedInputs: Object.fromEntries(post?.refused ?? []),
329
337
  canvases: reports.map((r) => ({ ...r, findings: r.findings.map(({ span: _s, ...f }) => f) })),
330
338
  ...(args.fix ? { fixed, dryRun: args.dryRun } : {}),
331
339
  };
@@ -338,9 +346,57 @@ export function runCanvasModes(
338
346
  ? `${args.dryRun ? 'would fix' : 'fixed'}: ${fixed.map((f) => `${f.file} (${f.edits})`).join(', ')}`
339
347
  : 'nothing to fix'
340
348
  );
341
- for (const r of reports) lines.push(...(args.quiet ? [`${r.path}: ${r.state}`] : summarize(r)));
349
+ const why = refusedWhy(project, reports, post);
350
+ for (const r of reports) {
351
+ lines.push(...(args.quiet ? [`${r.path}: ${r.state}`] : summarize(r)));
352
+ for (const line of why.get(r.path) ?? []) lines.push(` ✗ ${line}`);
353
+ }
342
354
  if (!reports.length) lines.push('no canvas matched');
355
+ else if (post && !post.live) lines.push(NO_STUDIO_NOTE);
343
356
  return { code, stdout: `${lines.join('\n')}\n`, stderr: '' };
344
357
  }
345
358
 
359
+ /**
360
+ * 2.0.5 (#205) — why a canvas renders nothing in its frame, in the shell card's words
361
+ * (client/v2/code/canvas-imports-words.js): (1) its import walk reaches another canvas's code (the studio
362
+ * refuses its module, access/closure.ts `walkImports`; judged with the closure config the studio uses), and
363
+ * (2) — only a running studio knows — its BUILT module was refused for a file another canvas owns (`post`,
364
+ * read from `/_index-data` by bin/_ds-check-live.mjs).
365
+ */
366
+ function refusedWhy(
367
+ project: Project,
368
+ reports: CanvasReport[],
369
+ post: PostBuild | null
370
+ ): Map<string, string[]> {
371
+ const out = new Map<string, string[]>();
372
+ if (!reports.length) return out;
373
+ let walked = new Map<string, string[]>();
374
+ try {
375
+ const reader = diskProjectReader(project.designRoot, () => 'ds-check');
376
+ const cfg = closureConfigFor({
377
+ cfg: project.config as { linkedHub?: { url?: string } | null },
378
+ paths: { designRoot: project.designRoot },
379
+ });
380
+ walked = canvasImportsReport(
381
+ reader,
382
+ reports.map((r) => r.path),
383
+ cfg
384
+ );
385
+ } catch {
386
+ /* the walk is a courtesy here: the report stands without it */
387
+ }
388
+ const dir =
389
+ typeof project.config.newComponentDir === 'string' ? project.config.newComponentDir : '';
390
+ for (const r of reports) {
391
+ const imports = walked.get(r.path) ?? [];
392
+ const built = post?.refused.get(r.path) ?? [];
393
+ if (!imports.length && !built.length) continue;
394
+ out.set(
395
+ r.path,
396
+ canvasImportsLines(imports, dir, built).filter((l): l is string => typeof l === 'string')
397
+ );
398
+ }
399
+ return out;
400
+ }
401
+
346
402
  export { relative, resolve };
@@ -209,6 +209,31 @@ export function checkSystem(model: SystemModel, idx: RegistryIndex): SystemRepor
209
209
  if (themeGaps.length) reasons.add('theme-gap');
210
210
  if (cfg.themes.length === 1) reasons.add('single-theme');
211
211
 
212
+ // fix/ds-convert-hooks-cli #10 — a colour role declared ONLY on `:root` as `var(--x)`: a custom
213
+ // property's var() is resolved where it is declared, so a nested `[data-theme='light']` island
214
+ // inherits the value `:root` resolved (the dark one) even when it redefines `--x`. A warning
215
+ // note (no level change: theme-gap / single-theme already carry one), with the fix.
216
+ const rootOnly: string[] = [];
217
+ for (const r of required) {
218
+ if (!r.perTheme) continue;
219
+ const ds = model.byName.get(r.name) ?? [];
220
+ if (!ds.length) continue;
221
+ const onlyRoot = ds.every((d) =>
222
+ (model.rules[d.rule]?.selector ?? '')
223
+ .replace(/\/\*[\s\S]*?\*\//g, ' ')
224
+ .split(',')
225
+ .every((s) => s.trim() === ':root')
226
+ );
227
+ if (onlyRoot && ds.some((d) => /\bvar\(/.test(d.value))) rootOnly.push(r.name);
228
+ }
229
+ const rootOnlyNote = rootOnly.length
230
+ ? {
231
+ id: 'root-only-roles',
232
+ name: rootOnly.join(' '),
233
+ detail: `declared only on :root as var(…), so a nested [data-theme] island inherits the value :root resolved, not its own theme's. Declare them in each theme's rule too (e.g. \`.ds[data-theme="light"], [data-theme="light"] { ${rootOnly[0]}: var(…); }\`), so every island resolves var() against its own theme.`,
234
+ }
235
+ : null;
236
+
212
237
  // ── Value types + unresolved refs ──────────────────────────────────────────
213
238
  const typeErrors: TypeError_[] = [];
214
239
  const unresolvedRefs: { name: string; ref: string }[] = [];
@@ -256,7 +281,7 @@ export function checkSystem(model: SystemModel, idx: RegistryIndex): SystemRepor
256
281
  collisions.push({ id: 'type-mismatch', name: e.name, detect: 'type' });
257
282
  }
258
283
  if (typeErrors.length) reasons.add('type-collision');
259
- const notes: SystemReport['notes'] = [];
284
+ const notes: SystemReport['notes'] = rootOnlyNote ? [rootOnlyNote] : [];
260
285
  for (const row of reg.collisions) {
261
286
  if (row.detect === 'type') continue;
262
287
  let hit: string | null = null;
@@ -6,6 +6,7 @@ import { join, resolve } from 'node:path';
6
6
  import { runCanvasModes } from './canvas-cli.ts';
7
7
  import { checkSystem, type SystemReport } from './check.ts';
8
8
  import { emitTokensJson } from './emit.ts';
9
+ import type { PostBuild } from './post-build.ts';
9
10
  import { indexRegistry, loadRegistry } from './registry.ts';
10
11
  import {
11
12
  diskFs,
@@ -261,7 +262,9 @@ function humanSystem(r: SystemReport): string {
261
262
  ` C7: ${r.c7.families} accent famil${r.c7.families === 1 ? 'y' : 'ies'} vs ${r.c7.strategy} → ${r.c7.pass ? 'pass' : 'FAIL'}`
262
263
  );
263
264
  for (const n of r.notes)
264
- lines.push(` note: ${n.id}${n.name ? ` (${n.name})` : ''} — ${n.detail}`);
265
+ lines.push(
266
+ ` ${n.id === 'root-only-roles' ? 'warning' : 'note'}: ${n.id}${n.name ? ` (${n.name})` : ''} — ${n.detail}`
267
+ );
265
268
  return lines.join('\n');
266
269
  }
267
270
 
@@ -274,7 +277,8 @@ export interface RunResult {
274
277
  export function runDsCheck(
275
278
  argv: string[],
276
279
  env: Record<string, string | undefined> = process.env,
277
- hookInput: string | null = null
280
+ hookInput: string | null = null,
281
+ post: PostBuild | null = null
278
282
  ): RunResult {
279
283
  const t0 = performance.now();
280
284
  let args: DsCheckArgs;
@@ -300,7 +304,7 @@ export function runDsCheck(
300
304
  if (args.emit) throw new UsageError('--emit is a system flag; run it without canvas flags');
301
305
  // `<ds> --canvases`: the system result rides along (its code wins when non-zero)
302
306
  const sys = args.allCanvases && args.systems.length ? systemReports(project, systems) : null;
303
- return runCanvasModes(args, project, sys, t0, hookInput);
307
+ return runCanvasModes(args, project, sys, t0, hookInput, post);
304
308
  }
305
309
  let emitted: { written: string[]; refused: string[] } | null = null;
306
310
  if (args.emit) {
@@ -170,6 +170,39 @@ function readText(abs: string): string | null {
170
170
  }
171
171
  }
172
172
 
173
+ /** The Design system canvas's own files (canvas, sidecar, board), moved from `dsAbs` into `trashAbs`. */
174
+ function moveDsCanvasFiles(dsAbs: string, trashAbs: string): string[] {
175
+ const moved: string[] = [];
176
+ for (const f of [DS_CANVAS, DS_META, DS_ANNOTATIONS]) {
177
+ const from = path.join(dsAbs, f);
178
+ if (!existsSync(from)) continue;
179
+ mkdirSync(trashAbs, { recursive: true });
180
+ renameSync(from, path.join(trashAbs, f));
181
+ moved.push(f);
182
+ }
183
+ return moved;
184
+ }
185
+
186
+ /**
187
+ * fix/ds-convert-hooks-cli #8 — a Design system canvas left over by a system that is a FOLDER (no
188
+ * head.json: a Restore that sync brought back, a copy) goes to the Trash the way Restore puts one
189
+ * there: `_trash/ds-convert/<ds>-<stamp>/`. `null` when the system is converted — then the canvas IS
190
+ * the system, and Restore (`ds convert <ds> --restore`) is the way back.
191
+ */
192
+ export function trashFolderDsCanvas(
193
+ designRoot: string,
194
+ dsRel: string,
195
+ now = Date.now()
196
+ ): { trash: string; moved: string[] } | null {
197
+ const a = path.join(designRoot, ...dsRel.split('/'));
198
+ if (readHead(a).state !== 'absent') return null;
199
+ const name = path.basename(a);
200
+ let trash = `${RESTORE_TRASH_REL}/${name}-${stampOf(now)}`;
201
+ for (let n = 2; existsSync(path.join(designRoot, trash)); n++)
202
+ trash = `${RESTORE_TRASH_REL}/${name}-${stampOf(now)}-${n}`;
203
+ return { trash, moved: moveDsCanvasFiles(a, path.join(designRoot, trash)) };
204
+ }
205
+
173
206
  const stampOf = (ms: number) =>
174
207
  new Date(ms)
175
208
  .toISOString()
@@ -580,12 +613,7 @@ export function createDsConvert(engine: DsEngine) {
580
613
  const moved = moveHeadAside(a, { head: h.doc.head, base: h.doc.base }, trashAbs);
581
614
  if (tokens !== null && tokens !== model.tokensJson)
582
615
  atomicWrite(path.join(a, TOKENS_JSON_KEY), tokens);
583
- for (const f of [DS_CANVAS, DS_META, DS_ANNOTATIONS]) {
584
- const from = path.join(a, f);
585
- if (!existsSync(from)) continue;
586
- renameSync(from, path.join(trashAbs, f));
587
- moved.push(f);
588
- }
616
+ moved.push(...moveDsCanvasFiles(a, trashAbs));
589
617
  return {
590
618
  action: 'restore',
591
619
  rev: null,
@@ -20,6 +20,7 @@ import path from 'node:path';
20
20
  import { LOCAL_OWNER } from '../access/request.ts';
21
21
  import { createDsUsage } from '../index/ds-usage.ts';
22
22
  import { type DsOp, type DsOpAnswer, runDsOp } from '../routes/ds.ts';
23
+ import { recordPendingDelete } from '../sync/pending-deletes.ts';
23
24
  import { createDsEngine } from './engine.ts';
24
25
  import type { By } from './head.ts';
25
26
 
@@ -556,6 +557,18 @@ export async function execDsPlan(
556
557
  usage,
557
558
  access: LOCAL_OWNER,
558
559
  by,
560
+ // #7 — no studio, no bus: a deletion (Restore trashing the Design system canvas) is written
561
+ // down for the next sync boot to tell the project (sync/pending-deletes.ts).
562
+ emit: (event, payload) => {
563
+ const p = payload as { action?: unknown; slug?: unknown; rel?: unknown } | null;
564
+ if (
565
+ event === 'canvas-list-update' &&
566
+ p?.action === 'removed' &&
567
+ typeof p.slug === 'string' &&
568
+ typeof p.rel === 'string'
569
+ )
570
+ recordPendingDelete(designRoot, { slug: p.slug, rel: p.rel });
571
+ },
559
572
  });
560
573
  } finally {
561
574
  usage?.stop();
@@ -0,0 +1,38 @@
1
+ // ds/post-build.ts — 2.0.5 (#205): what ds-check --canvas knows about canvases refused AFTER their build.
2
+ //
3
+ // The import walk (access/closure.ts) is static: it names a canvas that imports another canvas. A built module
4
+ // can still be refused at serve time (the inputs gate inlined a file another canvas owns); only the running
5
+ // studio knows, and it reports it on the main origin's `/_index-data` as `canvasRefusedInputs`
6
+ // (access/refused-inputs.ts). `bin/_ds-check-live.mjs` asks that studio — loopback only — and hands the answer
7
+ // here; with no studio ds-check says so and prints the static reasons only.
8
+
9
+ export interface PostBuild {
10
+ /** A studio for this project answered. False = only the import walk was checked. */
11
+ live: boolean;
12
+ /** canvas (design-root-relative, `ui/a.tsx`) → the design-root files its built module was refused for. */
13
+ refused: Map<string, string[]>;
14
+ }
15
+
16
+ export const NO_STUDIO: PostBuild = { live: false, refused: new Map() };
17
+
18
+ /** What to print when no studio answered, so a quiet report is not read as "nothing is refused". */
19
+ export const NO_STUDIO_NOTE =
20
+ 'note: no studio is running for this project — only the import walk was checked. A canvas refused after its build (it uses a file another canvas owns) shows here while the studio is open.';
21
+
22
+ /** `/_index-data` → the refused files per canvas, keys design-root-relative. Anything else is ignored. */
23
+ export function refusedFromIndex(index: unknown): Map<string, string[]> {
24
+ const out = new Map<string, string[]>();
25
+ if (!index || typeof index !== 'object') return out;
26
+ const rec = index as { designRoot?: unknown; canvasRefusedInputs?: unknown };
27
+ const designRel =
28
+ typeof rec.designRoot === 'string' && rec.designRoot ? rec.designRoot : '.design';
29
+ const raw = rec.canvasRefusedInputs;
30
+ if (!raw || typeof raw !== 'object' || Array.isArray(raw)) return out;
31
+ for (const [key, list] of Object.entries(raw as Record<string, unknown>)) {
32
+ if (!Array.isArray(list)) continue;
33
+ const names = list.filter((n): n is string => typeof n === 'string' && n !== '');
34
+ if (!names.length) continue;
35
+ out.set(key.startsWith(`${designRel}/`) ? key.slice(designRel.length + 1) : key, names);
36
+ }
37
+ return out;
38
+ }
@@ -4,8 +4,10 @@
4
4
  // was visible (`systemFailed`), and the live tree still hashes to the stage's `beforeTreeHash`. Then:
5
5
  // 1. every codemodded canvas that passed the visual gate goes to the kernel as ONE proposal
6
6
  // (labelled "Brought <system> up to schema v1") — one Version-history entry, one ⌘Z;
7
- // 2. only once the kernel accepted it, the system files (tokens CSS, tokens.json, config.json's
8
- // `schema: 1`) are written on Plane B, tmp + rename, and the action's record lands in
7
+ // — its LANES only (.tsx / .meta.json / .annotations.json); a codemod's other files (a CSS
8
+ // twin) are no document's lane and go with step 2;
9
+ // 2. only once the kernel accepted it, those files and the system files (tokens CSS, tokens.json,
10
+ // config.json's `schema: 1`) are written on Plane B, tmp + rename, and the action's record lands in
9
11
  // `_state/ds-upgrade/<ds>/applied/<actionId>.json` with both versions of each file;
10
12
  // 3. the throwaway stage folder goes.
11
13
  // The undo hook (S10.2's `registerUndoHook`, wired through `registerDsUndoHook`) runs after the
@@ -69,6 +71,11 @@ export interface ApplyResult {
69
71
  }
70
72
 
71
73
  const NAME_RE = /^[A-Za-z0-9][A-Za-z0-9_-]{0,63}$/;
74
+ /** The files of a canvas the kernel holds as lanes of its document. */
75
+ export function canvasLanes(canvas: string): Set<string> {
76
+ const base = canvas.replace(/\.tsx$/i, '');
77
+ return new Set([canvas, `${base}.meta.json`, `${base}.annotations.json`]);
78
+ }
72
79
  const ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
73
80
  const readText = (abs: string) => {
74
81
  try {
@@ -119,14 +126,28 @@ async function applyLocked(inp: ApplyInput): Promise<ApplyResult> {
119
126
  );
120
127
  const pass = new Set(review.updatesCanvases.filter((c) => c.diff === 'pass').map((c) => c.path));
121
128
  const after = path.join(stage.dir, 'after', '.design');
129
+ // The kernel takes a canvas's LANES only (its .tsx, .meta.json, .annotations.json): a codemod's
130
+ // other files (the canvas's CSS twin) are no document's lane — a linked hub answers
131
+ // `unknown-canvas`, the local home `invalid`. They ride the file plane with the system files.
122
132
  const files: { rel: string; text: string }[] = [];
133
+ const planeFiles: { rel: string; before: string | null; after: string }[] = [];
134
+ const systemRels = new Set(stage.systemFiles.map((f) => f.rel));
135
+ const seen = new Set<string>();
123
136
  let updated = 0;
124
137
  for (const c of stage.canvases) {
125
138
  if (!pass.has(c.path)) continue;
139
+ const lanes = canvasLanes(c.path);
126
140
  for (const rel of c.files) {
127
141
  const text = readText(path.join(after, rel));
128
142
  if (text === null) throw new DsUpgradeError('ds-upgrade-no-stage', `the stage lost ${rel}`);
129
- files.push({ rel, text });
143
+ if (seen.has(rel)) continue;
144
+ seen.add(rel);
145
+ if (lanes.has(rel)) files.push({ rel, text });
146
+ else if (!systemRels.has(rel)) {
147
+ const abs = safeAbs(inp.designRoot, rel);
148
+ if (!abs) throw new DsUpgradeError('ds-upgrade-no-stage', `the stage names ${rel}`);
149
+ planeFiles.push({ rel, before: readText(abs), after: text });
150
+ }
130
151
  }
131
152
  updated++;
132
153
  }
@@ -147,8 +168,9 @@ async function applyLocked(inp: ApplyInput): Promise<ApplyResult> {
147
168
  );
148
169
  actionId = out.actionId ?? null;
149
170
  }
150
- // Plane B, after the kernel accepted: config.json (the schema flag) last
151
- const ordered = [...stage.systemFiles].sort(
171
+ // Plane B, after the kernel accepted: the canvases' other files, the system files, config.json
172
+ // (the schema flag) last
173
+ const ordered = [...planeFiles, ...stage.systemFiles].sort(
152
174
  (a, b) => Number(a.rel === 'config.json') - Number(b.rel === 'config.json')
153
175
  );
154
176
  for (const f of ordered) atomicWrite(path.join(inp.designRoot, f.rel), f.after);
@@ -44,6 +44,24 @@ export interface UpgradeAsyncOptions {
44
44
  }
45
45
 
46
46
  const out = (code: number, stdout = '', stderr = ''): UpgradeRun => ({ code, stdout, stderr });
47
+
48
+ export const USAGE = `usage: maude design ds-upgrade <ds> <step> [--root <project>]
49
+
50
+ Bring a design system up to the schema (V2-1.13 §5.10). Steps, in order:
51
+ --analyse the check + the mechanical plan, as JSON (read-only)
52
+ --plan-mechanical the plan JSON alone (read-only)
53
+ --validate <plan.json> the invariants on a judged plan (exit 13 = refused, nothing written)
54
+ --stage <plan.json> throwaway before/ + after/ copies; prints the stage, its "stamp" field
55
+ names it in the steps below
56
+ --prove <stamp> two headless studios + the visual gate → review.json
57
+ --apply <stamp> ONE action through the project's open studio (exit 3 = none open)
58
+ --discard <stamp> the throwaway copies and the record go
59
+ --status the live stages and their stamps: staged, being proved, proved
60
+ --cancel <stamp> stops a proof in flight (then --discard)
61
+
62
+ <stamp> is the digits --stage printed (or --status lists); the record folder
63
+ <designRoot>/_state/ds-upgrade/<ds>/<stamp>/ works too.
64
+ `;
47
65
  const json = (v: unknown) => `${JSON.stringify(v, null, 2)}\n`;
48
66
  const refusal = (e: DsUpgradeError) =>
49
67
  out(
@@ -64,6 +82,7 @@ export function runDsUpgrade(
64
82
  const names: string[] = [];
65
83
  for (let i = 0; i < argv.length; i++) {
66
84
  const t = argv[i];
85
+ if (t === '--help' || t === '-h' || t === 'help') return out(EXIT.ok, USAGE);
67
86
  if (t === '--root') root = argv[++i] ?? null;
68
87
  else if (t === '--analyse' || t === '--plan-mechanical' || t === '--status')
69
88
  step = t.slice(2);
@@ -78,12 +97,13 @@ export function runDsUpgrade(
78
97
  );
79
98
  } else if (t === '--json') {
80
99
  /* always JSON */
81
- } else if (t.startsWith('--')) throw new UsageError(`unknown flag ${t}`);
100
+ } else if (t.startsWith('--'))
101
+ throw new UsageError(`unknown flag ${t} (maude design ds-upgrade --help)`);
82
102
  else names.push(t);
83
103
  }
84
104
  if (names.length !== 1 || !step)
85
105
  throw new UsageError(
86
- 'usage: ds-upgrade <ds> --analyse | --plan-mechanical | --status | --validate|--stage <plan.json> | --prove|--apply|--discard|--cancel <stage>'
106
+ 'usage: ds-upgrade <ds> --analyse | --plan-mechanical | --status | --validate|--stage <plan.json> | --prove|--apply|--discard|--cancel <stamp> (--help for more)'
87
107
  );
88
108
  const project = loadProject(root, env);
89
109
  const [cfg] = selectSystems(project, names);