@ultimat3/cli 31.52.0 → 31.53.1
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/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/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-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/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/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-files.ts +31 -1
- package/src/guards-shipped-names.ts +5 -0
- package/src/kit/agent-audit.ts +56 -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 +166 -0
- package/src/kit/skill-planx.ts +140 -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/messages-design.ts +104 -0
- package/src/messages-upgrade.ts +9 -0
- package/src/messages.ts +2 -0
- package/src/registry.ts +4 -0
- package/src/shot-diff.ts +96 -0
- package/src/shot-gpu.ts +17 -5
- 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 +10 -0
- package/src/templates/index.ts +1 -2
- package/src/templates/island.ts +55 -8
- package/src/templates/kit-released-forms.ts +64 -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-guards.ts +31 -2
- 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/saas.ts +4 -0
- 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/workspace-checks.ts +3 -3
- package/wiki/Agents.md +33 -1
- package/wiki/CLI-Reference-Tools.md +24 -3
- package/wiki/CLI-Reference.md +4 -2
- package/wiki/Design-Research.md +96 -0
- package/wiki/Effects.md +83 -0
- package/wiki/FAQ.md +1 -1
- package/wiki/Getting-Started.md +1 -1
- package/wiki/Home.md +2 -2
- package/wiki/Known-Gaps.md +3 -2
- package/wiki/MCP-And-AI.md +4 -0
- package/wiki/Motion.md +85 -0
- package/wiki/Project-Layout.md +1 -1
- package/wiki/Tutorial-02-First-Feature.md +1 -1
- package/wiki/UI-Components.md +2 -0
- package/wiki/Upgrading.md +4 -2
- package/src/templates/scaffold-claude-agents.ts +0 -161
- package/src/templates/scaffold-claude-commands.ts +0 -239
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// `x design`'s declaration, apart from its body: the parser, `x help` and the `errors` step read it
|
|
2
|
+
// without loading `cmd-design.ts`, which `registry.ts` imports only when the command runs.
|
|
3
|
+
|
|
4
|
+
import type { CommandSpec } from './parse';
|
|
5
|
+
|
|
6
|
+
export const DESIGN_SUBCOMMANDS = ['research'] as const;
|
|
7
|
+
|
|
8
|
+
export const designSpec: CommandSpec = {
|
|
9
|
+
name: 'design',
|
|
10
|
+
summary:
|
|
11
|
+
'research a reference site: shots, measured palette/type/spacing/motion, a defineTheme() proposal and a motion map',
|
|
12
|
+
usage:
|
|
13
|
+
'x design research <url…> [--follow <n>] [--out .x/design] [--viewport 390x844,1440x900] [--allow-hosts <h,…>] [--timeout <ms>] [--json] · x design research --list',
|
|
14
|
+
// No default: `research` drives a browser at the web, which is typed or not run.
|
|
15
|
+
subcommands: [...DESIGN_SUBCOMMANDS],
|
|
16
|
+
flags: [
|
|
17
|
+
{
|
|
18
|
+
name: 'follow',
|
|
19
|
+
type: 'string',
|
|
20
|
+
summary:
|
|
21
|
+
'also research up to n links of each reference: same origin, or a --allow-hosts host',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
name: 'out',
|
|
25
|
+
type: 'string',
|
|
26
|
+
summary: 'where each reference directory is written (default .x/design, never committed)',
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: 'viewport',
|
|
30
|
+
type: 'string',
|
|
31
|
+
summary:
|
|
32
|
+
'<w>x<h>[,<w>x<h>] — the sizes each reference is photographed at (default 390x844,1440x900)',
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
name: 'allow-hosts',
|
|
36
|
+
type: 'string',
|
|
37
|
+
summary:
|
|
38
|
+
'extra public hosts --follow may visit; never widens what the browser may reach (private addresses stay refused)',
|
|
39
|
+
},
|
|
40
|
+
{ name: 'timeout', type: 'string', summary: 'ms one reference navigation may take' },
|
|
41
|
+
{
|
|
42
|
+
name: 'list',
|
|
43
|
+
type: 'boolean',
|
|
44
|
+
summary: 'the default reference catalogues and the licence posture each is held to',
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// `@ultimat3/ui`'s palette tables and `defineTheme`, reached at run time. The CLI does not depend on
|
|
2
|
+
// `@ultimat3/ui` (`error-catalog.ts` names it an optional host for the same reason), and an app that
|
|
3
|
+
// researches a design has it installed: resolved, the proposal's colours are contrast-checked and
|
|
4
|
+
// then handed to `defineTheme` itself; unresolved, the proposal carries no colours at all.
|
|
5
|
+
|
|
6
|
+
import type { DesignProposal, ThemeTables } from './design-map';
|
|
7
|
+
|
|
8
|
+
export interface ThemeHost {
|
|
9
|
+
readonly tables: ThemeTables;
|
|
10
|
+
/** `defineTheme`, which throws on a proposal it refuses. */
|
|
11
|
+
readonly defineTheme: (input: DesignProposal) => unknown;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const record = (value: unknown): Record<string, unknown> | undefined =>
|
|
15
|
+
typeof value === 'object' && value !== null ? (value as Record<string, unknown>) : undefined;
|
|
16
|
+
|
|
17
|
+
const stringTable = (value: unknown): Record<string, string> | undefined => {
|
|
18
|
+
const table = record(value);
|
|
19
|
+
if (table === undefined) return undefined;
|
|
20
|
+
return Object.values(table).every((entry) => typeof entry === 'string')
|
|
21
|
+
? (table as Record<string, string>)
|
|
22
|
+
: undefined;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const pairList = (value: unknown): ThemeTables['pairs'] =>
|
|
26
|
+
(Array.isArray(value) ? value : []).flatMap((entry: unknown) => {
|
|
27
|
+
const pair = record(entry);
|
|
28
|
+
const fg = pair?.['fg'];
|
|
29
|
+
const bg = pair?.['bg'];
|
|
30
|
+
const minimum = pair?.['minimum'];
|
|
31
|
+
return typeof fg === 'string' && typeof bg === 'string' && typeof minimum === 'number'
|
|
32
|
+
? [{ fg, bg, minimum }]
|
|
33
|
+
: [];
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
/** The module's exports read as `unknown` and checked: a version that renamed one is no host. */
|
|
37
|
+
export function themeHostOf(module: unknown): ThemeHost | undefined {
|
|
38
|
+
const ui = record(module);
|
|
39
|
+
const tokens = record(ui?.['colorTokens']);
|
|
40
|
+
const light = stringTable(tokens?.['light']);
|
|
41
|
+
const dark = stringTable(tokens?.['dark']);
|
|
42
|
+
const aliases = stringTable(ui?.['COLOR_ALIASES']);
|
|
43
|
+
const contrast = ui?.['contrastRatio'];
|
|
44
|
+
const define = ui?.['defineTheme'];
|
|
45
|
+
if (
|
|
46
|
+
light === undefined ||
|
|
47
|
+
dark === undefined ||
|
|
48
|
+
aliases === undefined ||
|
|
49
|
+
typeof contrast !== 'function' ||
|
|
50
|
+
typeof define !== 'function'
|
|
51
|
+
) {
|
|
52
|
+
return undefined;
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
tables: {
|
|
56
|
+
colors: { light, dark },
|
|
57
|
+
aliases,
|
|
58
|
+
pairs: [...pairList(ui?.['CONTRAST_PAIRS']), ...pairList(ui?.['ALIAS_CONTRAST_PAIRS'])],
|
|
59
|
+
contrast: (a, b) => Number(contrast(a, b)),
|
|
60
|
+
},
|
|
61
|
+
defineTheme: (input) => define(input),
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The specifier is a value, not a literal: `tsc` must not resolve a package the CLI never declares. */
|
|
66
|
+
const UI_SPECIFIER = '@ultimat3/ui';
|
|
67
|
+
|
|
68
|
+
export async function loadThemeHost(
|
|
69
|
+
load: (specifier: string) => Promise<unknown> = (specifier) => import(specifier),
|
|
70
|
+
): Promise<ThemeHost | undefined> {
|
|
71
|
+
try {
|
|
72
|
+
return themeHostOf(await load(UI_SPECIFIER));
|
|
73
|
+
} catch {
|
|
74
|
+
// Not installed beside the CLI: the documented degraded path, reported in reference.json.
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* The proposal `defineTheme` accepts, by `defineTheme`'s own verdict: as mapped, else without its
|
|
81
|
+
* colours (a palette rule this CLI predates), else `{}` marked unvalidated — never a proposal that
|
|
82
|
+
* would not boot, and never a thrown run.
|
|
83
|
+
*/
|
|
84
|
+
export function acceptedProposal(
|
|
85
|
+
proposal: DesignProposal,
|
|
86
|
+
host: ThemeHost | undefined,
|
|
87
|
+
): {
|
|
88
|
+
readonly proposal: DesignProposal;
|
|
89
|
+
readonly validated: boolean;
|
|
90
|
+
} {
|
|
91
|
+
if (host === undefined) return { proposal, validated: false };
|
|
92
|
+
if (accepts(host, proposal)) return { proposal, validated: true };
|
|
93
|
+
const { colors: _dropped, ...rest } = proposal;
|
|
94
|
+
if (accepts(host, rest)) return { proposal: rest, validated: true };
|
|
95
|
+
// A rule this CLI does not know refuses more than colours: an empty proposal is still a
|
|
96
|
+
// `defineTheme` argument, and a research run never dies over a token it could not validate.
|
|
97
|
+
return { proposal: {}, validated: false };
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const accepts = (host: ThemeHost, proposal: DesignProposal): boolean => {
|
|
101
|
+
try {
|
|
102
|
+
host.defineTheme(proposal);
|
|
103
|
+
return true;
|
|
104
|
+
} catch {
|
|
105
|
+
return false;
|
|
106
|
+
}
|
|
107
|
+
};
|