@ultimat3/cli 31.51.0 → 31.53.0
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/CLAUDE.md +1 -1
- package/README.md +9 -9
- package/package.json +29 -29
- package/src/app-kit-disk.ts +39 -0
- package/src/app-kit-forms.ts +27 -0
- package/src/app-kit.ts +146 -0
- package/src/budgets.ts +3 -1
- package/src/catalog-layout.ts +194 -0
- package/src/cdp-shot-driver-screen.ts +72 -0
- package/src/cdp-shot-driver.ts +17 -1
- package/src/cmd-design-capture.ts +210 -0
- package/src/cmd-design-errors.ts +50 -0
- package/src/cmd-design-paths.ts +47 -0
- package/src/cmd-design-publish.ts +64 -0
- package/src/cmd-design-run.ts +229 -0
- package/src/cmd-design-spec.ts +47 -0
- package/src/cmd-design-theme.ts +107 -0
- package/src/cmd-design-url.ts +201 -0
- package/src/cmd-design.ts +188 -0
- package/src/cmd-doctor.ts +3 -0
- package/src/cmd-generate-spec.ts +5 -0
- package/src/cmd-generate.ts +3 -1
- package/src/cmd-i18n-spec.ts +4 -4
- package/src/cmd-i18n-split.ts +133 -0
- package/src/cmd-i18n.ts +46 -66
- package/src/cmd-kit-spec.ts +13 -0
- package/src/cmd-kit.ts +133 -0
- package/src/cmd-shot-against.ts +275 -0
- package/src/cmd-shot-spec.ts +9 -1
- package/src/cmd-shot.ts +19 -0
- package/src/cmd-upgrade.ts +11 -0
- package/src/codemods/agent-kit.ts +130 -0
- package/src/codemods/agents-md-budget.ts +47 -0
- package/src/codemods/docs-visual-quality.ts +198 -0
- package/src/codemods/index.ts +8 -0
- package/src/codemods/settings-kit-allow.ts +49 -0
- package/src/config-redact.ts +20 -4
- package/src/db-rollback-pass.ts +4 -1
- package/src/design-extract-script.ts +187 -0
- package/src/design-extract.ts +311 -0
- package/src/design-map-colors.ts +180 -0
- package/src/design-map.ts +288 -0
- package/src/dev-child-watch.ts +16 -0
- package/src/dev-db-migrate.ts +27 -46
- package/src/dev-db-migrator-hold.ts +131 -0
- package/src/dev-db-rollback.ts +11 -2
- package/src/dev-rebuild-schema.ts +7 -24
- package/src/doctor-kit.ts +25 -0
- package/src/error-catalog.ts +4 -2
- package/src/error-codes-kit.ts +24 -0
- package/src/error-codes.ts +12 -10
- package/src/generate-catalog-locales.ts +25 -2
- package/src/generate-files.ts +31 -1
- package/src/generate-follow-ups.ts +8 -3
- package/src/guards-shipped-names.ts +5 -0
- package/src/i18n-audit.ts +17 -33
- package/src/i18n-index.ts +108 -31
- package/src/i18n-locale-parity.ts +14 -6
- package/src/i18n-new-locale.ts +75 -0
- package/src/i18n-registration.ts +52 -27
- package/src/island-capture.ts +36 -7
- package/src/kit/agent-audit.ts +49 -0
- package/src/kit/agent-data.ts +32 -0
- package/src/kit/agent-server.ts +34 -0
- package/src/kit/agent-shape.ts +61 -0
- package/src/kit/agent-web.ts +49 -0
- package/src/kit/design-map.ts +106 -0
- package/src/kit/managed.ts +12 -0
- package/src/kit/registry.ts +89 -0
- package/src/kit/skill-design-research.ts +119 -0
- package/src/kit/skill-feature.ts +159 -0
- package/src/kit/skill-planx.ts +139 -0
- package/src/kit/skill-upgrade.ts +94 -0
- package/src/kit/skill-verify.ts +80 -0
- package/src/mcp-errors.ts +5 -0
- package/src/mcp-ui-diff.ts +13 -38
- package/src/mcp-ui.ts +30 -1
- package/src/merge-state.ts +3 -2
- package/src/messages-design.ts +104 -0
- package/src/messages-floor.ts +2 -0
- package/src/messages-upgrade.ts +9 -0
- package/src/messages.ts +4 -0
- package/src/registry.ts +4 -0
- package/src/serve-boot-telemetry.ts +106 -0
- package/src/serve-boot.ts +23 -4
- package/src/shot-blank.ts +70 -0
- package/src/shot-diff.ts +96 -0
- package/src/shot-gpu.ts +17 -5
- package/src/templates/catalog-barrel.ts +84 -0
- package/src/templates/guard-animated-layout-script.ts +173 -0
- package/src/templates/guard-effect-without-fallback.ts +117 -0
- package/src/templates/guard-motion-adapter.ts +161 -0
- package/src/templates/guard-raw-frame-loop.ts +134 -0
- package/src/templates/guard-raw-motion-script.ts +132 -0
- package/src/templates/guard-raw-motion-ts-scan.ts +95 -0
- package/src/templates/guard-released-forms.ts +12 -1
- package/src/templates/guard-untranslated-string.ts +27 -6
- package/src/templates/index.ts +1 -2
- package/src/templates/island.ts +55 -8
- package/src/templates/kit-released-forms.ts +63 -0
- package/src/templates/locales.ts +6 -0
- package/src/templates/motion-scale.ts +115 -0
- package/src/templates/scaffold-claude.ts +39 -26
- package/src/templates/scaffold-design.ts +41 -0
- package/src/templates/scaffold-docs.ts +31 -7
- package/src/templates/scaffold-gitattributes.ts +9 -2
- package/src/templates/scaffold-guards.ts +31 -2
- package/src/templates/scaffold-i18n.ts +10 -6
- package/src/templates/scaffold-verify-floor.ts +3 -0
- package/src/templates/shapes/blog-site.ts +15 -0
- package/src/templates/shapes/blog.ts +2 -0
- package/src/templates/shapes/content-site.ts +13 -0
- package/src/templates/shapes/content.ts +2 -0
- package/src/templates/shapes/dashboard-detail.ts +2 -0
- package/src/templates/shapes/dashboard-motion.ts +284 -0
- package/src/templates/shapes/dashboard.ts +19 -1
- package/src/templates/shapes/landing-motion.ts +67 -0
- package/src/templates/shapes/offline.ts +5 -2
- package/src/templates/shapes/saas.ts +4 -0
- package/src/test-ignores.ts +3 -2
- package/src/upgrade-gate.ts +14 -2
- package/src/upgrade-kit.ts +65 -0
- package/src/upgrade-report-kit.ts +28 -0
- package/src/upgrade-report.ts +3 -0
- package/src/verify-checks.ts +9 -1
- package/src/verify-floor.ts +9 -1
- package/src/verify-local-only.ts +66 -0
- package/src/verify-run.ts +17 -2
- package/src/workspace-checks.ts +3 -3
- package/wiki/Actions.md +1 -1
- package/wiki/Agents.md +33 -1
- package/wiki/Auth.md +3 -3
- package/wiki/Batching-And-Preloading.md +1 -0
- package/wiki/CLI-Reference-Data.md +241 -0
- package/wiki/CLI-Reference-Gate.md +572 -0
- package/wiki/CLI-Reference-Project.md +414 -0
- package/wiki/CLI-Reference-Ship.md +348 -0
- package/wiki/CLI-Reference-Tools.md +687 -0
- package/wiki/CLI-Reference.md +18 -2227
- package/wiki/Compared.md +8 -8
- package/wiki/Configuration.md +26 -2
- package/wiki/Deployment.md +1 -1
- package/wiki/Design-Research.md +96 -0
- package/wiki/Effects.md +83 -0
- package/wiki/Entities-And-Migrations.md +3 -2
- package/wiki/FAQ.md +1 -1
- package/wiki/Getting-Started.md +1 -1
- package/wiki/Home.md +2 -2
- package/wiki/I18n.md +39 -5
- package/wiki/Installation.md +1 -1
- package/wiki/Jobs-And-Workflows.md +29 -1
- package/wiki/Known-Gaps.md +6 -2
- package/wiki/MCP-And-AI.md +4 -0
- package/wiki/Motion.md +85 -0
- package/wiki/Observability.md +15 -1
- package/wiki/Outbound-HTTP.md +62 -2
- package/wiki/PWA-And-Offline.md +1 -1
- package/wiki/Policies-And-Authz.md +10 -0
- package/wiki/Project-Layout.md +1 -1
- package/wiki/Realtime.md +29 -2
- package/wiki/Static-Assets.md +1 -1
- package/wiki/Testing.md +33 -0
- package/wiki/Theming.md +31 -8
- package/wiki/Troubleshooting.md +1 -1
- package/wiki/Tutorial-02-First-Feature.md +1 -1
- package/wiki/UI-Components.md +2 -0
- package/wiki/Upgrading.md +9 -3
- package/src/templates/scaffold-claude-agents.ts +0 -161
- package/src/templates/scaffold-claude-commands.ts +0 -239
package/src/cdp-shot-driver.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
launchChrome,
|
|
14
14
|
} from '@ultimat3/scraping/cdp';
|
|
15
15
|
import type { ShotDriver, ShotSession, ShotSessionInit } from './browser-launcher-port';
|
|
16
|
+
import { type DialScreen, screenedConnection } from './cdp-shot-driver-screen';
|
|
16
17
|
import { cdpShotPage } from './cdp-shot-page';
|
|
17
18
|
import { watchPage } from './cdp-shot-watch';
|
|
18
19
|
|
|
@@ -27,6 +28,14 @@ export interface CdpShotDriverOptions {
|
|
|
27
28
|
/** Attach here: a provider's `wss://` session, or a sidecar's `http://host:9222`. */
|
|
28
29
|
readonly cdpUrl?: string | undefined;
|
|
29
30
|
readonly viewport?: { readonly width: number; readonly height: number } | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* The DNS half of the session's interception (`cdp-shot-driver-screen.ts`): every paused request
|
|
33
|
+
* on the page AND the browser session is screened by it before the host allow list decides.
|
|
34
|
+
* `x design research` sets it, because its allow list is every PUBLIC host. `Fetch` pauses no
|
|
35
|
+
* WebSocket handshake (and `Network.setBlockedURLs` blocks none, measured on Chrome 150), so a
|
|
36
|
+
* caller that sets this also refuses WebSockets in the page itself — `DESIGN_PREPARE` does.
|
|
37
|
+
*/
|
|
38
|
+
readonly dialScreen?: Omit<DialScreen, 'owns'> | undefined;
|
|
30
39
|
/** Test seams: the two ways a connection comes to exist, so no test needs a browser. */
|
|
31
40
|
readonly launch?:
|
|
32
41
|
| ((executable: string, timeoutMs: number) => Promise<LaunchedBrowser>)
|
|
@@ -151,8 +160,15 @@ export function cdpShotDriver(options: CdpShotDriverOptions): ShotDriver {
|
|
|
151
160
|
});
|
|
152
161
|
}
|
|
153
162
|
// Watching BEFORE the domains are on, so the first request is already counted.
|
|
163
|
+
const dialScreen = options.dialScreen;
|
|
154
164
|
const watch = watchPage({
|
|
155
|
-
connection
|
|
165
|
+
connection:
|
|
166
|
+
dialScreen === undefined
|
|
167
|
+
? connection
|
|
168
|
+
: screenedConnection(connection, {
|
|
169
|
+
...dialScreen,
|
|
170
|
+
owns: (on) => on === sessionId || on === browserSessionId,
|
|
171
|
+
}),
|
|
156
172
|
sessionId,
|
|
157
173
|
browserSessionId,
|
|
158
174
|
clock: init.clock,
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// One reference URL photographed and measured: one browser per viewport, both colour schemes, the
|
|
2
|
+
// recorder installed before the document, the scroll-and-hover pass after load, a clipped PNG per
|
|
3
|
+
// (viewport, scheme).
|
|
4
|
+
//
|
|
5
|
+
// Every request the page makes is screened browser-wide (`dialScreen`), and a navigation the screen
|
|
6
|
+
// or the floor stopped is `X_DESIGN_URL_REFUSED`, never a picture of an error page.
|
|
7
|
+
|
|
8
|
+
// why: Bun has no recursive directory create.
|
|
9
|
+
import { mkdirSync } from 'node:fs';
|
|
10
|
+
// why: Bun exposes no path-join primitive.
|
|
11
|
+
import { join } from 'node:path';
|
|
12
|
+
import { isUltimateError, renderThrowable } from '@ultimat3/core';
|
|
13
|
+
import { systemClock } from '@ultimat3/core/adapter';
|
|
14
|
+
import { CdpCallFailedError, CdpTimeoutError } from '@ultimat3/scraping/cdp';
|
|
15
|
+
import type { CaptureClip, NetworkEntry, ShotDriver, ShotPage } from './browser-launcher-port';
|
|
16
|
+
import type { DialRefusal, DialScreen } from './cdp-shot-driver-screen';
|
|
17
|
+
import {
|
|
18
|
+
DesignAbortedError,
|
|
19
|
+
DesignReferenceUnreachableError,
|
|
20
|
+
DesignUrlRefusedError,
|
|
21
|
+
} from './cmd-design-errors';
|
|
22
|
+
import { DESIGN_SCHEMES, type DesignScheme, referenceShotName } from './cmd-design-paths';
|
|
23
|
+
import type { DesignHostPolicy } from './cmd-design-url';
|
|
24
|
+
import { browserDialScreen } from './cmd-design-url';
|
|
25
|
+
import { type Extraction, extractDesign, mergeExtractions } from './design-extract';
|
|
26
|
+
import { DESIGN_PREPARE } from './design-extract-script';
|
|
27
|
+
import { hash8 } from './shot-diff';
|
|
28
|
+
import { documentStatus } from './shot-verdict';
|
|
29
|
+
import { type ShotViewport, VIEWPORT_MAX } from './shot-viewport';
|
|
30
|
+
|
|
31
|
+
/** How a capture gets its browser: `cdpShotDriver` with the screen in production, a fake in tests. */
|
|
32
|
+
export type DesignDriverFor = (
|
|
33
|
+
viewport: ShotViewport,
|
|
34
|
+
dialScreen: Omit<DialScreen, 'owns'>,
|
|
35
|
+
) => Promise<ShotDriver>;
|
|
36
|
+
|
|
37
|
+
export interface CaptureInput {
|
|
38
|
+
readonly url: string;
|
|
39
|
+
readonly dir: string;
|
|
40
|
+
readonly viewports: readonly ShotViewport[];
|
|
41
|
+
readonly timeoutMs: number;
|
|
42
|
+
readonly policy: DesignHostPolicy;
|
|
43
|
+
readonly driverFor: DesignDriverFor;
|
|
44
|
+
readonly signal?: AbortSignal | undefined;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface Capture {
|
|
48
|
+
/** Where the page landed, as `pageRef`: `location.href` is page-settable text. */
|
|
49
|
+
readonly finalUrl: string;
|
|
50
|
+
readonly byScheme: Readonly<Record<DesignScheme, Extraction>>;
|
|
51
|
+
readonly shots: readonly string[];
|
|
52
|
+
/** Hostnames of every request refused as inward — the floor's and the resolver's — never a URL. */
|
|
53
|
+
readonly refusedHosts: readonly string[];
|
|
54
|
+
/** Hostnames refused because they did not resolve: unreachable, not private. */
|
|
55
|
+
readonly unresolvedHosts: readonly string[];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const hostOf = (url: string): string => {
|
|
59
|
+
try {
|
|
60
|
+
return new URL(url).hostname;
|
|
61
|
+
} catch {
|
|
62
|
+
return '';
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
/** The navigation's failure as one of this command's two codes. */
|
|
67
|
+
function navigationError(url: string, error: unknown, timeoutMs: number): Error {
|
|
68
|
+
if (isUltimateError(error) && error.code === 'X_SHOT_HOST_REFUSED') {
|
|
69
|
+
return new DesignUrlRefusedError({
|
|
70
|
+
url,
|
|
71
|
+
reason: 'names a loopback, private or link-local address',
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
const detail = renderThrowable(error);
|
|
75
|
+
// The one reason a navigation is BlockedByClient: the floor or the resolver failed it.
|
|
76
|
+
if (detail.includes('ERR_BLOCKED_BY_CLIENT')) {
|
|
77
|
+
return new DesignUrlRefusedError({
|
|
78
|
+
url,
|
|
79
|
+
reason:
|
|
80
|
+
'redirected to, or loaded its document from, a loopback, private or link-local address',
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
if (error instanceof CdpTimeoutError) {
|
|
84
|
+
return new DesignReferenceUnreachableError({
|
|
85
|
+
url,
|
|
86
|
+
reason: `did not finish loading within ${String(timeoutMs)}ms`,
|
|
87
|
+
timeoutMs,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
if (error instanceof CdpCallFailedError) {
|
|
91
|
+
return new DesignReferenceUnreachableError({ url, reason: detail, timeoutMs });
|
|
92
|
+
}
|
|
93
|
+
return error instanceof Error
|
|
94
|
+
? error
|
|
95
|
+
: new DesignReferenceUnreachableError({ url, reason: detail, timeoutMs });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async function visit(page: ShotPage, input: CaptureInput, scheme: DesignScheme): Promise<void> {
|
|
99
|
+
await page.colorScheme(scheme);
|
|
100
|
+
try {
|
|
101
|
+
await page.goto(input.url, { timeout: input.timeoutMs });
|
|
102
|
+
} catch (error) {
|
|
103
|
+
throw navigationError(input.url, error, input.timeoutMs);
|
|
104
|
+
}
|
|
105
|
+
const status = documentStatus(page.network(), page.url());
|
|
106
|
+
if (status !== null && status >= 400) {
|
|
107
|
+
throw new DesignReferenceUnreachableError({
|
|
108
|
+
url: input.url,
|
|
109
|
+
reason: `answered HTTP ${String(status)}`,
|
|
110
|
+
timeoutMs: input.timeoutMs,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const refusedBy = (network: readonly NetworkEntry[]): string[] =>
|
|
116
|
+
network.filter((entry) => entry.refused !== undefined).map((entry) => hostOf(entry.url));
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The capture's clip: the viewport's width (a reference photographed at 390 is 390 wide, whatever
|
|
120
|
+
* overflows sideways) and the document's height up to `VIEWPORT_MAX` — Chrome's texture limit, past
|
|
121
|
+
* which a capture is tiles nobody painted, and a page that reports a million pixels of height is
|
|
122
|
+
* a memory bomb, not a reference. The size is page-reported, so it is clamped, never trusted.
|
|
123
|
+
*/
|
|
124
|
+
async function captureClip(page: ShotPage, viewport: ShotViewport): Promise<CaptureClip> {
|
|
125
|
+
const reported = await page
|
|
126
|
+
.evaluate('document.documentElement.scrollHeight')
|
|
127
|
+
.catch(() => viewport.height);
|
|
128
|
+
const height = typeof reported === 'number' && Number.isFinite(reported) ? reported : 0;
|
|
129
|
+
return {
|
|
130
|
+
x: 0,
|
|
131
|
+
y: 0,
|
|
132
|
+
width: viewport.width,
|
|
133
|
+
height: Math.min(VIEWPORT_MAX, Math.max(viewport.height, Math.ceil(height))),
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** Every page-supplied URL is reported as its origin and a hash: its path is the page's text. */
|
|
138
|
+
export const pageRef = (url: string): string => {
|
|
139
|
+
try {
|
|
140
|
+
return `${new URL(url).origin}#${hash8(url)}`;
|
|
141
|
+
} catch {
|
|
142
|
+
return `#${hash8(url)}`;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
export async function captureReference(input: CaptureInput): Promise<Capture> {
|
|
147
|
+
const { signal } = input;
|
|
148
|
+
const refused: string[] = [];
|
|
149
|
+
const unresolved: string[] = [];
|
|
150
|
+
const dialScreen = {
|
|
151
|
+
screen: browserDialScreen(input.policy),
|
|
152
|
+
refused: (url: string, reason: DialRefusal) =>
|
|
153
|
+
(reason === 'private' ? refused : unresolved).push(hostOf(url)),
|
|
154
|
+
};
|
|
155
|
+
const aborted = (): DesignAbortedError => new DesignAbortedError({ url: input.url });
|
|
156
|
+
// A function, not a read: the flag flips while the awaits below are pending.
|
|
157
|
+
const isAborted = (): boolean => signal?.aborted === true;
|
|
158
|
+
const perScheme = new Map<DesignScheme, Extraction[]>(
|
|
159
|
+
DESIGN_SCHEMES.map((scheme) => [scheme, []]),
|
|
160
|
+
);
|
|
161
|
+
const of = (scheme: DesignScheme): Extraction[] => perScheme.get(scheme) ?? [];
|
|
162
|
+
const shots: string[] = [];
|
|
163
|
+
let finalUrl = input.url;
|
|
164
|
+
mkdirSync(input.dir, { recursive: true });
|
|
165
|
+
for (const viewport of input.viewports) {
|
|
166
|
+
// Checked before every launch: a cancelled call must not keep starting browsers.
|
|
167
|
+
if (isAborted()) throw aborted();
|
|
168
|
+
const driver = await input.driverFor(viewport, dialScreen);
|
|
169
|
+
const session = await driver.open({
|
|
170
|
+
name: 'x design research',
|
|
171
|
+
rules: { allowHosts: input.policy.allowHosts },
|
|
172
|
+
clock: systemClock,
|
|
173
|
+
timeoutMs: input.timeoutMs,
|
|
174
|
+
viewport,
|
|
175
|
+
});
|
|
176
|
+
// An abort mid-capture ends the browser at once; the pending CDP call then fails and is
|
|
177
|
+
// reported as the abort it is, never as an unreachable page.
|
|
178
|
+
const stop = (): void => void session.close();
|
|
179
|
+
signal?.addEventListener('abort', stop, { once: true });
|
|
180
|
+
try {
|
|
181
|
+
await session.page.prepare(DESIGN_PREPARE);
|
|
182
|
+
for (const scheme of DESIGN_SCHEMES) {
|
|
183
|
+
await visit(session.page, input, scheme);
|
|
184
|
+
finalUrl = session.page.url();
|
|
185
|
+
of(scheme).push(await extractDesign(session.page));
|
|
186
|
+
const clip = await captureClip(session.page, viewport);
|
|
187
|
+
const bytes = await session.page.screenshot({ clip });
|
|
188
|
+
if (isAborted()) throw aborted();
|
|
189
|
+
const file = join(input.dir, referenceShotName(viewport.width, scheme));
|
|
190
|
+
await Bun.write(file, bytes);
|
|
191
|
+
shots.push(file);
|
|
192
|
+
}
|
|
193
|
+
refused.push(...refusedBy(session.page.network()));
|
|
194
|
+
} catch (error) {
|
|
195
|
+
throw isAborted() ? aborted() : error;
|
|
196
|
+
} finally {
|
|
197
|
+
signal?.removeEventListener('abort', stop);
|
|
198
|
+
await session.close();
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
const hosts = (list: readonly string[]) =>
|
|
202
|
+
[...new Set(list.filter((host) => host !== ''))].sort();
|
|
203
|
+
return {
|
|
204
|
+
finalUrl: pageRef(finalUrl),
|
|
205
|
+
byScheme: { light: mergeExtractions(of('light')), dark: mergeExtractions(of('dark')) },
|
|
206
|
+
shots,
|
|
207
|
+
refusedHosts: hosts(refused),
|
|
208
|
+
unresolvedHosts: hosts(unresolved),
|
|
209
|
+
};
|
|
210
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// The two ways `x design research` refuses, beside their throwers. Codes and titles are registered
|
|
2
|
+
// in `error-codes.ts`, the runnable line per code in `mcp-errors.ts`.
|
|
3
|
+
|
|
4
|
+
import { renderCauseValue, renderFixShellArg, UltimateError } from '@ultimat3/core';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* A reference URL — typed, followed, or reached by the page itself as a redirect — that is not
|
|
8
|
+
* http(s) or lands inside the network. `reason` is this package's own text, never page content.
|
|
9
|
+
*/
|
|
10
|
+
export class DesignUrlRefusedError extends UltimateError {
|
|
11
|
+
constructor(input: { readonly url: string; readonly reason: string }) {
|
|
12
|
+
super({
|
|
13
|
+
code: 'X_DESIGN_URL_REFUSED',
|
|
14
|
+
cause: `${renderCauseValue(input.url)} ${input.reason}: a reference is a public web page, and a headless browser pointed inside the network is an SSRF`,
|
|
15
|
+
fix: 'x design research https://<public-host>/<path> # a public http(s) page; private, loopback and link-local addresses are refused for every request the page makes',
|
|
16
|
+
meta: { url: input.url },
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** The navigation failed or did not finish: a network error, a DNS miss, a 4xx/5xx, a timeout. */
|
|
22
|
+
export class DesignReferenceUnreachableError extends UltimateError {
|
|
23
|
+
constructor(input: {
|
|
24
|
+
readonly url: string;
|
|
25
|
+
readonly reason: string;
|
|
26
|
+
readonly timeoutMs: number;
|
|
27
|
+
}) {
|
|
28
|
+
super({
|
|
29
|
+
code: 'X_DESIGN_REFERENCE_UNREACHABLE',
|
|
30
|
+
cause: `${renderCauseValue(input.url)} could not be researched: ${input.reason}`,
|
|
31
|
+
fix: `x design research ${renderFixShellArg(input.url, '<url>')} --timeout ${renderFixShellArg(String(input.timeoutMs * 2), '<ms>')} # or drop the URL from the list`,
|
|
32
|
+
meta: { url: input.url, timeoutMs: input.timeoutMs },
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The caller went away (`ui.research` cancelled, the CLI interrupted). Core's `X_ABORTED`, as
|
|
39
|
+
* `throwIfAborted` raises it: the run stops launching browsers and publishes nothing half-done.
|
|
40
|
+
*/
|
|
41
|
+
export class DesignAbortedError extends UltimateError {
|
|
42
|
+
constructor(input: { readonly url: string }) {
|
|
43
|
+
super({
|
|
44
|
+
code: 'X_ABORTED',
|
|
45
|
+
cause: `x design research was cancelled while researching ${renderCauseValue(input.url)}; nothing from that reference was published`,
|
|
46
|
+
fix: `x design research ${renderFixShellArg(input.url, '<url>')} --json # run it again when you still want it`,
|
|
47
|
+
meta: { url: input.url },
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Where `x design research` writes, named once: `x shot --against` and `ui.research` read the same
|
|
2
|
+
// directory and the same file names, and a second spelling of either is a reference nobody finds.
|
|
3
|
+
|
|
4
|
+
// why: Bun exposes no path-join primitive.
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import type { ShotViewport } from './shot-viewport';
|
|
7
|
+
|
|
8
|
+
/** Under `.x/`, which every scaffold ignores: third-party pixels are never committed. */
|
|
9
|
+
export const DESIGN_DIR = join('.x', 'design');
|
|
10
|
+
|
|
11
|
+
export const DESIGN_SCHEMES = ['light', 'dark'] as const;
|
|
12
|
+
export type DesignScheme = (typeof DESIGN_SCHEMES)[number];
|
|
13
|
+
|
|
14
|
+
/** A phone and a desktop: the two widths a reference is photographed at unless `--viewport` says. */
|
|
15
|
+
export const DESIGN_VIEWPORTS: readonly ShotViewport[] = [
|
|
16
|
+
{ width: 390, height: 844 },
|
|
17
|
+
{ width: 1440, height: 900 },
|
|
18
|
+
];
|
|
19
|
+
|
|
20
|
+
export const REFERENCE_FILE = 'reference.json';
|
|
21
|
+
export const TOKENS_FILE = 'tokens.proposal.json';
|
|
22
|
+
export const MOTION_MAP_FILE = 'motion-map.json';
|
|
23
|
+
export const SOURCES_FILE = 'sources.json';
|
|
24
|
+
|
|
25
|
+
/** `shot-390-light.png`: keyed by width and scheme, the pair `x shot --against` matches on. */
|
|
26
|
+
export const referenceShotName = (width: number, scheme: DesignScheme): string =>
|
|
27
|
+
`shot-${String(width)}-${scheme}.png`;
|
|
28
|
+
|
|
29
|
+
export const REFERENCE_SHOT_PATTERN = /^shot-(\d+)-(light|dark)\.png$/;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* One directory per reference URL: host and path, lower-case, every other run of characters a
|
|
33
|
+
* dash, at most 80 — readable in a listing and safe on every filesystem. The query is dropped: a
|
|
34
|
+
* catalogue's `?tab=` is the same page to a designer, and a slug carrying it is a path an agent
|
|
35
|
+
* cannot guess.
|
|
36
|
+
*/
|
|
37
|
+
export function designSlug(url: string): string {
|
|
38
|
+
const parsed = new URL(url);
|
|
39
|
+
const raw = `${parsed.hostname.replace(/^www\./, '')}${parsed.pathname}`;
|
|
40
|
+
const slug = raw
|
|
41
|
+
.toLowerCase()
|
|
42
|
+
.replace(/[^a-z0-9]+/g, '-')
|
|
43
|
+
.replace(/^-+|-+$/g, '')
|
|
44
|
+
.slice(0, 80)
|
|
45
|
+
.replace(/-+$/, '');
|
|
46
|
+
return slug === '' ? 'reference' : slug;
|
|
47
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
// A reference directory appears WHOLE or not at all: built in `<dir>.tmp-<pid>-<id>`, swapped in
|
|
2
|
+
// only once complete, runs into one directory in this process taking turns.
|
|
3
|
+
//
|
|
4
|
+
// `x shot --against` diffs whatever shots a `<slug>/` holds, so a slug mixing two runs — a cancelled
|
|
5
|
+
// one beside its retry, a failed or narrower rerun over an older one — is a comparison against a
|
|
6
|
+
// reference that never existed (`repro-archive-write.ts`'s rule).
|
|
7
|
+
|
|
8
|
+
// why: Bun has no directory rename or recursive remove.
|
|
9
|
+
import { mkdir, rename, rm } from 'node:fs/promises';
|
|
10
|
+
|
|
11
|
+
/** The tail of the last run per directory; a run waits for it, failed or not. */
|
|
12
|
+
const queues = new Map<string, Promise<unknown>>();
|
|
13
|
+
|
|
14
|
+
const scratchName = (dir: string, kind: string): string =>
|
|
15
|
+
`${dir}.${kind}-${String(process.pid)}-${crypto.randomUUID().slice(0, 8)}`;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Two renames, because a directory is never renamed over a non-empty one: the old run steps aside,
|
|
19
|
+
* the new one steps in, the old one is removed. A crash between the two leaves the old run under a
|
|
20
|
+
* `.old-` name, never a half-written `<dir>`.
|
|
21
|
+
*/
|
|
22
|
+
async function swapIn(building: string, dir: string): Promise<void> {
|
|
23
|
+
const old = scratchName(dir, 'old');
|
|
24
|
+
const moved = await rename(dir, old).then(
|
|
25
|
+
() => true,
|
|
26
|
+
(error: unknown) => {
|
|
27
|
+
if ((error as { code?: unknown }).code === 'ENOENT') return false;
|
|
28
|
+
throw error;
|
|
29
|
+
},
|
|
30
|
+
);
|
|
31
|
+
await rename(building, dir);
|
|
32
|
+
if (moved) await rm(old, { recursive: true, force: true });
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async function buildAndSwap<T>(dir: string, build: (building: string) => Promise<T>): Promise<T> {
|
|
36
|
+
const building = scratchName(dir, 'tmp');
|
|
37
|
+
try {
|
|
38
|
+
await mkdir(building, { recursive: true });
|
|
39
|
+
const result = await build(building);
|
|
40
|
+
await swapIn(building, dir);
|
|
41
|
+
return result;
|
|
42
|
+
} finally {
|
|
43
|
+
await rm(building, { recursive: true, force: true });
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** `build` writes into a fresh scratch directory; `dir` becomes it only when `build` resolves. */
|
|
48
|
+
export function publishDirectory<T>(
|
|
49
|
+
dir: string,
|
|
50
|
+
build: (building: string) => Promise<T>,
|
|
51
|
+
): Promise<T> {
|
|
52
|
+
const previous = queues.get(dir) ?? Promise.resolve();
|
|
53
|
+
const run = previous.then(
|
|
54
|
+
() => buildAndSwap(dir, build),
|
|
55
|
+
() => buildAndSwap(dir, build),
|
|
56
|
+
);
|
|
57
|
+
const tail = run.catch(() => undefined);
|
|
58
|
+
queues.set(dir, tail);
|
|
59
|
+
// Forgotten once nothing is queued behind it: the map holds live work, not every slug ever seen.
|
|
60
|
+
void tail.then(() => {
|
|
61
|
+
if (queues.get(dir) === tail) queues.delete(dir);
|
|
62
|
+
});
|
|
63
|
+
return run;
|
|
64
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// `x design research` and `ui.research`, one body: each reference screened, captured, mapped and
|
|
2
|
+
// published whole as its five artefacts under `<out>/<slug>/`, then up to `follow` of its links.
|
|
3
|
+
//
|
|
4
|
+
// The browser and the theme host are arguments, so a test runs the whole thing with a fake driver —
|
|
5
|
+
// and a fixture server reached through `trustedHosts`, which only a harness can pass.
|
|
6
|
+
|
|
7
|
+
// why: Bun exposes no path-join primitive.
|
|
8
|
+
import { join } from 'node:path';
|
|
9
|
+
import { isUltimateError } from '@ultimat3/core';
|
|
10
|
+
import type { JsonValue } from '@ultimat3/schema';
|
|
11
|
+
import type { DesignDriverFor } from './cmd-design-capture';
|
|
12
|
+
import { captureReference, pageRef } from './cmd-design-capture';
|
|
13
|
+
import { DesignAbortedError } from './cmd-design-errors';
|
|
14
|
+
import {
|
|
15
|
+
designSlug,
|
|
16
|
+
MOTION_MAP_FILE,
|
|
17
|
+
REFERENCE_FILE,
|
|
18
|
+
SOURCES_FILE,
|
|
19
|
+
TOKENS_FILE,
|
|
20
|
+
} from './cmd-design-paths';
|
|
21
|
+
import { publishDirectory } from './cmd-design-publish';
|
|
22
|
+
import type { ThemeHost } from './cmd-design-theme';
|
|
23
|
+
import { acceptedProposal } from './cmd-design-theme';
|
|
24
|
+
import type { DesignHostPolicy } from './cmd-design-url';
|
|
25
|
+
import { followTargets, readReferenceUrl, screenReference } from './cmd-design-url';
|
|
26
|
+
import { mapDesign } from './design-map';
|
|
27
|
+
import { postureFor } from './messages-design';
|
|
28
|
+
import { hash8 } from './shot-diff';
|
|
29
|
+
import type { ShotViewport } from './shot-viewport';
|
|
30
|
+
|
|
31
|
+
export interface ResearchOptions {
|
|
32
|
+
readonly urls: readonly string[];
|
|
33
|
+
/** Links visited per typed reference, same origin or `allowHosts`. */
|
|
34
|
+
readonly follow: number;
|
|
35
|
+
/** Absolute. */
|
|
36
|
+
readonly outDir: string;
|
|
37
|
+
readonly viewports: readonly ShotViewport[];
|
|
38
|
+
readonly allowHosts: readonly string[];
|
|
39
|
+
readonly timeoutMs: number;
|
|
40
|
+
readonly policy: DesignHostPolicy;
|
|
41
|
+
readonly driverFor: DesignDriverFor;
|
|
42
|
+
readonly themeHost: ThemeHost | undefined;
|
|
43
|
+
readonly now: () => Date;
|
|
44
|
+
/** The caller's cancellation: checked before every reference and every browser launch. */
|
|
45
|
+
readonly signal?: AbortSignal | undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export interface ResearchedReference {
|
|
49
|
+
/** A typed URL as typed; a followed one as `pageRef` — its path is the page's text. */
|
|
50
|
+
readonly url: string;
|
|
51
|
+
/** Always `pageRef`: `location.href` is page-settable. */
|
|
52
|
+
readonly finalUrl: string;
|
|
53
|
+
readonly dir: string;
|
|
54
|
+
readonly followedFrom: string | null;
|
|
55
|
+
readonly shots: readonly string[];
|
|
56
|
+
readonly files: Readonly<Record<'reference' | 'tokens' | 'motionMap' | 'sources', string>>;
|
|
57
|
+
readonly colors: number;
|
|
58
|
+
readonly animations: number;
|
|
59
|
+
readonly refused: number;
|
|
60
|
+
/** Whether `defineTheme` itself accepted `tokens.proposal.json`. */
|
|
61
|
+
readonly validated: boolean;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** A `--follow` link that failed: recorded, and the run went on. Code only — no page text. */
|
|
65
|
+
export interface SkippedReference {
|
|
66
|
+
readonly url: string;
|
|
67
|
+
readonly followedFrom: string;
|
|
68
|
+
readonly code: string;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface ResearchOutcome {
|
|
72
|
+
readonly references: readonly ResearchedReference[];
|
|
73
|
+
readonly skipped: readonly SkippedReference[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const json = async (file: string, value: unknown): Promise<void> => {
|
|
77
|
+
await Bun.write(file, `${JSON.stringify(value, null, 2)}\n`);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
interface Visit {
|
|
81
|
+
/** What the browser navigates to. */
|
|
82
|
+
readonly url: string;
|
|
83
|
+
/** What files and answers name it by. */
|
|
84
|
+
readonly shown: string;
|
|
85
|
+
readonly slug: string;
|
|
86
|
+
readonly followedFrom: string | null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function researchOne(
|
|
90
|
+
visit: Visit,
|
|
91
|
+
options: ResearchOptions,
|
|
92
|
+
): Promise<{ readonly reference: ResearchedReference; readonly links: readonly string[] }> {
|
|
93
|
+
if (options.signal?.aborted === true) throw new DesignAbortedError({ url: visit.shown });
|
|
94
|
+
await screenReference(visit.url, options.policy);
|
|
95
|
+
const dir = join(options.outDir, visit.slug);
|
|
96
|
+
const at = (name: string) => join(dir, name);
|
|
97
|
+
return publishDirectory(dir, async (building) => {
|
|
98
|
+
const capture = await captureReference({
|
|
99
|
+
url: visit.url,
|
|
100
|
+
dir: building,
|
|
101
|
+
viewports: options.viewports,
|
|
102
|
+
timeoutMs: options.timeoutMs,
|
|
103
|
+
policy: options.policy,
|
|
104
|
+
driverFor: options.driverFor,
|
|
105
|
+
signal: options.signal,
|
|
106
|
+
});
|
|
107
|
+
const mapped = mapDesign(capture.byScheme, options.themeHost?.tables);
|
|
108
|
+
const accepted = acceptedProposal(mapped.proposal, options.themeHost);
|
|
109
|
+
const light = capture.byScheme.light;
|
|
110
|
+
const researchedAt = options.now().toISOString();
|
|
111
|
+
// Measured values only: channels, numbers, CSS keywords, bounded family names, hostnames.
|
|
112
|
+
await json(join(building, REFERENCE_FILE), {
|
|
113
|
+
url: visit.shown,
|
|
114
|
+
finalUrl: capture.finalUrl,
|
|
115
|
+
researchedAt,
|
|
116
|
+
viewports: options.viewports,
|
|
117
|
+
palette: mapped.palette,
|
|
118
|
+
fonts: {
|
|
119
|
+
families: [...new Set(light.fonts.map((font) => font.family))],
|
|
120
|
+
scale: [...new Set(light.fonts.map((font) => font.sizePx))].sort((a, b) => a - b),
|
|
121
|
+
usage: light.fonts,
|
|
122
|
+
},
|
|
123
|
+
spacing: [...light.spacing].sort((a, b) => a.px - b.px),
|
|
124
|
+
radii: light.radii,
|
|
125
|
+
shadows: light.shadows,
|
|
126
|
+
backdropFilter: light.backdrop,
|
|
127
|
+
canvases: light.canvases,
|
|
128
|
+
motion: light.motion,
|
|
129
|
+
refused: {
|
|
130
|
+
count: capture.refusedHosts.length,
|
|
131
|
+
hosts: capture.refusedHosts,
|
|
132
|
+
unresolved: capture.unresolvedHosts,
|
|
133
|
+
},
|
|
134
|
+
tokens: {
|
|
135
|
+
validated: accepted.validated,
|
|
136
|
+
coloursProposed: accepted.proposal.colors !== undefined,
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
await json(join(building, TOKENS_FILE), accepted.proposal);
|
|
140
|
+
await json(join(building, MOTION_MAP_FILE), { url: visit.shown, entries: mapped.motionMap });
|
|
141
|
+
const { source, posture } = postureFor(visit.url);
|
|
142
|
+
await json(join(building, SOURCES_FILE), {
|
|
143
|
+
url: visit.shown,
|
|
144
|
+
finalUrl: capture.finalUrl,
|
|
145
|
+
followedFrom: visit.followedFrom,
|
|
146
|
+
researchedAt,
|
|
147
|
+
source,
|
|
148
|
+
posture,
|
|
149
|
+
rule: 'ideas and techniques only: never copy code from a reference into the app',
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
reference: {
|
|
153
|
+
url: visit.shown,
|
|
154
|
+
finalUrl: capture.finalUrl,
|
|
155
|
+
dir,
|
|
156
|
+
followedFrom: visit.followedFrom,
|
|
157
|
+
// Named where they will be once published, not where they were built.
|
|
158
|
+
shots: capture.shots.map((file) => at(file.slice(building.length + 1))),
|
|
159
|
+
files: {
|
|
160
|
+
reference: at(REFERENCE_FILE),
|
|
161
|
+
tokens: at(TOKENS_FILE),
|
|
162
|
+
motionMap: at(MOTION_MAP_FILE),
|
|
163
|
+
sources: at(SOURCES_FILE),
|
|
164
|
+
},
|
|
165
|
+
colors: mapped.palette.light.length,
|
|
166
|
+
animations: light.motion.length,
|
|
167
|
+
refused: capture.refusedHosts.length,
|
|
168
|
+
validated: accepted.validated,
|
|
169
|
+
},
|
|
170
|
+
links: light.links,
|
|
171
|
+
};
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** A typed URL's slug, made unique against the ones this run already wrote. */
|
|
176
|
+
const uniqueSlug = (url: string, taken: ReadonlySet<string>): string => {
|
|
177
|
+
const slug = designSlug(url);
|
|
178
|
+
return taken.has(slug) ? `${slug}-${hash8(url)}` : slug;
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Every typed reference in order, each followed by up to `follow` of its own links. A typed URL
|
|
183
|
+
* fails the run; a followed link that fails is recorded in `skipped` and the run goes on — one
|
|
184
|
+
* broken catalogue entry is not a reason to throw away the rest. Cancellation always propagates.
|
|
185
|
+
*/
|
|
186
|
+
export async function researchDesign(options: ResearchOptions): Promise<ResearchOutcome> {
|
|
187
|
+
// Every typed URL judged before the first browser: a typo in the third must not cost two captures.
|
|
188
|
+
const urls = options.urls.map(readReferenceUrl);
|
|
189
|
+
const references: ResearchedReference[] = [];
|
|
190
|
+
const skipped: SkippedReference[] = [];
|
|
191
|
+
const taken = new Set<string>();
|
|
192
|
+
for (const url of urls) {
|
|
193
|
+
const slug = uniqueSlug(url, taken);
|
|
194
|
+
taken.add(slug);
|
|
195
|
+
const first = await researchOne({ url, shown: url, slug, followedFrom: null }, options);
|
|
196
|
+
references.push(first.reference);
|
|
197
|
+
for (const link of followTargets(url, first.links, options.allowHosts, options.follow)) {
|
|
198
|
+
// A followed page's directory never carries its path: the path is the page's text.
|
|
199
|
+
const followed = { url: link, shown: pageRef(link), followedFrom: url };
|
|
200
|
+
const linkSlug = `${slug}--${hash8(link)}`;
|
|
201
|
+
if (taken.has(linkSlug)) continue;
|
|
202
|
+
taken.add(linkSlug);
|
|
203
|
+
try {
|
|
204
|
+
references.push((await researchOne({ ...followed, slug: linkSlug }, options)).reference);
|
|
205
|
+
} catch (error) {
|
|
206
|
+
if (!isUltimateError(error) || error.code === 'X_ABORTED') throw error;
|
|
207
|
+
skipped.push({ url: followed.shown, followedFrom: url, code: error.code });
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return { references, skipped };
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/** The `--json` / `ui.research` answer. */
|
|
215
|
+
export const researchJson = (outcome: ResearchOutcome): JsonValue => ({
|
|
216
|
+
references: outcome.references.map((reference) => ({
|
|
217
|
+
url: reference.url,
|
|
218
|
+
finalUrl: reference.finalUrl,
|
|
219
|
+
dir: reference.dir,
|
|
220
|
+
followedFrom: reference.followedFrom,
|
|
221
|
+
shots: [...reference.shots],
|
|
222
|
+
files: { ...reference.files },
|
|
223
|
+
colors: reference.colors,
|
|
224
|
+
animations: reference.animations,
|
|
225
|
+
refused: reference.refused,
|
|
226
|
+
validated: reference.validated,
|
|
227
|
+
})),
|
|
228
|
+
skipped: outcome.skipped.map((entry) => ({ ...entry })),
|
|
229
|
+
});
|