@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,201 @@
|
|
|
1
|
+
// Which URLs `x design research` may reach: the typed reference, every link `--follow` visits, and —
|
|
2
|
+
// through the CDP driver's interception — every navigation, redirect and subresource the page asks
|
|
3
|
+
// for. One policy for all of them: public hosts only. The screen is core's (`hostDecision`'s address
|
|
4
|
+
// floor, `screenDial`'s resolve-and-classify), the one `@ultimat3/scraping`'s browser leg uses too.
|
|
5
|
+
|
|
6
|
+
import type { HostRule } from '@ultimat3/core';
|
|
7
|
+
import { ANY_HOST, classifyAddress, hostDecision, hostMatches } from '@ultimat3/core';
|
|
8
|
+
import type { DialResolve } from '@ultimat3/core/outbound';
|
|
9
|
+
import { resolveDialHost, screenDial } from '@ultimat3/core/outbound';
|
|
10
|
+
import { DEFAULT_PAGE_TIMEOUT_MS } from './cdp-shot-clock';
|
|
11
|
+
import type { DialRefusal } from './cdp-shot-driver-screen';
|
|
12
|
+
import { DesignReferenceUnreachableError, DesignUrlRefusedError } from './cmd-design-errors';
|
|
13
|
+
import { designSlug } from './cmd-design-paths';
|
|
14
|
+
import { BadFlagError } from './errors';
|
|
15
|
+
|
|
16
|
+
export interface DesignHostPolicy {
|
|
17
|
+
/** `*` plus any harness-trusted host: core's floor keeps the wildcard off every inward literal. */
|
|
18
|
+
readonly allowHosts: readonly HostRule[];
|
|
19
|
+
/** Exact hosts admitted without a resolve — a TEST HARNESS seam, never a flag. */
|
|
20
|
+
readonly trustedHosts: readonly string[];
|
|
21
|
+
readonly resolve: DialResolve;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* `trustedHosts` exists so a fixture server on 127.0.0.1 can be researched in a test: injected by
|
|
26
|
+
* the harness through the run's options, and deliberately absent from the command's flags — a
|
|
27
|
+
* flag that admitted loopback would be the SSRF this policy exists to refuse.
|
|
28
|
+
*/
|
|
29
|
+
export function designHostPolicy(input: {
|
|
30
|
+
readonly resolve?: DialResolve | undefined;
|
|
31
|
+
readonly trustedHosts?: readonly string[] | undefined;
|
|
32
|
+
}): DesignHostPolicy {
|
|
33
|
+
const trustedHosts = input.trustedHosts ?? [];
|
|
34
|
+
return {
|
|
35
|
+
allowHosts: [ANY_HOST, ...trustedHosts],
|
|
36
|
+
trustedHosts,
|
|
37
|
+
resolve: input.resolve ?? resolveDialHost,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** The reference as typed: http(s), no credentials. Anything else is refused by name. */
|
|
42
|
+
export function readReferenceUrl(raw: string): string {
|
|
43
|
+
let parsed: URL;
|
|
44
|
+
try {
|
|
45
|
+
parsed = new URL(raw);
|
|
46
|
+
} catch {
|
|
47
|
+
throw new DesignUrlRefusedError({ url: raw, reason: 'is not an absolute URL' });
|
|
48
|
+
}
|
|
49
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') {
|
|
50
|
+
throw new DesignUrlRefusedError({ url: raw, reason: `is ${parsed.protocol}, not http(s)` });
|
|
51
|
+
}
|
|
52
|
+
if (parsed.username !== '' || parsed.password !== '') {
|
|
53
|
+
throw new DesignUrlRefusedError({
|
|
54
|
+
url: raw,
|
|
55
|
+
reason: 'carries credentials, which would ride every request the page makes',
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
return raw;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const hostnameOf = (url: URL): string => url.hostname.replace(/^\[|\]$/g, '');
|
|
62
|
+
|
|
63
|
+
const isTrusted = (hostname: string, policy: DesignHostPolicy): boolean =>
|
|
64
|
+
policy.trustedHosts.some((rule) => hostMatches(hostname, rule));
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* The typed URL, screened before a browser exists: the address floor, then — for a name — every
|
|
68
|
+
* address it resolves to. A name that does not resolve is unreachable, not refused: nothing about
|
|
69
|
+
* it is inside the network, it is simply not there.
|
|
70
|
+
*/
|
|
71
|
+
export async function screenReference(url: string, policy: DesignHostPolicy): Promise<void> {
|
|
72
|
+
if (!hostDecision(url, policy.allowHosts).allowed) {
|
|
73
|
+
throw new DesignUrlRefusedError({
|
|
74
|
+
url,
|
|
75
|
+
reason: 'names a loopback, private or link-local address',
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
const parsed = new URL(url);
|
|
79
|
+
const hostname = hostnameOf(parsed);
|
|
80
|
+
if (classifyAddress(hostname) !== undefined || isTrusted(hostname, policy)) return;
|
|
81
|
+
const verdict = await screenDial(parsed, { resolve: policy.resolve });
|
|
82
|
+
if ('pin' in verdict) return;
|
|
83
|
+
if ('unresolved' in verdict) {
|
|
84
|
+
throw new DesignReferenceUnreachableError({
|
|
85
|
+
url,
|
|
86
|
+
reason: verdict.unresolved,
|
|
87
|
+
timeoutMs: DEFAULT_PAGE_TIMEOUT_MS,
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
// The class, never the address: core's own rule for a refusal reason.
|
|
91
|
+
throw new DesignUrlRefusedError({ url, reason: `resolves to a ${verdict.refused} address` });
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The schemes the browser dials by name. */
|
|
95
|
+
const DIALLED = new Set(['http:', 'https:', 'ws:', 'wss:']);
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The driver's `dialScreen.screen`: `undefined` when the floor decides alone (a literal, a hostless
|
|
99
|
+
* scheme, a trusted host), else the refusal or `undefined` to release. A DEFINITE answer — every
|
|
100
|
+
* address public, or one not — is memoised per name for the session: a page asks for the same CDN a
|
|
101
|
+
* hundred times. A resolver failure or an empty answer is `unresolved` and asked again next time:
|
|
102
|
+
* a transient SERVFAIL proves nothing about where the name points, so it is never cached, and
|
|
103
|
+
* never reported as private.
|
|
104
|
+
*/
|
|
105
|
+
export function browserDialScreen(
|
|
106
|
+
policy: DesignHostPolicy,
|
|
107
|
+
): (url: string) => Promise<DialRefusal | undefined> | undefined {
|
|
108
|
+
const known = new Map<string, DialRefusal | 'public'>();
|
|
109
|
+
return (url) => {
|
|
110
|
+
let parsed: URL;
|
|
111
|
+
try {
|
|
112
|
+
parsed = new URL(url);
|
|
113
|
+
} catch {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
if (!DIALLED.has(parsed.protocol)) return undefined;
|
|
117
|
+
const hostname = hostnameOf(parsed);
|
|
118
|
+
if (hostname === '' || classifyAddress(hostname) !== undefined) return undefined;
|
|
119
|
+
if (isTrusted(hostname, policy)) return undefined;
|
|
120
|
+
const held = known.get(hostname);
|
|
121
|
+
if (held !== undefined) return Promise.resolve(held === 'public' ? undefined : held);
|
|
122
|
+
return screenDial(parsed, { resolve: policy.resolve }).then(
|
|
123
|
+
(verdict): DialRefusal | undefined => {
|
|
124
|
+
if ('unresolved' in verdict) return 'unresolved';
|
|
125
|
+
known.set(hostname, 'pin' in verdict ? 'public' : 'private');
|
|
126
|
+
return 'pin' in verdict ? undefined : 'private';
|
|
127
|
+
},
|
|
128
|
+
(): DialRefusal => 'unresolved',
|
|
129
|
+
);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* `--allow-hosts`: the hosts `--follow` may visit beyond the reference's own origin. A public name
|
|
135
|
+
* or a `*.` suffix; never `*`, `localhost` or an inward literal — the flag widens what is FOLLOWED,
|
|
136
|
+
* and it can never widen what the browser may reach.
|
|
137
|
+
*/
|
|
138
|
+
export function readDesignAllowHosts(raw: string | undefined): readonly string[] {
|
|
139
|
+
if (raw === undefined) return [];
|
|
140
|
+
return raw.split(',').map((entry) => {
|
|
141
|
+
const host = entry.trim().toLowerCase();
|
|
142
|
+
if (host === '' || host === ANY_HOST) {
|
|
143
|
+
throw new BadFlagError({
|
|
144
|
+
flag: 'allow-hosts',
|
|
145
|
+
command: 'design research',
|
|
146
|
+
reason: host === '' ? 'lists an empty host' : '* would follow every link on the web',
|
|
147
|
+
fix: 'x design research https://example.com/ --follow 5 --allow-hosts docs.example.com',
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
const literal = classifyAddress(host);
|
|
151
|
+
const name = host.replace(/\.$/, '');
|
|
152
|
+
if (
|
|
153
|
+
(literal !== undefined && literal !== 'public') ||
|
|
154
|
+
name === 'localhost' ||
|
|
155
|
+
name.endsWith('.localhost')
|
|
156
|
+
) {
|
|
157
|
+
throw new DesignUrlRefusedError({
|
|
158
|
+
url: host,
|
|
159
|
+
reason: 'names a loopback, private or link-local host',
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return host;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* The links `--follow <n>` visits: same origin as the reference, or a host `--allow-hosts` names;
|
|
168
|
+
* http(s) only, the fragment dropped, a page whose slug is already taken skipped, in page order,
|
|
169
|
+
* at most `n`. Each is screened again before it is visited, exactly like the reference.
|
|
170
|
+
*/
|
|
171
|
+
export function followTargets(
|
|
172
|
+
reference: string,
|
|
173
|
+
links: readonly string[],
|
|
174
|
+
allowHosts: readonly string[],
|
|
175
|
+
n: number,
|
|
176
|
+
): readonly string[] {
|
|
177
|
+
const origin = new URL(reference);
|
|
178
|
+
// Deduped on the DIRECTORY a page is written to, not its href: `/docs/`, `/docs?tab=2` and the
|
|
179
|
+
// reference's own `/docs` share one slug, and a followed page must never overwrite another's.
|
|
180
|
+
const seen = new Set([designSlug(reference)]);
|
|
181
|
+
const out: string[] = [];
|
|
182
|
+
for (const link of links) {
|
|
183
|
+
if (out.length >= n) break;
|
|
184
|
+
let parsed: URL;
|
|
185
|
+
try {
|
|
186
|
+
parsed = new URL(link);
|
|
187
|
+
} catch {
|
|
188
|
+
continue;
|
|
189
|
+
}
|
|
190
|
+
if (parsed.protocol !== 'http:' && parsed.protocol !== 'https:') continue;
|
|
191
|
+
parsed.hash = '';
|
|
192
|
+
const allowed =
|
|
193
|
+
parsed.origin === origin.origin ||
|
|
194
|
+
allowHosts.some((rule) => hostMatches(parsed.hostname, rule));
|
|
195
|
+
const slug = designSlug(parsed.href);
|
|
196
|
+
if (!allowed || seen.has(slug)) continue;
|
|
197
|
+
seen.add(slug);
|
|
198
|
+
out.push(parsed.href);
|
|
199
|
+
}
|
|
200
|
+
return out;
|
|
201
|
+
}
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// `x design research <url…>` — the command: flags read, a reference site measured into tokens,
|
|
2
|
+
// motion calls and effects entries, the result rendered.
|
|
3
|
+
//
|
|
4
|
+
// The mechanism; the `design-research` skill is the procedure that drives it. Never a gate step: it
|
|
5
|
+
// needs a browser and the public web. Everything captured lands in `.x/design/` (ignored):
|
|
6
|
+
// third-party pixels are never committed.
|
|
7
|
+
|
|
8
|
+
// why: Bun exposes no path primitives; `--out` resolves against the caller's cwd.
|
|
9
|
+
import { join, resolve } from 'node:path';
|
|
10
|
+
import { finiteCount } from '@ultimat3/core';
|
|
11
|
+
import type { DialResolve } from '@ultimat3/core/outbound';
|
|
12
|
+
import type { ShotDriver } from './browser-launcher-port';
|
|
13
|
+
import { DEFAULT_PAGE_TIMEOUT_MS } from './cdp-shot-clock';
|
|
14
|
+
import { cdpShotDriver } from './cdp-shot-driver';
|
|
15
|
+
import type { DesignDriverFor } from './cmd-design-capture';
|
|
16
|
+
import { DESIGN_DIR, DESIGN_VIEWPORTS } from './cmd-design-paths';
|
|
17
|
+
import { type ResearchOutcome, researchDesign, researchJson } from './cmd-design-run';
|
|
18
|
+
import { designSpec } from './cmd-design-spec';
|
|
19
|
+
import { loadThemeHost } from './cmd-design-theme';
|
|
20
|
+
import { designHostPolicy, readDesignAllowHosts } from './cmd-design-url';
|
|
21
|
+
import type { CliCommand, CommandContext } from './command';
|
|
22
|
+
import { BadFlagError, MissingPositionalError } from './errors';
|
|
23
|
+
import { intFlagOr } from './flag-number';
|
|
24
|
+
import { msg } from './messages';
|
|
25
|
+
import { DESIGN_SOURCES } from './messages-design';
|
|
26
|
+
import type { CommandResult } from './output';
|
|
27
|
+
import type { ParsedArgs } from './parse';
|
|
28
|
+
import { flagBool, flagString } from './parse';
|
|
29
|
+
import type { Env } from './runtime-bindings';
|
|
30
|
+
import { shotBrowserChoice } from './shot-browser';
|
|
31
|
+
import type { ShotViewport } from './shot-viewport';
|
|
32
|
+
import { parseViewports } from './shot-viewport';
|
|
33
|
+
|
|
34
|
+
/** Links per reference `--follow` may take: a catalogue page, not a crawl. */
|
|
35
|
+
export const FOLLOW_MAX = 20;
|
|
36
|
+
|
|
37
|
+
const EXAMPLE = 'x design research https://example.com/ --json';
|
|
38
|
+
|
|
39
|
+
const intFlag = (args: ParsedArgs, name: string, min: number, fallback: number, max?: number) =>
|
|
40
|
+
intFlagOr(
|
|
41
|
+
args,
|
|
42
|
+
{
|
|
43
|
+
name,
|
|
44
|
+
command: 'design research',
|
|
45
|
+
min,
|
|
46
|
+
...(max === undefined ? {} : { max }),
|
|
47
|
+
example: `x design research https://example.com/ --${name} ${String(fallback)}`,
|
|
48
|
+
},
|
|
49
|
+
fallback,
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
export interface DesignRunInput {
|
|
53
|
+
readonly urls: readonly string[];
|
|
54
|
+
readonly outDir: string;
|
|
55
|
+
readonly env: Env;
|
|
56
|
+
readonly follow?: number | undefined;
|
|
57
|
+
readonly viewports?: readonly ShotViewport[] | undefined;
|
|
58
|
+
readonly allowHosts?: readonly string[] | undefined;
|
|
59
|
+
readonly timeoutMs?: number | undefined;
|
|
60
|
+
/** Test seams, never flags: the browser, the resolver, and hosts admitted without one. */
|
|
61
|
+
readonly driver?: ((viewport: ShotViewport) => Promise<ShotDriver>) | undefined;
|
|
62
|
+
readonly resolve?: DialResolve | undefined;
|
|
63
|
+
readonly trustedHosts?: readonly string[] | undefined;
|
|
64
|
+
/** `ui.research`'s cancellation: no browser is launched, and nothing published, after it. */
|
|
65
|
+
readonly signal?: AbortSignal | undefined;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The one body behind the command and `ui.research`. */
|
|
69
|
+
export async function runDesignResearch(input: DesignRunInput): Promise<ResearchOutcome> {
|
|
70
|
+
const driverFor: DesignDriverFor = async (viewport, dialScreen) => {
|
|
71
|
+
if (input.driver !== undefined) return input.driver(viewport);
|
|
72
|
+
// The same choice `x shot` makes, from the environment: a local Chrome or an attach URL.
|
|
73
|
+
const { cdpUrl, executablePath } = shotBrowserChoice({
|
|
74
|
+
cdpFlag: undefined,
|
|
75
|
+
browserFlag: undefined,
|
|
76
|
+
env: input.env,
|
|
77
|
+
});
|
|
78
|
+
return cdpShotDriver({
|
|
79
|
+
...(cdpUrl === undefined ? {} : { cdpUrl }),
|
|
80
|
+
...(executablePath === undefined ? {} : { executablePath }),
|
|
81
|
+
viewport,
|
|
82
|
+
dialScreen,
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
return researchDesign({
|
|
86
|
+
urls: input.urls,
|
|
87
|
+
// Screened here as well as by the flag reader: `ui.research` reaches this with an agent's number.
|
|
88
|
+
follow: finiteCount('x design research', 'follow', input.follow ?? 0),
|
|
89
|
+
outDir: input.outDir,
|
|
90
|
+
viewports: input.viewports ?? DESIGN_VIEWPORTS,
|
|
91
|
+
allowHosts: input.allowHosts ?? [],
|
|
92
|
+
timeoutMs: finiteCount(
|
|
93
|
+
'x design research',
|
|
94
|
+
'timeoutMs',
|
|
95
|
+
input.timeoutMs ?? DEFAULT_PAGE_TIMEOUT_MS,
|
|
96
|
+
1,
|
|
97
|
+
),
|
|
98
|
+
policy: designHostPolicy({ resolve: input.resolve, trustedHosts: input.trustedHosts }),
|
|
99
|
+
driverFor,
|
|
100
|
+
themeHost: await loadThemeHost(),
|
|
101
|
+
now: () => new Date(),
|
|
102
|
+
signal: input.signal,
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export function designListResult(): CommandResult {
|
|
107
|
+
return {
|
|
108
|
+
ok: true,
|
|
109
|
+
command: 'design',
|
|
110
|
+
summary: msg('cli.design.list', { count: DESIGN_SOURCES.length }),
|
|
111
|
+
lines: DESIGN_SOURCES.map((source) =>
|
|
112
|
+
msg('cli.design.source', {
|
|
113
|
+
name: source.name,
|
|
114
|
+
url: source.url,
|
|
115
|
+
posture: source.posture,
|
|
116
|
+
why: source.why,
|
|
117
|
+
}),
|
|
118
|
+
),
|
|
119
|
+
data: {
|
|
120
|
+
sources: DESIGN_SOURCES.map((source) => ({ ...source, hosts: [...source.hosts] })),
|
|
121
|
+
},
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
export function designResult(outcome: ResearchOutcome, out: string): CommandResult {
|
|
126
|
+
return {
|
|
127
|
+
ok: true,
|
|
128
|
+
command: 'design',
|
|
129
|
+
summary: msg('cli.design.summary', { count: outcome.references.length, out }),
|
|
130
|
+
lines: [
|
|
131
|
+
...outcome.references.flatMap((reference) => [
|
|
132
|
+
msg('cli.design.reference', { url: reference.url, dir: reference.dir }),
|
|
133
|
+
msg('cli.design.facts', {
|
|
134
|
+
colors: reference.colors,
|
|
135
|
+
animations: reference.animations,
|
|
136
|
+
refused: reference.refused,
|
|
137
|
+
}),
|
|
138
|
+
...(reference.validated ? [] : [msg('cli.design.unvalidated')]),
|
|
139
|
+
]),
|
|
140
|
+
...outcome.skipped.map((entry) =>
|
|
141
|
+
msg('cli.design.skipped', { url: entry.url, code: entry.code }),
|
|
142
|
+
),
|
|
143
|
+
],
|
|
144
|
+
data: researchJson(outcome),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export const designCommand: CliCommand = {
|
|
149
|
+
spec: designSpec,
|
|
150
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
151
|
+
const urls = ctx.args.positionals;
|
|
152
|
+
if (flagBool(ctx.args, 'list')) {
|
|
153
|
+
if (urls.length > 0) {
|
|
154
|
+
throw new BadFlagError({
|
|
155
|
+
flag: 'list',
|
|
156
|
+
command: 'design research',
|
|
157
|
+
reason: 'lists the reference catalogues; it researches no URL',
|
|
158
|
+
fix: 'x design research --list --json',
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
return designListResult();
|
|
162
|
+
}
|
|
163
|
+
if (urls.length === 0) {
|
|
164
|
+
throw new MissingPositionalError({
|
|
165
|
+
command: 'design research',
|
|
166
|
+
positional: 'url',
|
|
167
|
+
example: EXAMPLE,
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
// Every value read before a browser starts: a typo must not cost a launch to report.
|
|
171
|
+
const follow = intFlag(ctx.args, 'follow', 0, 0, FOLLOW_MAX);
|
|
172
|
+
const timeoutMs = intFlag(ctx.args, 'timeout', 1, DEFAULT_PAGE_TIMEOUT_MS);
|
|
173
|
+
const viewports = parseViewports(flagString(ctx.args, 'viewport'));
|
|
174
|
+
const allowHosts = readDesignAllowHosts(flagString(ctx.args, 'allow-hosts'));
|
|
175
|
+
const flag = flagString(ctx.args, 'out');
|
|
176
|
+
const outDir = flag === undefined ? join(ctx.cwd, DESIGN_DIR) : resolve(ctx.cwd, flag);
|
|
177
|
+
const outcome = await runDesignResearch({
|
|
178
|
+
urls,
|
|
179
|
+
outDir,
|
|
180
|
+
env: ctx.env,
|
|
181
|
+
follow,
|
|
182
|
+
viewports,
|
|
183
|
+
allowHosts,
|
|
184
|
+
timeoutMs,
|
|
185
|
+
});
|
|
186
|
+
return designResult(outcome, outDir);
|
|
187
|
+
},
|
|
188
|
+
};
|
package/src/cmd-doctor.ts
CHANGED
|
@@ -17,6 +17,7 @@ import { coverageExcludesProbe, withCoverageExcludes } from './doctor-coverage';
|
|
|
17
17
|
import { embeddedDatabaseFinding } from './doctor-database';
|
|
18
18
|
import { guardedCheck, guardedListing } from './doctor-guarded';
|
|
19
19
|
import { shippedGuardsProbe, vendoredGuardWarnings, withGuardListing } from './doctor-guards';
|
|
20
|
+
import { kitWarnings } from './doctor-kit';
|
|
20
21
|
import { offlineFallbackFinding } from './doctor-offline';
|
|
21
22
|
import { NO_POOLER_FACT, poolerFindings, withPoolerReport } from './doctor-pooler';
|
|
22
23
|
import { doctorPort, ownerAskedOnce, portFindings } from './doctor-port';
|
|
@@ -250,6 +251,7 @@ export async function reportDoctor(probe: DoctorReportProbe): Promise<CommandRes
|
|
|
250
251
|
const warnings = await guardedListing('warnings', failed, () => doctorWarnings(asked), []);
|
|
251
252
|
const superseded = await inApp('superseded workarounds', supersededFindings, []);
|
|
252
253
|
const floors = await inApp('advisory floors', advisoryFloorFindings, []);
|
|
254
|
+
const kit = await inApp('agent kit', kitWarnings, []);
|
|
253
255
|
// An `x upgrade` driven by a CLI older than the codemod engine left files it owed.
|
|
254
256
|
const codemods = await inApp(
|
|
255
257
|
'pending codemods',
|
|
@@ -264,6 +266,7 @@ export async function reportDoctor(probe: DoctorReportProbe): Promise<CommandRes
|
|
|
264
266
|
...browserWarnings(browser),
|
|
265
267
|
...superseded,
|
|
266
268
|
...floors,
|
|
269
|
+
...kit,
|
|
267
270
|
...codemods,
|
|
268
271
|
...failed,
|
|
269
272
|
]);
|
package/src/cmd-generate-spec.ts
CHANGED
|
@@ -26,6 +26,11 @@ export const generateSpec: CommandSpec = {
|
|
|
26
26
|
{ name: 'admin', type: 'boolean', summary: 'resource: also emit the admin override' },
|
|
27
27
|
{ name: 'locales', type: 'string', summary: 'comma-separated locales, default en' },
|
|
28
28
|
{ name: 'at', type: 'string', summary: 'island, admin:page: directory to write into' },
|
|
29
|
+
{
|
|
30
|
+
name: 'effect',
|
|
31
|
+
type: 'string',
|
|
32
|
+
summary: 'island: wrap the panel in an @ultimat3/effects entry',
|
|
33
|
+
},
|
|
29
34
|
{
|
|
30
35
|
name: 'app',
|
|
31
36
|
type: 'string',
|
package/src/cmd-generate.ts
CHANGED
|
@@ -19,7 +19,7 @@ import { appDisk, plannedDisk } from './generate-disk';
|
|
|
19
19
|
import { writtenExercises } from './generate-exercise';
|
|
20
20
|
import { assertFeatureExists } from './generate-feature';
|
|
21
21
|
import { assertSliceToRead } from './generate-feature-required';
|
|
22
|
-
import { DEFAULT_APP, generate, sliceDir } from './generate-files';
|
|
22
|
+
import { DEFAULT_APP, generate, readEffect, sliceDir } from './generate-files';
|
|
23
23
|
import { followUpEdits } from './generate-follow-ups';
|
|
24
24
|
import { formatWritten } from './generate-format-written';
|
|
25
25
|
import { runInvite } from './generate-invite';
|
|
@@ -99,6 +99,7 @@ export const generateCommand: CliCommand = {
|
|
|
99
99
|
const surface = readSurface(flagString(ctx.args, 'surface'), kind, name);
|
|
100
100
|
const locales = resolveLocales(await namedOrAppLocales(root, flagList(ctx.args, 'locales')));
|
|
101
101
|
const at = flagString(ctx.args, 'at');
|
|
102
|
+
const effect = readEffect(flagString(ctx.args, 'effect'), kind);
|
|
102
103
|
// The app workspace the slice lands in; `web` unless an app-local generator names another.
|
|
103
104
|
const app = readApp(flagString(ctx.args, 'app'), root, kind, name);
|
|
104
105
|
// Read with the two above, and refused here for their reason: the value is spliced into the
|
|
@@ -150,6 +151,7 @@ export const generateCommand: CliCommand = {
|
|
|
150
151
|
...(sliceEntity === undefined ? {} : { sliceEntity }),
|
|
151
152
|
...(sliceRepo === undefined ? {} : { sliceRepo }),
|
|
152
153
|
...(at === undefined ? {} : { at }),
|
|
154
|
+
...(effect === undefined ? {} : { effect }),
|
|
153
155
|
...(app === DEFAULT_APP ? {} : { app }),
|
|
154
156
|
...(permission === undefined ? {} : { permission }),
|
|
155
157
|
surface,
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// `x kit`'s declaration, apart from its body: the parser, `x help` and the `errors` step read it
|
|
2
|
+
// without loading `cmd-kit.ts`, which `registry.ts` imports only when the command runs.
|
|
3
|
+
|
|
4
|
+
import type { CommandSpec } from './parse';
|
|
5
|
+
|
|
6
|
+
export const kitSpec: CommandSpec = {
|
|
7
|
+
name: 'kit',
|
|
8
|
+
summary:
|
|
9
|
+
'write the managed agent kit (.claude/skills, .claude/agents) from the installed framework; app-* files and "off" entries are never touched',
|
|
10
|
+
usage: 'x kit [--json]',
|
|
11
|
+
requiresApp: true,
|
|
12
|
+
flags: [],
|
|
13
|
+
};
|
package/src/cmd-kit.ts
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// `x kit` — writes the managed agent kit into the app and refreshes it after an upgrade. A file is
|
|
2
|
+
// rewritten only when it differs; `app-*` files, `apps/web/DESIGN.md` and any entry `.claude/kit.json`
|
|
3
|
+
// lists under "off" are never touched, and `.claude/kit.json` is written once, when it is absent.
|
|
4
|
+
|
|
5
|
+
import { ERROR_DOCS_URL } from '@ultimat3/core';
|
|
6
|
+
import { activeKit, judgeKit, parseKitMarker } from './app-kit';
|
|
7
|
+
import { diskAt, managedKit } from './app-kit-disk';
|
|
8
|
+
import { requireAppRoot } from './app-root';
|
|
9
|
+
import { kitSpec } from './cmd-kit-spec';
|
|
10
|
+
import { agentKitCodemod } from './codemods/agent-kit';
|
|
11
|
+
import { fsCodemodApp } from './codemods/engine-fs';
|
|
12
|
+
import type { CliCommand, CommandContext } from './command';
|
|
13
|
+
import { ScaffoldPathEscapeError } from './errors';
|
|
14
|
+
import { KIT_MARKER, kitMarkerFile } from './kit/registry';
|
|
15
|
+
import { msg } from './messages';
|
|
16
|
+
import type { CommandResult, Finding } from './output';
|
|
17
|
+
|
|
18
|
+
export interface KitWrite {
|
|
19
|
+
readonly path: string;
|
|
20
|
+
readonly action: 'created' | 'updated';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** What a refresh wrote. `findings` is what it could not decide for the author. */
|
|
24
|
+
export interface KitRefresh {
|
|
25
|
+
readonly written: readonly KitWrite[];
|
|
26
|
+
readonly unchanged: number;
|
|
27
|
+
readonly off: readonly string[];
|
|
28
|
+
readonly findings: readonly Finding[];
|
|
29
|
+
/** Old files kept as `app-<name>.md` before the managed ones landed: the edits nothing may lose. */
|
|
30
|
+
readonly renamed: readonly { readonly path: string; readonly reason: string }[];
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** A path the guard refused: named, with how to find the link that leaves the app. */
|
|
34
|
+
const escapeFinding = (path: string): Finding => ({
|
|
35
|
+
code: 'X_SCAFFOLD_PATH_ESCAPE',
|
|
36
|
+
cause: `${path} resolves outside the app (a symlink on the way leaves it), so x kit did not write it`,
|
|
37
|
+
fix: 'find .claude -type l -ls # each link that leaves the app: rm it, make the path a real file or directory, then: bunx x kit',
|
|
38
|
+
docs: ERROR_DOCS_URL,
|
|
39
|
+
at: path,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
/** Writes every managed file that is missing or differs; the marker when absent. Never deletes. */
|
|
43
|
+
export async function refreshKit(root: string): Promise<KitRefresh> {
|
|
44
|
+
const disk = diskAt(root);
|
|
45
|
+
const managed = await managedKit(root);
|
|
46
|
+
const markerText = await disk.read(KIT_MARKER);
|
|
47
|
+
const marker = parseKitMarker(markerText);
|
|
48
|
+
// An unreadable marker is the author's: guessing its "off" list could overwrite a file it kept.
|
|
49
|
+
if (marker.state === 'invalid') {
|
|
50
|
+
const verdict = await judgeKit(disk, managed);
|
|
51
|
+
return { written: [], unchanged: 0, off: [], findings: verdict.findings, renamed: [] };
|
|
52
|
+
}
|
|
53
|
+
const off = marker.state === 'present' ? marker.off : [];
|
|
54
|
+
// No marker yet: a legacy `.claude/agents/<n>.md` an author edited sits on a managed path, and the
|
|
55
|
+
// write below would replace it. The codemod's own step keeps it as `app-<n>.md` first (and drops an
|
|
56
|
+
// unedited released one); with a marker it does nothing, and the gate judges an edit instead.
|
|
57
|
+
// Every write goes through the engine's guard (`codemods/engine-fs.ts`): a path that resolves
|
|
58
|
+
// outside the app, through a symlink or not, is refused and said so, never followed.
|
|
59
|
+
const app = fsCodemodApp(root);
|
|
60
|
+
const refusals: Finding[] = [];
|
|
61
|
+
const guarded = async <T>(path: string, work: () => Promise<T>): Promise<T | undefined> => {
|
|
62
|
+
try {
|
|
63
|
+
return await work();
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (!(error instanceof ScaffoldPathEscapeError)) throw error;
|
|
66
|
+
refusals.push(escapeFinding(path));
|
|
67
|
+
return undefined;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
const carried =
|
|
71
|
+
marker.state === 'absent'
|
|
72
|
+
? await guarded('.claude', () => agentKitCodemod().run(app))
|
|
73
|
+
: undefined;
|
|
74
|
+
const renamed = (carried?.skipped ?? []).map((skip) => ({
|
|
75
|
+
path: skip.path,
|
|
76
|
+
reason: skip.reason,
|
|
77
|
+
}));
|
|
78
|
+
const written: KitWrite[] = [];
|
|
79
|
+
let unchanged = 0;
|
|
80
|
+
for (const file of activeKit(managed, off)) {
|
|
81
|
+
const held = await guarded(file.path, () => app.read(file.path));
|
|
82
|
+
if (held === undefined && refusals.some((found) => found.at === file.path)) continue;
|
|
83
|
+
if (held === file.contents) {
|
|
84
|
+
unchanged += 1;
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
const landed = await guarded(file.path, async () => {
|
|
88
|
+
await app.write(file.path, file.contents);
|
|
89
|
+
return true;
|
|
90
|
+
});
|
|
91
|
+
if (landed === true) {
|
|
92
|
+
written.push({ path: file.path, action: held === undefined ? 'created' : 'updated' });
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
if (marker.state === 'absent') {
|
|
96
|
+
const file = kitMarkerFile();
|
|
97
|
+
const landed = await guarded(file.path, async () => {
|
|
98
|
+
await app.write(file.path, String(file.contents));
|
|
99
|
+
return true;
|
|
100
|
+
});
|
|
101
|
+
if (landed === true) written.push({ path: file.path, action: 'created' });
|
|
102
|
+
}
|
|
103
|
+
// Left for the author: a command a skill shadows is renamed with `git mv`, never by this command.
|
|
104
|
+
const after = await judgeKit(disk, managed);
|
|
105
|
+
return { written, unchanged, off, findings: [...refusals, ...after.findings], renamed };
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export const kitCommand: CliCommand = {
|
|
109
|
+
spec: kitSpec,
|
|
110
|
+
async run(ctx: CommandContext): Promise<CommandResult> {
|
|
111
|
+
const root = requireAppRoot('kit', ctx.cwd).dir;
|
|
112
|
+
const done = await refreshKit(root);
|
|
113
|
+
return {
|
|
114
|
+
ok: done.findings.length === 0,
|
|
115
|
+
command: 'kit',
|
|
116
|
+
summary:
|
|
117
|
+
done.written.length === 0
|
|
118
|
+
? msg('cli.kit.current', { count: done.unchanged })
|
|
119
|
+
: msg('cli.kit.wrote', { count: done.written.length }),
|
|
120
|
+
findings: done.findings,
|
|
121
|
+
data: {
|
|
122
|
+
written: done.written.map((w) => ({ ...w })),
|
|
123
|
+
unchanged: done.unchanged,
|
|
124
|
+
off: [...done.off],
|
|
125
|
+
renamed: done.renamed.map((r) => ({ ...r })),
|
|
126
|
+
},
|
|
127
|
+
lines: [
|
|
128
|
+
...done.written.map((w) => `${w.action} ${w.path}`),
|
|
129
|
+
...done.renamed.map((r) => `kept ${r.path}: ${r.reason}`),
|
|
130
|
+
],
|
|
131
|
+
};
|
|
132
|
+
},
|
|
133
|
+
};
|