@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.
- package/apps/hub/src/project-transactions/kernel.mjs +10 -1
- package/apps/studio/access/filters.ts +12 -5
- package/apps/studio/access/known-canvases.ts +24 -1
- package/apps/studio/access/refused-inputs.ts +89 -0
- package/apps/studio/actions/agents.ts +5 -0
- package/apps/studio/actions/defs/app.ts +12 -0
- package/apps/studio/actions.manifest.json +13 -1
- package/apps/studio/actions.parity.json +7 -1
- package/apps/studio/annotations/ui/element-node.tsx +139 -54
- package/apps/studio/annotations/ui/lod.tsx +1 -1
- package/apps/studio/annotations/ui/text-style.ts +1 -1
- package/apps/studio/annotations-layer.tsx +0 -12
- package/apps/studio/api.ts +42 -0
- package/apps/studio/artboard-live-gate.tsx +267 -0
- package/apps/studio/artboard-live.ts +336 -0
- package/apps/studio/artboard-webgl.ts +668 -0
- package/apps/studio/bin/_agent-browser-bin.mjs +8 -0
- package/apps/studio/bin/_agent-browser-safe.mjs +2 -1
- package/apps/studio/bin/_canvas-reasons.mjs +34 -0
- package/apps/studio/bin/_ds-check-live.mjs +37 -0
- package/apps/studio/bin/_ds-check.mjs +4 -1
- package/apps/studio/bin/_ds-prove-judge.mjs +167 -0
- package/apps/studio/bin/_ds-prove-playwright.mjs +183 -105
- package/apps/studio/bin/_import-asset.mjs +2 -1
- package/apps/studio/bin/_perf-probe.mjs +2 -1
- package/apps/studio/bin/_studio-verb.mjs +24 -3
- package/apps/studio/bin/_thumb-blank.mjs +70 -0
- package/apps/studio/bin/_thumb-cover.mjs +35 -0
- package/apps/studio/bin/_thumbs-playwright.mjs +89 -12
- package/apps/studio/bin/ds-check.sh +5 -1
- package/apps/studio/bin/perf.sh +11 -1
- package/apps/studio/bin/server-up.sh +7 -2
- package/apps/studio/bin/smoke.sh +19 -0
- package/apps/studio/canvas-lib.tsx +131 -12
- package/apps/studio/client/canvas-url.js +13 -0
- package/apps/studio/client/home/HomeAccounts.jsx +262 -0
- package/apps/studio/client/home/Shelves.jsx +4 -3
- package/apps/studio/client/home/home-accounts-model.js +121 -0
- package/apps/studio/client/home/home-api.js +6 -0
- package/apps/studio/client/home/home-app.jsx +141 -40
- package/apps/studio/client/home/home-model.js +172 -6
- package/apps/studio/client/home/home.css +169 -5
- package/apps/studio/client/home/shell-mode.js +8 -1
- package/apps/studio/client/hooks/use-project-data.jsx +2 -0
- package/apps/studio/client/panels/ChatPanel.jsx +27 -20
- package/apps/studio/client/panels/CreateProject.jsx +19 -5
- package/apps/studio/client/panels/caps-cache.js +46 -0
- package/apps/studio/client/shell/viewport.jsx +36 -8
- package/apps/studio/client/v2/access/access-client.js +2 -0
- package/apps/studio/client/v2/access/access-host.jsx +12 -1
- package/apps/studio/client/v2/access/trashed-banner.jsx +6 -3
- package/apps/studio/client/v2/ai/Advanced.jsx +12 -0
- package/apps/studio/client/v2/ai/Composer.jsx +27 -10
- package/apps/studio/client/v2/code/canvas-imports-card.jsx +15 -14
- package/apps/studio/client/v2/code/canvas-imports-words.js +44 -0
- package/apps/studio/client/v2/code/code-bus.js +5 -0
- package/apps/studio/client/v2/ds/advanced-host.jsx +11 -26
- package/apps/studio/client/v2/ds/ds-refresh.js +161 -0
- package/apps/studio/client/v2/ds/library-host.jsx +45 -45
- package/apps/studio/client/v2/ds/make-host.jsx +13 -15
- package/apps/studio/client/v2/ds/off-system-host.jsx +18 -19
- package/apps/studio/client/v2/ds/review-host.jsx +7 -1
- package/apps/studio/client/v2/ds/truth-host.jsx +15 -17
- package/apps/studio/client/v2/ds/upgrade-host.jsx +26 -10
- package/apps/studio/client/v2/history/branch-actions.js +13 -9
- package/apps/studio/client/v2/history/git-advanced.jsx +8 -1
- package/apps/studio/client/v2/history/git-model.js +3 -1
- package/apps/studio/client/v2/history/git-parts.jsx +16 -1
- package/apps/studio/client/v2/presence/faces.jsx +42 -14
- package/apps/studio/client/v2/shell/account-card.jsx +10 -4
- package/apps/studio/client/v2/shell/canvas-crash-guard.js +137 -0
- package/apps/studio/client/v2/shell/github-signin-host.jsx +42 -0
- package/apps/studio/client/v2/shell/menu-runner.js +11 -0
- package/apps/studio/client/v2/shell/project-account-card.jsx +203 -0
- package/apps/studio/client/v2/shell/project-account-model.js +182 -0
- package/apps/studio/client/v2/shell/share-cluster-host.jsx +137 -10
- package/apps/studio/client/v2/shell/share-cluster.css +58 -0
- package/apps/studio/client/v2/shell/share-cluster.jsx +26 -7
- package/apps/studio/client/v2/shell/team-switch.js +94 -0
- package/apps/studio/client/v2/shell/too-heavy-card.jsx +38 -0
- package/apps/studio/client/v2/shell/use-account.js +8 -1
- package/apps/studio/collab/persistence.ts +9 -1
- package/apps/studio/collab/registry.ts +32 -0
- package/apps/studio/collab/room.ts +8 -0
- package/apps/studio/config-reload-wire.ts +53 -0
- package/apps/studio/dist/client.bundle.js +1232 -1232
- package/apps/studio/dist/styles.css +1 -1
- package/apps/studio/ds/board/specimen.tsx +12 -1
- package/apps/studio/ds/canvas-cli.ts +58 -2
- package/apps/studio/ds/check.ts +26 -1
- package/apps/studio/ds/cli.ts +7 -3
- package/apps/studio/ds/convert.ts +34 -6
- package/apps/studio/ds/ds-verb.ts +13 -0
- package/apps/studio/ds/post-build.ts +38 -0
- package/apps/studio/ds/upgrade-apply.ts +27 -5
- package/apps/studio/ds/upgrade-cli.ts +22 -2
- package/apps/studio/ds/upgrade-prove.ts +198 -15
- package/apps/studio/ds/upgrade-stage.ts +4 -1
- package/apps/studio/history/trash.ts +6 -0
- package/apps/studio/home/accounts.ts +87 -0
- package/apps/studio/home/index-reader.ts +24 -2
- package/apps/studio/home/routes.ts +19 -0
- package/apps/studio/http.ts +14 -2
- package/apps/studio/routes/ds-convert.ts +18 -0
- package/apps/studio/routes/trash.ts +16 -1
- package/apps/studio/server.ts +8 -10
- package/apps/studio/sync/accepted-cold-start.ts +28 -13
- package/apps/studio/sync/asset-push.ts +146 -23
- package/apps/studio/sync/asset-state.ts +3 -2
- package/apps/studio/sync/file-membership.ts +28 -3
- package/apps/studio/sync/file-plane.ts +40 -9
- package/apps/studio/sync/file-pull.ts +304 -33
- package/apps/studio/sync/hub-link.ts +1 -2
- package/apps/studio/sync/index.ts +308 -150
- package/apps/studio/sync/journal-client.ts +94 -5
- package/apps/studio/sync/pending-deletes.ts +100 -0
- package/apps/studio/sync/projection.ts +77 -12
- package/apps/studio/sync/seed-progress.ts +12 -1
- package/apps/studio/sync/status.ts +3 -1
- package/apps/studio/thumbs/service.ts +12 -2
- package/apps/studio/thumbs/validate.ts +7 -0
- package/apps/studio/ui-prefs-migrate.ts +4 -0
- package/apps/studio/video-comp.tsx +23 -0
- package/apps/studio/whats-new.json +72 -0
- package/cli/lib/bash-guard.mjs +13 -1
- package/cli/lib/design-help.gen.mjs +1 -1
- package/cli/lib/design-hook.mjs +20 -0
- package/cli/lib/studio-locate.mjs +35 -10
- package/package.json +8 -8
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Internal shim behind smoke.sh — 2.0.5 (#205): why a canvas does not render, in the shell card's own words.
|
|
2
|
+
//
|
|
3
|
+
// Reads the studio's `/_index-data` answer on stdin (smoke.sh fetches it from the main origin of the server
|
|
4
|
+
// it is already smoking) and prints, per canvas that imports another canvas (`canvasImportsCanvases`) or whose
|
|
5
|
+
// built module was refused for a file another canvas owns (`canvasRefusedInputs`):
|
|
6
|
+
//
|
|
7
|
+
// REFUSED ui/Home.tsx — This canvas uses ui/Shared.tsx, which belongs to another canvas. Move the shared …
|
|
8
|
+
//
|
|
9
|
+
// Lines go to stdout, one per canvas; nothing (exit 0) when there is nothing to say or the answer is unreadable.
|
|
10
|
+
import { canvasImportsLines } from '../client/v2/code/canvas-imports-words.js';
|
|
11
|
+
|
|
12
|
+
export function reasonLines(index, componentDir) {
|
|
13
|
+
if (!index || typeof index !== 'object') return [];
|
|
14
|
+
const designRel = typeof index.designRoot === 'string' ? index.designRoot : '.design';
|
|
15
|
+
const imports = index.canvasImportsCanvases ?? {};
|
|
16
|
+
const refused = index.canvasRefusedInputs ?? {};
|
|
17
|
+
const keys = [...new Set([...Object.keys(imports), ...Object.keys(refused)])].sort();
|
|
18
|
+
return keys.map((k) => {
|
|
19
|
+
const rel = k.startsWith(`${designRel}/`) ? k.slice(designRel.length + 1) : k;
|
|
20
|
+
const words = canvasImportsLines(imports[k] ?? [], componentDir, refused[k] ?? []);
|
|
21
|
+
return `REFUSED ${rel} — ${words.join(' ')}`;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (import.meta.main) {
|
|
26
|
+
let index = null;
|
|
27
|
+
try {
|
|
28
|
+
index = JSON.parse(await Bun.stdin.text());
|
|
29
|
+
} catch {
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
const lines = reasonLines(index, process.argv[2]);
|
|
33
|
+
if (lines.length) process.stdout.write(`${lines.join('\n')}\n`);
|
|
34
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// Internal helper behind _ds-check.mjs — 2.0.5 (#205): ask the project's running studio which canvases it
|
|
2
|
+
// refused after their build (`/_index-data` `canvasRefusedInputs`), for `ds-check --canvas`.
|
|
3
|
+
//
|
|
4
|
+
// The studio is found the one way every in-process verb finds it (cli/lib/studio-locate.mjs): the
|
|
5
|
+
// `_server.json` PORT only, on 127.0.0.1, a live pid, and `/_health` naming THIS root — so a planted
|
|
6
|
+
// `_server.json` cannot point ds-check at another host or project. Any failure → "no studio": ds-check then
|
|
7
|
+
// says so and prints the static reasons only.
|
|
8
|
+
import { resolve } from 'node:path';
|
|
9
|
+
import { locateStudio } from '../../../cli/lib/studio-locate.mjs';
|
|
10
|
+
import { NO_STUDIO, refusedFromIndex } from '../ds/post-build.ts';
|
|
11
|
+
|
|
12
|
+
/** The project root ds-check will use (`--root`, else $CLAUDE_PROJECT_DIR, else the cwd). */
|
|
13
|
+
export function rootOf(argv, env = process.env, cwd = process.cwd()) {
|
|
14
|
+
const i = argv.indexOf('--root');
|
|
15
|
+
return resolve(i >= 0 && argv[i + 1] ? argv[i + 1] : (env.CLAUDE_PROJECT_DIR ?? cwd));
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** Only the canvas modes that print a per-canvas report look; a PostToolUse hook never waits on a studio. */
|
|
19
|
+
export function wantsLive(argv) {
|
|
20
|
+
if (argv.includes('--hook') || argv.includes('--cheatsheet')) return false;
|
|
21
|
+
return argv.some((a) => a === '--canvas' || a === '--canvases' || a === '--changed');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** `{ live, refused }` — never throws, never touches anything but 127.0.0.1. `locate` is for tests. */
|
|
25
|
+
export async function liveRefusals(root, { locate = locateStudio, timeoutMs = 1500 } = {}) {
|
|
26
|
+
try {
|
|
27
|
+
const studio = await locate(root, { timeoutMs });
|
|
28
|
+
if (!studio) return NO_STUDIO;
|
|
29
|
+
const res = await fetch(`${studio.base}/_index-data`, {
|
|
30
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
31
|
+
});
|
|
32
|
+
if (!res.ok) return NO_STUDIO;
|
|
33
|
+
return { live: true, refused: refusedFromIndex(await res.json()) };
|
|
34
|
+
} catch {
|
|
35
|
+
return NO_STUDIO;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// Internal shim behind ds-check.sh (`maude design ds-check`). See ds-check.sh for usage.
|
|
2
2
|
import { runDsCheck } from '../ds/cli.ts';
|
|
3
|
+
import { liveRefusals, rootOf, wantsLive } from './_ds-check-live.mjs';
|
|
3
4
|
|
|
4
5
|
const argv = process.argv.slice(2);
|
|
5
6
|
const hook = argv.includes('--hook');
|
|
@@ -19,7 +20,9 @@ if (hook && !argv.includes('--canvas') && !process.stdin.isTTY) {
|
|
|
19
20
|
hookInput = null;
|
|
20
21
|
}
|
|
21
22
|
}
|
|
22
|
-
|
|
23
|
+
// 2.0.5 (#205): a canvas refused AFTER its build is known only to the running studio — ask it (loopback only).
|
|
24
|
+
const post = wantsLive(argv) ? await liveRefusals(rootOf(argv)) : undefined;
|
|
25
|
+
const r = runDsCheck(argv, process.env, hookInput, post);
|
|
23
26
|
// await the write: a large --json report piped to another process is truncated by an early exit
|
|
24
27
|
if (r.stdout) await new Promise((res) => process.stdout.write(r.stdout, res));
|
|
25
28
|
if (r.stderr && !hook) process.stderr.write(r.stderr);
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
// _ds-prove-judge.mjs — the pure half of the Bring-up visual gate (`_ds-prove-playwright.mjs`):
|
|
2
|
+
// which element is measured, how it is isolated and clipped, and how a measured pair is judged
|
|
3
|
+
// against the noise control. No imports: the page functions are handed to `page.evaluate` as they
|
|
4
|
+
// are (so they close over nothing), and the tests run them in happy-dom.
|
|
5
|
+
|
|
6
|
+
/** The pseudo-artboard id of a canvas that has no `[data-dc-screen]` (a specimen): its whole mount. */
|
|
7
|
+
export const SPECIMEN_ID = '(canvas)';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* In the page: the element to measure for `id` — an artboard, or (for SPECIMEN_ID) the canvas's own
|
|
11
|
+
* mount. Hides every element that is not it, one of its ancestors or one of its descendants
|
|
12
|
+
* (`visibility: hidden`, no layout change), so nothing else can cover it; sets the theme on the
|
|
13
|
+
* artboard's own `[data-theme]` nodes, or on `<html>` when it carries none (`htmlTheme`); resets the
|
|
14
|
+
* world's pan/zoom. Returns the element's rect, or null when it is not there. Idempotent: the first
|
|
15
|
+
* call saves what it changes, `restoreArtboard` puts it back.
|
|
16
|
+
*/
|
|
17
|
+
export function isolateArtboard({ id, theme, htmlTheme, specimenId }) {
|
|
18
|
+
const doc = document;
|
|
19
|
+
const find = () => {
|
|
20
|
+
if (id === specimenId) {
|
|
21
|
+
const root = doc.getElementById('canvas-root');
|
|
22
|
+
if (!root) return null;
|
|
23
|
+
return root.childElementCount === 1 ? root.firstElementChild : root;
|
|
24
|
+
}
|
|
25
|
+
return (
|
|
26
|
+
[...doc.querySelectorAll('[data-dc-screen]')].find(
|
|
27
|
+
(el) => el.getAttribute('data-dc-screen') === id
|
|
28
|
+
) ?? null
|
|
29
|
+
);
|
|
30
|
+
};
|
|
31
|
+
const el = find();
|
|
32
|
+
if (!el) return null;
|
|
33
|
+
window.__dsProveSaved ??= new Map();
|
|
34
|
+
if (!window.__dsProveSaved.has(id)) {
|
|
35
|
+
const themed = [el, ...el.querySelectorAll('[data-theme]')].filter((n) =>
|
|
36
|
+
n.hasAttribute('data-theme')
|
|
37
|
+
);
|
|
38
|
+
const hidden = [];
|
|
39
|
+
for (let n = el; n?.parentElement; n = n.parentElement)
|
|
40
|
+
for (const sib of n.parentElement.children) {
|
|
41
|
+
if (sib === n || /^(?:SCRIPT|STYLE|LINK|META|HEAD|TITLE)$/.test(sib.tagName)) continue;
|
|
42
|
+
hidden.push([sib, sib.style.visibility]);
|
|
43
|
+
}
|
|
44
|
+
window.__dsProveSaved.set(id, {
|
|
45
|
+
left: el.style.left,
|
|
46
|
+
top: el.style.top,
|
|
47
|
+
html: doc.documentElement.getAttribute('data-theme'),
|
|
48
|
+
themed: themed.map((n) => [n, n.getAttribute('data-theme')]),
|
|
49
|
+
hidden,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const saved = window.__dsProveSaved.get(id);
|
|
53
|
+
for (const [n] of saved.hidden) n.style.visibility = 'hidden';
|
|
54
|
+
if (saved.themed.length)
|
|
55
|
+
for (const [n, t] of saved.themed) n.setAttribute('data-theme', theme ?? t);
|
|
56
|
+
else if (htmlTheme) doc.documentElement.setAttribute('data-theme', htmlTheme);
|
|
57
|
+
const world = doc.querySelector('.dc-world');
|
|
58
|
+
if (world) {
|
|
59
|
+
world.style.zoom = '1';
|
|
60
|
+
world.style.transform = 'none';
|
|
61
|
+
}
|
|
62
|
+
// an artboard far out in the world is brought to the page's origin (a specimen flows there already)
|
|
63
|
+
if (id !== specimenId) {
|
|
64
|
+
el.style.left = '0px';
|
|
65
|
+
el.style.top = '0px';
|
|
66
|
+
const r = el.getBoundingClientRect();
|
|
67
|
+
if (r.left || r.top) {
|
|
68
|
+
el.style.left = `${-r.left}px`;
|
|
69
|
+
el.style.top = `${-r.top}px`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
window.scrollTo(0, 0);
|
|
73
|
+
const f = el.getBoundingClientRect();
|
|
74
|
+
return { x: f.left, y: f.top, width: f.width, height: f.height };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** In the page: undo `isolateArtboard(id)`. */
|
|
78
|
+
export function restoreArtboard({ id }) {
|
|
79
|
+
const saved = window.__dsProveSaved?.get(id);
|
|
80
|
+
if (!saved) return;
|
|
81
|
+
const el =
|
|
82
|
+
[...document.querySelectorAll('[data-dc-screen]')].find(
|
|
83
|
+
(n) => n.getAttribute('data-dc-screen') === id
|
|
84
|
+
) ?? null;
|
|
85
|
+
if (el) {
|
|
86
|
+
el.style.left = saved.left;
|
|
87
|
+
el.style.top = saved.top;
|
|
88
|
+
}
|
|
89
|
+
for (const [n, t] of saved.themed) n.setAttribute('data-theme', t);
|
|
90
|
+
if (saved.html === null) document.documentElement.removeAttribute('data-theme');
|
|
91
|
+
else document.documentElement.setAttribute('data-theme', saved.html);
|
|
92
|
+
for (const [n, v] of saved.hidden) n.style.visibility = v;
|
|
93
|
+
window.__dsProveSaved.delete(id);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* The screenshot clip: the element's OWN rect (never a corner of the viewport), whole pixels,
|
|
98
|
+
* inside the page, at most `maxSide` a side. Null when there is nothing to shoot.
|
|
99
|
+
*/
|
|
100
|
+
export function clipOf(rect, maxSide = 4000) {
|
|
101
|
+
if (!rect) return null;
|
|
102
|
+
const x = Math.max(0, Math.floor(rect.x));
|
|
103
|
+
const y = Math.max(0, Math.floor(rect.y));
|
|
104
|
+
const width = Math.min(maxSide, Math.ceil(rect.x + rect.width) - x);
|
|
105
|
+
const height = Math.min(maxSide, Math.ceil(rect.y + rect.height) - y);
|
|
106
|
+
if (!(width > 0 && height > 0)) return null;
|
|
107
|
+
return { x, y, width, height };
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The viewport an element needs to be shot whole: at least `base`, at most `maxSide`. */
|
|
111
|
+
export function viewportFor(rect, base, maxSide = 4000) {
|
|
112
|
+
return {
|
|
113
|
+
width: Math.min(maxSide, Math.max(base.width, Math.ceil(rect.x + rect.width))),
|
|
114
|
+
height: Math.min(maxSide, Math.max(base.height, Math.ceil(rect.y + rect.height))),
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** One measured pair: same size, changed pixels over its area. */
|
|
119
|
+
export const pairFails = (d, ratio) => !d.sized || d.changed / Math.max(1, d.area) > ratio;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The verdict for one artboard in one theme. `ab` is before × after. When it fails, the gate renders
|
|
123
|
+
* `before` a second time the way it rendered `after` (`ac` = before × control, `bc` = after × control,
|
|
124
|
+
* same procedure, same page kind): a pair that differs with ITSELF cannot be a failure.
|
|
125
|
+
* - no control (it passed, or the control could not render): `ab` decides
|
|
126
|
+
* - the control is clean (before × before is identical): `ab` decides — the change is real
|
|
127
|
+
* - the control is noisy: after × control decides (both rendered the same way); and a residue no
|
|
128
|
+
* larger than the noise itself is noise too
|
|
129
|
+
* Returns { fail, noise } — `noise: true` marks a failure the control explained away.
|
|
130
|
+
*/
|
|
131
|
+
export function judge({ ab, ac, bc }, ratio) {
|
|
132
|
+
if (!pairFails(ab, ratio)) return { fail: false, noise: false };
|
|
133
|
+
if (!ac || !bc) return { fail: true, noise: false };
|
|
134
|
+
if (!pairFails(ac, ratio)) return { fail: true, noise: false };
|
|
135
|
+
if (!pairFails(bc, ratio)) return { fail: false, noise: true };
|
|
136
|
+
const area = Math.max(1, bc.area);
|
|
137
|
+
const within = bc.sized && bc.changed <= ac.changed + ratio * area;
|
|
138
|
+
return within ? { fail: false, noise: true } : { fail: true, noise: false };
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** The themes one artboard is measured in: its own, else the system's (set on `<html>`), else none. */
|
|
142
|
+
export function themesFor(own, systemThemes) {
|
|
143
|
+
if (own.length) return own.map((t) => ({ theme: t, htmlTheme: null }));
|
|
144
|
+
if (systemThemes?.length) return systemThemes.map((t) => ({ theme: t, htmlTheme: t }));
|
|
145
|
+
return [{ theme: null, htmlTheme: null }];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Run `fn` with a hard deadline. On time: { ok: true, value }; past it: { ok: false } — `fn` is left
|
|
150
|
+
* running (the caller throws its page away). `fn` failing rejects as usual.
|
|
151
|
+
*/
|
|
152
|
+
export async function withDeadline(fn, ms) {
|
|
153
|
+
let timer;
|
|
154
|
+
const late = new Promise((r) => {
|
|
155
|
+
timer = setTimeout(() => r({ ok: false }), ms);
|
|
156
|
+
});
|
|
157
|
+
try {
|
|
158
|
+
return await Promise.race([
|
|
159
|
+
Promise.resolve()
|
|
160
|
+
.then(fn)
|
|
161
|
+
.then((value) => ({ ok: true, value })),
|
|
162
|
+
late,
|
|
163
|
+
]);
|
|
164
|
+
} finally {
|
|
165
|
+
clearTimeout(timer);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
@@ -2,18 +2,33 @@
|
|
|
2
2
|
// S10.15a). Spawned by ds/upgrade-prove.ts as a subprocess (so `bun --compile` of the studio never
|
|
3
3
|
// pulls playwright in), exactly like the exporters' shims.
|
|
4
4
|
//
|
|
5
|
-
// Input: `--job <file.json>` = { before, after, canvases: [{path, tokens, components}],
|
|
6
|
-
// ratio, timeout }. `before` / `after` are the origins of two
|
|
7
|
-
// copies; every URL goes through the main origin's 307 to that
|
|
8
|
-
// For every artboard of every canvas
|
|
9
|
-
//
|
|
10
|
-
//
|
|
5
|
+
// Input: `--job <file.json>` = { before, after, canvases: [{path, tokens, components, themes}],
|
|
6
|
+
// deltaE, ratio, timeout, canvasTimeout, workers? }. `before` / `after` are the origins of two
|
|
7
|
+
// headless studios on the staged copies; every URL goes through the main origin's 307 to that
|
|
8
|
+
// studio's read-only capture origin. For every artboard of every canvas (a specimen with none: its
|
|
9
|
+
// whole mount), in every theme it carries (`[data-theme]` inside it, flipped in place; one that
|
|
10
|
+
// carries none: each system theme, on `<html>`), both renders are shot by the artboard's OWN rect
|
|
11
|
+
// with everything else hidden (`_ds-prove-judge.mjs`) and diffed IN THE PAGE: OKLab ΔE × 100 >
|
|
12
|
+
// deltaE is a changed pixel, changed / area > ratio fails the artboard. A failing pair gets a noise
|
|
13
|
+
// control — `before` rendered again — and a pair that differs with itself is not a failure. Each
|
|
14
|
+
// canvas has a hard deadline: past it the canvas is `timeout` and the run goes on. No new
|
|
11
15
|
// dependency — the decode and the maths run in Chromium.
|
|
12
16
|
//
|
|
13
|
-
// Output (stdout, last line): { canvases: [{path, error?, artboards: [{id, theme,
|
|
14
|
-
// changed, area, fail, reason?}]}] }.
|
|
17
|
+
// Output (stdout, last line): { canvases: [{path, error?, specimen?, artboards: [{id, theme,
|
|
18
|
+
// width, height, changed, area, fail, reason?, noise?, empty?, control?}]}] }.
|
|
15
19
|
|
|
16
20
|
import { readFileSync } from 'node:fs';
|
|
21
|
+
import {
|
|
22
|
+
clipOf,
|
|
23
|
+
isolateArtboard,
|
|
24
|
+
judge,
|
|
25
|
+
pairFails,
|
|
26
|
+
restoreArtboard,
|
|
27
|
+
SPECIMEN_ID,
|
|
28
|
+
themesFor,
|
|
29
|
+
viewportFor,
|
|
30
|
+
withDeadline,
|
|
31
|
+
} from './_ds-prove-judge.mjs';
|
|
17
32
|
import { launchChromium, newShellContext } from './_pw-launch.mjs';
|
|
18
33
|
|
|
19
34
|
const argv = process.argv.slice(2);
|
|
@@ -27,6 +42,8 @@ const DELTA_E = Number(job.deltaE ?? 2);
|
|
|
27
42
|
const RATIO = Number(job.ratio ?? 0.005);
|
|
28
43
|
const TIMEOUT = Number(job.timeout ?? 20000);
|
|
29
44
|
const MAX_SIDE = 4000;
|
|
45
|
+
const CANVAS_TIMEOUT = Number(job.canvasTimeout ?? 180000);
|
|
46
|
+
const BASE_VIEWPORT = { width: 1440, height: 900 };
|
|
30
47
|
|
|
31
48
|
const shellUrl = (origin, c) => {
|
|
32
49
|
const p = new URLSearchParams();
|
|
@@ -52,6 +69,7 @@ async function open(page, url, gotoShell) {
|
|
|
52
69
|
err: !!document.getElementById('canvas-mount-error')?.textContent?.trim(),
|
|
53
70
|
mounted:
|
|
54
71
|
!!window.__maudeCanvasRuntime ||
|
|
72
|
+
!!window.__dsProveMounted ||
|
|
55
73
|
(document.getElementById('canvas-root')?.childElementCount ?? 0) > 0,
|
|
56
74
|
}))
|
|
57
75
|
.catch(() => null);
|
|
@@ -104,11 +122,6 @@ async function open(page, url, gotoShell) {
|
|
|
104
122
|
}
|
|
105
123
|
return page.evaluate(() => {
|
|
106
124
|
const err = document.getElementById('canvas-mount-error')?.textContent?.trim() || null;
|
|
107
|
-
const world = document.querySelector('.dc-world');
|
|
108
|
-
if (world) {
|
|
109
|
-
world.style.zoom = '1';
|
|
110
|
-
world.style.transform = 'none';
|
|
111
|
-
}
|
|
112
125
|
const boards = [...document.querySelectorAll('[data-dc-screen]')].map((el) => ({
|
|
113
126
|
id: el.getAttribute('data-dc-screen') || '',
|
|
114
127
|
themes: [
|
|
@@ -123,62 +136,51 @@ async function open(page, url, gotoShell) {
|
|
|
123
136
|
});
|
|
124
137
|
}
|
|
125
138
|
|
|
126
|
-
/**
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
()
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
}
|
|
171
|
-
await page.evaluate((id) => {
|
|
172
|
-
const ab = [...document.querySelectorAll('[data-dc-screen]')].find(
|
|
173
|
-
(el) => el.getAttribute('data-dc-screen') === id
|
|
174
|
-
);
|
|
175
|
-
const saved = window.__dsProveSaved?.get(id);
|
|
176
|
-
if (!ab || !saved) return;
|
|
177
|
-
ab.style.left = saved.left;
|
|
178
|
-
ab.style.top = saved.top;
|
|
179
|
-
for (const [n, t] of saved.themed) n.setAttribute('data-theme', t);
|
|
180
|
-
}, id);
|
|
181
|
-
return { png, width: rect.width, height: rect.height };
|
|
139
|
+
/** Two animation frames: what was set is laid out and painted. */
|
|
140
|
+
const frames = (page) =>
|
|
141
|
+
page.evaluate(() => new Promise((r) => requestAnimationFrame(() => requestAnimationFrame(r))));
|
|
142
|
+
|
|
143
|
+
/** Isolate the element and read its rect until it holds still (a hug artboard settles a pass late). */
|
|
144
|
+
async function stableRect(page, arg) {
|
|
145
|
+
let last = '';
|
|
146
|
+
let still = 0;
|
|
147
|
+
let rect = null;
|
|
148
|
+
for (let i = 0; i < 30 && still < 2; i++) {
|
|
149
|
+
rect = await page.evaluate(isolateArtboard, arg);
|
|
150
|
+
if (!rect) return null;
|
|
151
|
+
const key = [rect.x, rect.y, rect.width, rect.height].map(Math.round).join(',');
|
|
152
|
+
still = key === last ? still + 1 : 0;
|
|
153
|
+
last = key;
|
|
154
|
+
await frames(page);
|
|
155
|
+
}
|
|
156
|
+
return rect;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* One artboard (or a specimen's mount) in one theme → a PNG of exactly its own rect, everything else
|
|
161
|
+
* hidden. Every page goes through the same steps from the same viewport, whatever it shot before —
|
|
162
|
+
* so before and after are measured alike (the old shim sized after's viewport from before's shot, and
|
|
163
|
+
* the same unchanged artboard came out a different size). `{ empty: true }` = nothing rendered.
|
|
164
|
+
*/
|
|
165
|
+
async function shot(page, id, { theme, htmlTheme }) {
|
|
166
|
+
const arg = { id, theme, htmlTheme, specimenId: SPECIMEN_ID };
|
|
167
|
+
await page.setViewportSize(BASE_VIEWPORT);
|
|
168
|
+
try {
|
|
169
|
+
let rect = await stableRect(page, arg);
|
|
170
|
+
if (!rect) return null;
|
|
171
|
+
const vp = viewportFor(rect, BASE_VIEWPORT, MAX_SIDE);
|
|
172
|
+
if (vp.width !== BASE_VIEWPORT.width || vp.height !== BASE_VIEWPORT.height) {
|
|
173
|
+
await page.setViewportSize(vp);
|
|
174
|
+
rect = await stableRect(page, arg);
|
|
175
|
+
if (!rect) return null;
|
|
176
|
+
}
|
|
177
|
+
const clip = clipOf(rect, MAX_SIDE);
|
|
178
|
+
if (!clip) return { empty: true };
|
|
179
|
+
const png = await page.screenshot({ clip, animations: 'disabled' });
|
|
180
|
+
return { png, width: Math.ceil(rect.width), height: Math.ceil(rect.height) };
|
|
181
|
+
} finally {
|
|
182
|
+
await page.evaluate(restoreArtboard, { id }).catch(() => {});
|
|
183
|
+
}
|
|
182
184
|
}
|
|
183
185
|
|
|
184
186
|
/** The diff, in the page: OKLab ΔE per pixel over two same-size PNGs. */
|
|
@@ -237,9 +239,23 @@ async function diffInPage(page, a, b, deltaE) {
|
|
|
237
239
|
);
|
|
238
240
|
}
|
|
239
241
|
|
|
242
|
+
/** before × after (or any two shots) → the measured pair. */
|
|
243
|
+
async function measure(pd, x, y) {
|
|
244
|
+
const d = await diffInPage(pd, x.png, y.png, DELTA_E);
|
|
245
|
+
return { sized: x.width === y.width && x.height === y.height, changed: d.changed, area: d.area };
|
|
246
|
+
}
|
|
247
|
+
|
|
240
248
|
/** One canvas on one worker's pages → its row. Never throws: a canvas that cannot render is a row with an error. */
|
|
241
|
-
async function proveCanvas(c, { pa, pb, pd, goto }) {
|
|
249
|
+
async function proveCanvas(c, { pa, pb, pc, pd, goto }) {
|
|
242
250
|
const row = { path: c.path, artboards: [] };
|
|
251
|
+
let control = null; // before, rendered a second time — opened only when a pair fails
|
|
252
|
+
const openControl = () => {
|
|
253
|
+
control ??= open(pc, shellUrl(job.before, c), goto).then(
|
|
254
|
+
(C) => (C.err ? null : C),
|
|
255
|
+
() => null
|
|
256
|
+
);
|
|
257
|
+
return control;
|
|
258
|
+
};
|
|
243
259
|
try {
|
|
244
260
|
const [A, B] = await Promise.all([
|
|
245
261
|
open(pa, shellUrl(job.before, c), goto),
|
|
@@ -250,32 +266,49 @@ async function proveCanvas(c, { pa, pb, pd, goto }) {
|
|
|
250
266
|
row.detail = String(A.err || B.err).slice(0, 300);
|
|
251
267
|
return row;
|
|
252
268
|
}
|
|
253
|
-
|
|
254
|
-
|
|
269
|
+
// A canvas with no artboard on either side (a specimen) is measured as one: its whole mount.
|
|
270
|
+
const specimen = !A.boards.length && !B.boards.length;
|
|
271
|
+
if (specimen) row.specimen = true;
|
|
272
|
+
const boards = specimen ? [{ id: SPECIMEN_ID, themes: [] }] : A.boards;
|
|
273
|
+
const bIds = new Set(specimen ? [SPECIMEN_ID] : B.boards.map((x) => x.id));
|
|
274
|
+
for (const board of boards) {
|
|
255
275
|
if (!bIds.has(board.id)) {
|
|
256
276
|
row.artboards.push({ id: board.id, theme: null, fail: true, reason: 'missing' });
|
|
257
277
|
continue;
|
|
258
278
|
}
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
279
|
+
for (const t of themesFor(board.themes, c.themes)) {
|
|
280
|
+
const sa = await shot(pa, board.id, t);
|
|
281
|
+
const sb = sa && (await shot(pb, board.id, t));
|
|
282
|
+
if (sa?.empty && sb?.empty) {
|
|
283
|
+
row.artboards.push({ id: board.id, theme: t.theme, empty: true, fail: false });
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
if (!sa || !sb || sa.empty || sb.empty) {
|
|
287
|
+
row.artboards.push({ id: board.id, theme: t.theme, fail: true, reason: 'missing' });
|
|
265
288
|
continue;
|
|
266
289
|
}
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
|
|
290
|
+
const ab = await measure(pd, sa, sb);
|
|
291
|
+
let ac = null;
|
|
292
|
+
let bc = null;
|
|
293
|
+
if (pairFails(ab, RATIO) && (await openControl())) {
|
|
294
|
+
const sc = await shot(pc, board.id, t);
|
|
295
|
+
if (sc && !sc.empty) {
|
|
296
|
+
ac = await measure(pd, sa, sc);
|
|
297
|
+
bc = await measure(pd, sb, sc);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
const v = judge({ ab, ac, bc }, RATIO);
|
|
270
301
|
row.artboards.push({
|
|
271
302
|
id: board.id,
|
|
272
|
-
theme,
|
|
303
|
+
theme: t.theme,
|
|
273
304
|
width: sa.width,
|
|
274
305
|
height: sa.height,
|
|
275
|
-
changed:
|
|
276
|
-
area:
|
|
277
|
-
fail,
|
|
278
|
-
...(sized ? {} : { reason: 'size' }),
|
|
306
|
+
changed: ab.changed,
|
|
307
|
+
area: ab.area,
|
|
308
|
+
fail: v.fail,
|
|
309
|
+
...(ab.sized ? {} : { reason: 'size' }),
|
|
310
|
+
...(v.noise ? { noise: true } : {}),
|
|
311
|
+
...(ac ? { control: { changed: ac.changed, area: ac.area, sized: ac.sized } } : {}),
|
|
279
312
|
});
|
|
280
313
|
}
|
|
281
314
|
}
|
|
@@ -286,42 +319,87 @@ async function proveCanvas(c, { pa, pb, pd, goto }) {
|
|
|
286
319
|
return row;
|
|
287
320
|
}
|
|
288
321
|
|
|
322
|
+
const CONTEXT_OPTS = {
|
|
323
|
+
serviceWorkers: 'block',
|
|
324
|
+
viewport: BASE_VIEWPORT,
|
|
325
|
+
deviceScaleFactor: 1,
|
|
326
|
+
reducedMotion: 'reduce',
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/** A worker's own context and pages (before, after, the noise control, the diff page). */
|
|
330
|
+
async function newPages(browser) {
|
|
331
|
+
// gate-b-c4d — each page confined to the origin its shell lands on (popups, other origins refused).
|
|
332
|
+
const { ctx, goto } = await newShellContext(browser, CONTEXT_OPTS);
|
|
333
|
+
// The shell tells its parent the canvas mounted (`canvas-mounted`, also for a specimen that
|
|
334
|
+
// renders nothing); at the top level that parent is the page itself. Without it such a canvas
|
|
335
|
+
// waited out the whole timeout on both sides.
|
|
336
|
+
await ctx.addInitScript(() => {
|
|
337
|
+
addEventListener('message', (e) => {
|
|
338
|
+
const d = e.data;
|
|
339
|
+
if (d && (d.dgn === 'canvas-mounted' || d.dgn === 'canvas-rendered'))
|
|
340
|
+
window.__dsProveMounted = true;
|
|
341
|
+
});
|
|
342
|
+
});
|
|
343
|
+
const pages = {
|
|
344
|
+
pa: await ctx.newPage(),
|
|
345
|
+
pb: await ctx.newPage(),
|
|
346
|
+
pc: await ctx.newPage(),
|
|
347
|
+
pd: await ctx.newPage(),
|
|
348
|
+
goto,
|
|
349
|
+
};
|
|
350
|
+
await pages.pd.setContent('<!doctype html><title>ds prove diff</title>');
|
|
351
|
+
return { ctx, pages };
|
|
352
|
+
}
|
|
353
|
+
|
|
289
354
|
// Canvases are independent, so a few workers prove them side by side, each on a context of its own
|
|
290
355
|
// (a canvas's render is a page, not the machine). The order of `out.canvases` is the job's.
|
|
356
|
+
//
|
|
357
|
+
// Every canvas has a hard deadline (`canvasTimeout`): a canvas whose renderer never answers (a heavy
|
|
358
|
+
// 3D scene at 99 % CPU) is reported `timeout` and the run goes on — its worker throws the context
|
|
359
|
+
// away (closing its pages kills their renderers) and starts a fresh one; when even the close does not
|
|
360
|
+
// answer, the worker moves to a browser of its own, so no later canvas inherits the stuck one.
|
|
291
361
|
const WORKERS = Math.max(1, Math.min(Number(job.workers ?? 3), job.canvases.length || 1));
|
|
292
|
-
const
|
|
362
|
+
const shared = await launchChromium();
|
|
363
|
+
const browsers = new Set([shared]);
|
|
293
364
|
const out = { canvases: job.canvases.map((c) => ({ path: c.path, artboards: [] })) };
|
|
365
|
+
const closeWithin = (p, ms) => withDeadline(() => p, ms).catch(() => ({ ok: false }));
|
|
294
366
|
try {
|
|
295
367
|
let next = 0;
|
|
296
368
|
let done = 0;
|
|
297
369
|
const worker = async () => {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
serviceWorkers: 'block',
|
|
301
|
-
viewport: { width: 1440, height: 900 },
|
|
302
|
-
deviceScaleFactor: 1,
|
|
303
|
-
reducedMotion: 'reduce',
|
|
304
|
-
});
|
|
305
|
-
const pages = {
|
|
306
|
-
pa: await ctx.newPage(),
|
|
307
|
-
pb: await ctx.newPage(),
|
|
308
|
-
pd: await ctx.newPage(),
|
|
309
|
-
goto,
|
|
310
|
-
};
|
|
311
|
-
await pages.pd.setContent('<!doctype html><title>ds prove diff</title>');
|
|
370
|
+
let browser = shared;
|
|
371
|
+
let { ctx, pages } = await newPages(browser);
|
|
312
372
|
for (;;) {
|
|
313
373
|
const i = next++;
|
|
314
374
|
if (i >= job.canvases.length) break;
|
|
315
|
-
|
|
375
|
+
const c = job.canvases[i];
|
|
376
|
+
const r = await withDeadline(() => proveCanvas(c, pages), CANVAS_TIMEOUT);
|
|
377
|
+
if (r.ok) out.canvases[i] = r.value;
|
|
378
|
+
else {
|
|
379
|
+
out.canvases[i] = {
|
|
380
|
+
path: c.path,
|
|
381
|
+
error: 'timeout',
|
|
382
|
+
detail: `no answer within ${Math.round(CANVAS_TIMEOUT / 1000)} s`,
|
|
383
|
+
artboards: [],
|
|
384
|
+
};
|
|
385
|
+
const closed = await closeWithin(ctx.close(), 10_000);
|
|
386
|
+
if (!closed.ok) {
|
|
387
|
+
browser = await launchChromium();
|
|
388
|
+
browsers.add(browser);
|
|
389
|
+
}
|
|
390
|
+
({ ctx, pages } = await newPages(browser));
|
|
391
|
+
}
|
|
316
392
|
done++;
|
|
317
393
|
console.log(
|
|
318
394
|
`MAUDE_PROGRESS ${JSON.stringify({ current: done, total: job.canvases.length })}`
|
|
319
395
|
);
|
|
320
396
|
}
|
|
321
|
-
await ctx.close();
|
|
397
|
+
await closeWithin(ctx.close(), 10_000);
|
|
322
398
|
};
|
|
323
399
|
await Promise.all(Array.from({ length: WORKERS }, worker));
|
|
324
400
|
} finally {
|
|
325
|
-
await
|
|
401
|
+
await Promise.all([...browsers].map((b) => closeWithin(b.close(), 10_000)));
|
|
326
402
|
}
|
|
327
|
-
|
|
403
|
+
// a stuck renderer can keep the browser's pipes open: write the answer, then leave
|
|
404
|
+
await new Promise((r) => process.stdout.write(`${JSON.stringify(out)}\n`, r));
|
|
405
|
+
process.exit(0);
|
|
@@ -32,6 +32,7 @@ import { Worker } from 'node:worker_threads';
|
|
|
32
32
|
import { Window } from 'happy-dom';
|
|
33
33
|
import { recordAssetOrigin } from '../asset-origins.ts';
|
|
34
34
|
import { isValidSvg, optimizeSvg } from '../draw/optimize.ts';
|
|
35
|
+
import { resolveAgentBrowserBin } from './_agent-browser-bin.mjs';
|
|
35
36
|
|
|
36
37
|
export class ImportAssetError extends Error {
|
|
37
38
|
/**
|
|
@@ -535,7 +536,7 @@ export function assertPdfPageCap(pageCount, maxPages = PDF_MAX_PAGES) {
|
|
|
535
536
|
// ============================================================================
|
|
536
537
|
|
|
537
538
|
function agentBrowserBin() {
|
|
538
|
-
return
|
|
539
|
+
return resolveAgentBrowserBin();
|
|
539
540
|
}
|
|
540
541
|
|
|
541
542
|
function runAgentBrowser(sessionName, args, { timeoutMs = 20_000 } = {}) {
|