@ultimat3/cli 31.52.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/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 +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/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 +63 -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
package/CLAUDE.md
CHANGED
|
@@ -191,7 +191,7 @@ Commands: `bun test ./packages/cli/` (repo root: the preload),
|
|
|
191
191
|
| `cmd-tasks-run.ts` | `x tasks run`: `TaskHandle.enqueue()`; production needs `--production` or `ULTIMATE_TASK_RUN=<name>` (`X_TASK_RUN_PRODUCTION`) |
|
|
192
192
|
| `doctor-api-listing.ts` | `x doctor` warns: action/query off a `defineApi()` listing others |
|
|
193
193
|
| `cmd-auth.ts` / `cmd-auth-spec.ts` / `doctor-auth.ts` | `x auth seal-mfa`: seals plaintext `x_users.mfa_secret` through auth's `sealMfaSecrets` |
|
|
194
|
-
| `cmd-mcp.ts` / `mcp-host*.ts` / `mcp-errors.ts` / `mcp-db-target.ts` / `mcp-test-{output,run}.ts` | `x mcp serve`:
|
|
194
|
+
| `cmd-mcp.ts` / `mcp-host*.ts` / `mcp-errors.ts` / `mcp-db-target.ts` / `mcp-test-{output,run}.ts` | `x mcp serve`: 24 tools, two transports; `tests.run`/`verify.run` ARE `x test`/`x verify` † |
|
|
195
195
|
| `cmd-shot*.ts` / `cdp-shot-*.ts` / `browser-launcher*.ts` / `island-*` | `x shot` over raw CDP; `verdict.json` names its own blind spots. Not a gate step |
|
|
196
196
|
| `cmd-profile*.ts` | `x profile <route>`: in-process JSC sampling profile of a route, hottest functions |
|
|
197
197
|
| `mcp-host-logs.ts` | `logs.tail` and `x logs tail`'s reader: path rule, end-first bounded read, per-role tail |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ultimat3/cli",
|
|
3
|
-
"version": "31.
|
|
3
|
+
"version": "31.53.0",
|
|
4
4
|
"description": "The `x` binary: new, dev, build, verify, generate, db, mcp, doctor, deploy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"ultimate",
|
|
@@ -53,34 +53,34 @@
|
|
|
53
53
|
},
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"@babel/core": "^8.1.0",
|
|
56
|
-
"@ultimat3/action": "31.
|
|
57
|
-
"@ultimat3/admin": "31.
|
|
58
|
-
"@ultimat3/ai": "31.
|
|
59
|
-
"@ultimat3/auth": "31.
|
|
60
|
-
"@ultimat3/cache": "31.
|
|
61
|
-
"@ultimat3/core": "31.
|
|
62
|
-
"@ultimat3/db": "31.
|
|
63
|
-
"@ultimat3/entity": "31.
|
|
64
|
-
"@ultimat3/flags": "31.
|
|
65
|
-
"@ultimat3/http": "31.
|
|
66
|
-
"@ultimat3/i18n": "31.
|
|
67
|
-
"@ultimat3/jobs": "31.
|
|
68
|
-
"@ultimat3/mail": "31.
|
|
69
|
-
"@ultimat3/manifest": "31.
|
|
70
|
-
"@ultimat3/mcp": "31.
|
|
71
|
-
"@ultimat3/money": "31.
|
|
72
|
-
"@ultimat3/notify": "31.
|
|
73
|
-
"@ultimat3/policy": "31.
|
|
74
|
-
"@ultimat3/pwa": "31.
|
|
75
|
-
"@ultimat3/query": "31.
|
|
76
|
-
"@ultimat3/realtime": "31.
|
|
77
|
-
"@ultimat3/render": "31.
|
|
78
|
-
"@ultimat3/schema": "31.
|
|
79
|
-
"@ultimat3/scraping": "31.
|
|
80
|
-
"@ultimat3/seo": "31.
|
|
81
|
-
"@ultimat3/storage": "31.
|
|
82
|
-
"@ultimat3/testing": "31.
|
|
83
|
-
"@ultimat3/time": "31.
|
|
56
|
+
"@ultimat3/action": "31.53.0",
|
|
57
|
+
"@ultimat3/admin": "31.53.0",
|
|
58
|
+
"@ultimat3/ai": "31.53.0",
|
|
59
|
+
"@ultimat3/auth": "31.53.0",
|
|
60
|
+
"@ultimat3/cache": "31.53.0",
|
|
61
|
+
"@ultimat3/core": "31.53.0",
|
|
62
|
+
"@ultimat3/db": "31.53.0",
|
|
63
|
+
"@ultimat3/entity": "31.53.0",
|
|
64
|
+
"@ultimat3/flags": "31.53.0",
|
|
65
|
+
"@ultimat3/http": "31.53.0",
|
|
66
|
+
"@ultimat3/i18n": "31.53.0",
|
|
67
|
+
"@ultimat3/jobs": "31.53.0",
|
|
68
|
+
"@ultimat3/mail": "31.53.0",
|
|
69
|
+
"@ultimat3/manifest": "31.53.0",
|
|
70
|
+
"@ultimat3/mcp": "31.53.0",
|
|
71
|
+
"@ultimat3/money": "31.53.0",
|
|
72
|
+
"@ultimat3/notify": "31.53.0",
|
|
73
|
+
"@ultimat3/policy": "31.53.0",
|
|
74
|
+
"@ultimat3/pwa": "31.53.0",
|
|
75
|
+
"@ultimat3/query": "31.53.0",
|
|
76
|
+
"@ultimat3/realtime": "31.53.0",
|
|
77
|
+
"@ultimat3/render": "31.53.0",
|
|
78
|
+
"@ultimat3/schema": "31.53.0",
|
|
79
|
+
"@ultimat3/scraping": "31.53.0",
|
|
80
|
+
"@ultimat3/seo": "31.53.0",
|
|
81
|
+
"@ultimat3/storage": "31.53.0",
|
|
82
|
+
"@ultimat3/testing": "31.53.0",
|
|
83
|
+
"@ultimat3/time": "31.53.0",
|
|
84
84
|
"babel-preset-solid": "^1.9.16"
|
|
85
85
|
}
|
|
86
86
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// The agent kit as an app root holds it: the disk behind `judgeKit`, and the managed files rendered
|
|
2
|
+
// for the app's own name. One seam, so the gate, `x kit`, `x doctor` and `x upgrade` read the same.
|
|
3
|
+
|
|
4
|
+
// why: Bun exposes no path-join or basename primitive.
|
|
5
|
+
import { basename, join } from 'node:path';
|
|
6
|
+
import type { KitDisk, KitVerdict } from './app-kit';
|
|
7
|
+
import { judgeKit } from './app-kit';
|
|
8
|
+
import { appName } from './codemods/agents-dev-mcp';
|
|
9
|
+
import type { KitFile } from './kit/registry';
|
|
10
|
+
import { kitFiles } from './kit/registry';
|
|
11
|
+
import { names } from './templates/naming';
|
|
12
|
+
|
|
13
|
+
export const diskAt = (root: string): KitDisk => ({
|
|
14
|
+
async read(path) {
|
|
15
|
+
const file = Bun.file(join(root, path));
|
|
16
|
+
return (await file.exists()) ? file.text() : undefined;
|
|
17
|
+
},
|
|
18
|
+
async glob(pattern) {
|
|
19
|
+
const found: string[] = [];
|
|
20
|
+
for await (const path of new Bun.Glob(pattern).scan({ cwd: root })) found.push(path);
|
|
21
|
+
return found.sort();
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
/** The name the scaffold spelled into the kit: the root `package.json`'s, else the directory's. */
|
|
26
|
+
export async function kitAppName(root: string): Promise<string> {
|
|
27
|
+
const manifest = await diskAt(root).read('package.json');
|
|
28
|
+
return (manifest === undefined ? undefined : appName(manifest)) ?? basename(root);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** Every managed file rendered for the app at `root`. */
|
|
32
|
+
export async function managedKit(root: string): Promise<readonly KitFile[]> {
|
|
33
|
+
return kitFiles(names(await kitAppName(root)));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** The gate's, `x doctor`'s and `x upgrade`'s one question about an app. */
|
|
37
|
+
export async function kitVerdict(root: string): Promise<KitVerdict> {
|
|
38
|
+
return judgeKit(diskAt(root), await managedKit(root));
|
|
39
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// The identity of a command or agent file an earlier release wrote: hashed with the app's name
|
|
2
|
+
// swapped for a fixed one, because the templates spell `mcp__<app>__*` into the text. The refresh
|
|
3
|
+
// script and the `agent-kit` codemod share this one function, so a form hashed there matches here.
|
|
4
|
+
|
|
5
|
+
import { guardFormHash } from './guards-vendored';
|
|
6
|
+
|
|
7
|
+
/** A valid kebab name no app picks: the template is rendered with it, and an app's text maps to it. */
|
|
8
|
+
export const KIT_FORM_NAME = 'zz-kit-form-zz';
|
|
9
|
+
|
|
10
|
+
/** `file`'s hash with the app's `kebab` read as `KIT_FORM_NAME`. */
|
|
11
|
+
export const kitFormHash = (text: string, kebab: string): string =>
|
|
12
|
+
guardFormHash(kebab === '' ? text : text.replaceAll(kebab, KIT_FORM_NAME));
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* True when `text` is one of `known` for some name the app could have been scaffolded under. These
|
|
16
|
+
* are identities of public template text, never a secret, so a set lookup is the right comparison —
|
|
17
|
+
* `timingSafeEqual` would guard a value nobody is trying to learn byte by byte.
|
|
18
|
+
*/
|
|
19
|
+
export const isReleasedKitForm = (
|
|
20
|
+
text: string,
|
|
21
|
+
names: readonly string[],
|
|
22
|
+
known: readonly string[] | undefined,
|
|
23
|
+
): boolean => {
|
|
24
|
+
if (known === undefined) return false;
|
|
25
|
+
const released = new Set(known);
|
|
26
|
+
return names.some((name) => released.has(kitFormHash(text, name)));
|
|
27
|
+
};
|
package/src/app-kit.ts
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// The agent kit against the app's disk: a managed file missing or edited is X_KIT_DRIFT, a command
|
|
2
|
+
// that a same-named skill silently shadows is X_KIT_SHADOWED. Pure over an injected reader, so the
|
|
3
|
+
// gate, `x kit`, `x doctor` and `x upgrade` all ask one function. `.claude/kit.json` is the opt-in:
|
|
4
|
+
// present, the findings are errors; absent, one warning — `main` never reddens on a new rule.
|
|
5
|
+
|
|
6
|
+
import { ERROR_DOCS_URL, isJsonObject, renderFixShellArg } from '@ultimat3/core';
|
|
7
|
+
import type { KitFile } from './kit/registry';
|
|
8
|
+
import { KIT_MARKER } from './kit/registry';
|
|
9
|
+
import type { Finding } from './output';
|
|
10
|
+
|
|
11
|
+
export const KIT_DRIFT = 'X_KIT_DRIFT';
|
|
12
|
+
export const KIT_SHADOWED = 'X_KIT_SHADOWED';
|
|
13
|
+
export const KIT_FIX = 'bunx x kit';
|
|
14
|
+
const COMMANDS_DIR = '.claude/commands';
|
|
15
|
+
|
|
16
|
+
/** What the app's disk answers: the text at a path, and the paths a glob names. */
|
|
17
|
+
export interface KitDisk {
|
|
18
|
+
read(path: string): Promise<string | undefined>;
|
|
19
|
+
glob(pattern: string): Promise<readonly string[]>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type KitMarker =
|
|
23
|
+
| { readonly state: 'absent' }
|
|
24
|
+
| { readonly state: 'invalid'; readonly why: string }
|
|
25
|
+
| { readonly state: 'present'; readonly off: readonly string[] };
|
|
26
|
+
|
|
27
|
+
/** `kit.json` parsed: `{ "off": ["<entry name>", …] }`, the only key. */
|
|
28
|
+
export function parseKitMarker(text: string | undefined): KitMarker {
|
|
29
|
+
if (text === undefined) return { state: 'absent' };
|
|
30
|
+
let parsed: unknown;
|
|
31
|
+
try {
|
|
32
|
+
parsed = JSON.parse(text);
|
|
33
|
+
} catch {
|
|
34
|
+
return { state: 'invalid', why: 'it is not JSON' };
|
|
35
|
+
}
|
|
36
|
+
if (!isJsonObject(parsed)) return { state: 'invalid', why: 'it is not an object' };
|
|
37
|
+
const off = parsed['off'];
|
|
38
|
+
if (off === undefined) return { state: 'present', off: [] };
|
|
39
|
+
if (!Array.isArray(off) || off.some((entry) => typeof entry !== 'string')) {
|
|
40
|
+
return { state: 'invalid', why: '"off" is not a list of entry names' };
|
|
41
|
+
}
|
|
42
|
+
return { state: 'present', off: off as string[] };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const finding = (code: string, cause: string, fix: string, at: string): Finding => ({
|
|
46
|
+
code,
|
|
47
|
+
cause,
|
|
48
|
+
fix,
|
|
49
|
+
docs: ERROR_DOCS_URL,
|
|
50
|
+
at,
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
/** The managed files `x kit` writes: every entry the app has not switched off. */
|
|
54
|
+
export const activeKit = (
|
|
55
|
+
managed: readonly KitFile[],
|
|
56
|
+
off: readonly string[],
|
|
57
|
+
): readonly KitFile[] => managed.filter((file) => !off.includes(file.name));
|
|
58
|
+
|
|
59
|
+
const same = (a: string, b: string): boolean =>
|
|
60
|
+
a.replaceAll('\r\n', '\n') === b.replaceAll('\r\n', '\n');
|
|
61
|
+
|
|
62
|
+
/** One finding per managed file the disk lacks or holds edited. */
|
|
63
|
+
async function driftFindings(disk: KitDisk, files: readonly KitFile[]): Promise<Finding[]> {
|
|
64
|
+
const found: Finding[] = [];
|
|
65
|
+
for (const file of files) {
|
|
66
|
+
const held = await disk.read(file.path);
|
|
67
|
+
if (held !== undefined && same(held, file.contents)) continue;
|
|
68
|
+
const variant =
|
|
69
|
+
file.kind === 'skill'
|
|
70
|
+
? `.claude/skills/app-${file.name}/SKILL.md`
|
|
71
|
+
: `.claude/agents/app-${file.name}.md`;
|
|
72
|
+
found.push(
|
|
73
|
+
finding(
|
|
74
|
+
KIT_DRIFT,
|
|
75
|
+
held === undefined
|
|
76
|
+
? `${file.path} is a managed kit file and is missing`
|
|
77
|
+
: `${file.path} is a managed kit file and was edited by hand; \`x kit\` rewrites it`,
|
|
78
|
+
held === undefined
|
|
79
|
+
? KIT_FIX
|
|
80
|
+
: `${KIT_FIX} # to keep your change, copy the file to ${variant} and add "${file.name}" to "off" in ${KIT_MARKER} first`,
|
|
81
|
+
file.path,
|
|
82
|
+
),
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
return found;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** A `.claude/commands/<skill>.md` an ACTIVE skill of the same name silently shadows: not an "off" one. */
|
|
89
|
+
async function shadowFindings(disk: KitDisk, files: readonly KitFile[]): Promise<Finding[]> {
|
|
90
|
+
const found: Finding[] = [];
|
|
91
|
+
for (const file of files.filter((entry) => entry.kind === 'skill')) {
|
|
92
|
+
const path = `${COMMANDS_DIR}/${file.name}.md`;
|
|
93
|
+
if ((await disk.read(path)) === undefined) continue;
|
|
94
|
+
found.push(
|
|
95
|
+
finding(
|
|
96
|
+
KIT_SHADOWED,
|
|
97
|
+
`${path} is shadowed by the managed skill ${file.name}: the skill runs, the command never does`,
|
|
98
|
+
`git -C .claude/commands mv ${renderFixShellArg(`${file.name}.md`, '<command>.md')} ${renderFixShellArg(`app-${file.name}.md`, 'app-<command>.md')}`,
|
|
99
|
+
path,
|
|
100
|
+
),
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
return found;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export interface KitVerdict {
|
|
107
|
+
readonly marker: KitMarker;
|
|
108
|
+
readonly findings: readonly Finding[];
|
|
109
|
+
/** Advice that fails nothing: the marker absent, or one the gate cannot read. */
|
|
110
|
+
readonly warnings: readonly string[];
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The kit against the disk. A marker that reads as a list of names to leave off is honoured; one
|
|
115
|
+
* that does not parse is a finding of its own, and nothing else is judged against a guess.
|
|
116
|
+
*/
|
|
117
|
+
export async function judgeKit(disk: KitDisk, managed: readonly KitFile[]): Promise<KitVerdict> {
|
|
118
|
+
const marker = parseKitMarker(await disk.read(KIT_MARKER));
|
|
119
|
+
if (marker.state === 'absent') {
|
|
120
|
+
return {
|
|
121
|
+
marker,
|
|
122
|
+
findings: [],
|
|
123
|
+
warnings: [`${KIT_MARKER} is absent: this app has no managed agent kit — fix: ${KIT_FIX}`],
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
if (marker.state === 'invalid') {
|
|
127
|
+
return {
|
|
128
|
+
marker,
|
|
129
|
+
findings: [
|
|
130
|
+
finding(
|
|
131
|
+
KIT_DRIFT,
|
|
132
|
+
`${KIT_MARKER} is unreadable: ${marker.why}`,
|
|
133
|
+
`printf '{\\n "off": []\\n}\\n' > ${KIT_MARKER}`,
|
|
134
|
+
KIT_MARKER,
|
|
135
|
+
),
|
|
136
|
+
],
|
|
137
|
+
warnings: [],
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
const files = activeKit(managed, marker.off);
|
|
141
|
+
return {
|
|
142
|
+
marker,
|
|
143
|
+
findings: [...(await driftFindings(disk, files)), ...(await shadowFindings(disk, files))],
|
|
144
|
+
warnings: [],
|
|
145
|
+
};
|
|
146
|
+
}
|
package/src/budgets.ts
CHANGED
|
@@ -90,8 +90,10 @@ export interface BuildStats {
|
|
|
90
90
|
* origin), so two spellings of one fetch are charged once; and an app/ page is weighed as SERVED
|
|
91
91
|
* — its page boot charged, the runtime chunk that boot makes unfetched not (plan 101 sweep 9).
|
|
92
92
|
* `6`: a `<link rel="modulepreload">` is a fetch and is charged, deduped with every other (B4).
|
|
93
|
+
* `7`: the exempt theme script's bytes moved again — it also stamps `html[data-motion="paused"]`
|
|
94
|
+
* from the reader's stored motion pause before first paint (plan 101, 06 motion).
|
|
93
95
|
*/
|
|
94
|
-
export const BUILD_STATS_RULES =
|
|
96
|
+
export const BUILD_STATS_RULES = 7;
|
|
95
97
|
|
|
96
98
|
const chainOf = (stats: RouteStats): string =>
|
|
97
99
|
stats.heaviestChain === undefined ? 'unknown import chain' : stats.heaviestChain.join(' -> ');
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The DNS half of a shot session's request interception: `Fetch.requestPaused` events are screened
|
|
2
|
+
// by an async resolver before `cdp-shot-watch.ts` sees them — refused ones failed here, the rest
|
|
3
|
+
// handed on unchanged.
|
|
4
|
+
//
|
|
5
|
+
// The watch decides by NAME (core's `hostDecision`, whose floor already refuses a private literal and
|
|
6
|
+
// `localhost`); a name that RESOLVES inward needs a resolver. Chrome re-resolves the name itself
|
|
7
|
+
// (rebinding stays open, as `@ultimat3/scraping`'s browser leg documents): this closes the static
|
|
8
|
+
// case, not the race. A WebSocket handshake is never paused by `Fetch` at all — whoever screens a
|
|
9
|
+
// session refuses sockets in the page (`DESIGN_PREPARE`).
|
|
10
|
+
|
|
11
|
+
import type { CdpConnection, CdpEventListener } from '@ultimat3/scraping/cdp';
|
|
12
|
+
|
|
13
|
+
/** Why a request was refused: it resolves inward, or it could not be resolved at all. */
|
|
14
|
+
export type DialRefusal = 'private' | 'unresolved';
|
|
15
|
+
|
|
16
|
+
export interface DialScreen {
|
|
17
|
+
/** The sessions whose pauses are this session's to decide; another's pass through untouched. */
|
|
18
|
+
readonly owns: (sessionId: string | undefined) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* `undefined` when there is nothing to resolve (the watch decides alone), else a promise of the
|
|
21
|
+
* refusal — `undefined` when the request may go. A rejection refuses as `unresolved`: an
|
|
22
|
+
* unscreened request is never released, and a resolver that failed proved nothing private.
|
|
23
|
+
*/
|
|
24
|
+
readonly screen: (url: string) => Promise<DialRefusal | undefined> | undefined;
|
|
25
|
+
/** Told of each refusal and why, so the caller can report what the page tried to reach. */
|
|
26
|
+
readonly refused: (url: string, reason: DialRefusal) => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const urlOf = (params: Record<string, unknown>): string => {
|
|
30
|
+
const request = params['request'];
|
|
31
|
+
if (typeof request !== 'object' || request === null) return '';
|
|
32
|
+
const url = (request as Record<string, unknown>)['url'];
|
|
33
|
+
return typeof url === 'string' ? url : '';
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function screenedConnection(connection: CdpConnection, dial: DialScreen): CdpConnection {
|
|
37
|
+
const screenedListener =
|
|
38
|
+
(listener: CdpEventListener): CdpEventListener =>
|
|
39
|
+
(params, on) => {
|
|
40
|
+
if (!dial.owns(on)) return listener(params, on);
|
|
41
|
+
const url = urlOf(params);
|
|
42
|
+
const pending = dial.screen(url);
|
|
43
|
+
if (pending === undefined) return listener(params, on);
|
|
44
|
+
void pending
|
|
45
|
+
.catch((): DialRefusal => 'unresolved')
|
|
46
|
+
.then((refusal) => {
|
|
47
|
+
if (refusal === undefined) return listener(params, on);
|
|
48
|
+
dial.refused(url, refusal);
|
|
49
|
+
return connection
|
|
50
|
+
.send(
|
|
51
|
+
'Fetch.failRequest',
|
|
52
|
+
{ requestId: params['requestId'], errorReason: 'BlockedByClient' },
|
|
53
|
+
on,
|
|
54
|
+
)
|
|
55
|
+
.then(
|
|
56
|
+
() => undefined,
|
|
57
|
+
() => undefined,
|
|
58
|
+
);
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
send: (method, params, sessionId, deadlineMs) =>
|
|
63
|
+
connection.send(method, params, sessionId, deadlineMs),
|
|
64
|
+
once: (method, sessionId, timeoutMs) => connection.once(method, sessionId, timeoutMs),
|
|
65
|
+
on: (method, listener) =>
|
|
66
|
+
connection.on(
|
|
67
|
+
method,
|
|
68
|
+
method === 'Fetch.requestPaused' ? screenedListener(listener) : listener,
|
|
69
|
+
),
|
|
70
|
+
close: () => connection.close(),
|
|
71
|
+
};
|
|
72
|
+
}
|
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
|
+
}
|