@vectoriox/iox-ui 5.203.0 → 5.205.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/actions-core/index.d.ts +8 -1
- package/design-core/index.d.ts +70 -2
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs +8 -1
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-design-core.mjs +131 -11
- package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +5294 -267
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +524 -112
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +2308 -6
- package/index.d.ts +159 -13
- package/package.json +1 -1
- package/src/actions-core/element-actions.ts +9 -0
- package/src/design-core/contrast-audit.ts +93 -11
- package/src/design-core/flavor-spec.generated.ts +19 -0
- package/src/design-core/image-alt.ts +27 -0
- package/src/design-core/node-links.ts +12 -0
- package/src/design-core/public-api.ts +1 -0
- package/src/generation-core/ai-run.ts +31 -0
- package/src/generation-core/audit-site.ts +17 -3
- package/src/generation-core/baseline-roles.ts +10 -6
- package/src/generation-core/check-free.ts +12 -2
- package/src/generation-core/check-layout.ts +3 -2
- package/src/generation-core/critic-calibration.ts +178 -0
- package/src/generation-core/critic-prompt.ts +174 -0
- package/src/generation-core/critic-rubric.generated.ts +24 -0
- package/src/generation-core/critic-sheet.ts +270 -0
- package/src/generation-core/critic.ts +189 -0
- package/src/generation-core/design-doc-index.ts +58 -0
- package/src/generation-core/design-motion.ts +247 -0
- package/src/generation-core/design-ops-check.ts +370 -0
- package/src/generation-core/design-ops-of.ts +200 -0
- package/src/generation-core/design-ops.model.ts +239 -0
- package/src/generation-core/design-ops.schema.ts +122 -0
- package/src/generation-core/design-ops.ts +361 -0
- package/src/generation-core/design-recipes.ts +58 -0
- package/src/generation-core/designer-brief.ts +82 -0
- package/src/generation-core/designer-direction.ts +248 -0
- package/src/generation-core/designer-estimate.ts +171 -0
- package/src/generation-core/designer-lessons.generated.ts +653 -0
- package/src/generation-core/designer-lessons.ts +153 -0
- package/src/generation-core/designer-stop.ts +94 -0
- package/src/generation-core/footer-mix.ts +3 -1
- package/src/generation-core/node-baselines.generated.ts +953 -10
- package/src/generation-core/public-api.ts +20 -0
- package/src/generation-core/site-spec.generated.ts +73 -11
- package/src/generation-core/social-links.ts +195 -2
- package/src/generation-core/structure-fingerprint.ts +565 -0
- package/src/generation-core/templates.ts +39 -3
- package/styles/iox-design.css +26 -1
- package/styles/iox-forms.css +22 -0
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* THE CRITIC'S SHEET (ai-designer-plan §2c–§2d, AD3): what the critic looks at — the reference beside ours, view by view,
|
|
3
|
+
* laptop then phone, then 4–6 zoomed crops (a defect under ~20px is invisible at sheet scale, law HARNESS §1.5). The
|
|
4
|
+
* captures come from a `CaptureSource`: today the folders the tester and the designer loop wrote
|
|
5
|
+
* (`<dir>/<laptop|phone>/0N-<view>.png` + `metrics.json`); from AD2 the `iox-render` service, behind the same interface.
|
|
6
|
+
* This file only PLANS the sheet (which pairs, which crops, what they cost in image tokens); the pixels are the caller's.
|
|
7
|
+
* Pure.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export enum CaptureWidth {
|
|
11
|
+
Laptop = 'laptop',
|
|
12
|
+
Phone = 'phone',
|
|
13
|
+
}
|
|
14
|
+
/** The widths' viewports (§2c). */
|
|
15
|
+
export const CAPTURE_VIEWPORTS: Readonly<Record<CaptureWidth, { w: number; h: number }>> = {
|
|
16
|
+
[CaptureWidth.Laptop]: { w: 1440, h: 900 },
|
|
17
|
+
[CaptureWidth.Phone]: { w: 390, h: 844 },
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The views, in the order the sheet shows them: the tester's capture set (`first` … `full`) and the views `iox-render`
|
|
22
|
+
* adds in AD2 (two screens down, the Scenes at 25 / 50 / 90 %, reduced motion). A view a source does not have is skipped.
|
|
23
|
+
*/
|
|
24
|
+
export enum CaptureView {
|
|
25
|
+
First = 'first',
|
|
26
|
+
HeaderOpen = 'header-open',
|
|
27
|
+
HeaderScrolled = 'header-scrolled',
|
|
28
|
+
Down1 = 'down-1',
|
|
29
|
+
Down2 = 'down-2.2',
|
|
30
|
+
List = 'list',
|
|
31
|
+
Scene25 = 'scene-25',
|
|
32
|
+
Scene50 = 'scene-50',
|
|
33
|
+
Scene90 = 'scene-90',
|
|
34
|
+
Reduced = 'reduced-motion',
|
|
35
|
+
Footer = 'footer',
|
|
36
|
+
Full = 'full',
|
|
37
|
+
}
|
|
38
|
+
export const CAPTURE_VIEW_ORDER: ReadonlyArray<CaptureView> = Object.values(CaptureView);
|
|
39
|
+
|
|
40
|
+
/** One captured picture: where it is (a path, a storage key — the caller reads it) and its size in pixels. */
|
|
41
|
+
export interface CaptureShot {
|
|
42
|
+
width: CaptureWidth;
|
|
43
|
+
view: CaptureView;
|
|
44
|
+
ref: string;
|
|
45
|
+
w: number;
|
|
46
|
+
h: number;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** A box on a shot, in its pixels. */
|
|
50
|
+
export interface CaptureBox {
|
|
51
|
+
x: number;
|
|
52
|
+
y: number;
|
|
53
|
+
w: number;
|
|
54
|
+
h: number;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** The measures a capture knows (a subset of the tester's `metrics.json`; AD2's measures add to it). */
|
|
58
|
+
export interface CaptureMetrics {
|
|
59
|
+
/** The header's box at load. */
|
|
60
|
+
header?: CaptureBox;
|
|
61
|
+
/** Boxes a measure flagged (an overlap, a lone word, a clipped line) — each one is cropped first. */
|
|
62
|
+
flagged?: Array<{ box: CaptureBox; view: CaptureView; why: string }>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface CaptureSet {
|
|
66
|
+
/** The page (`law-home`) or the reference (`graya-institute`). */
|
|
67
|
+
name: string;
|
|
68
|
+
shots: CaptureShot[];
|
|
69
|
+
metrics?: Partial<Record<CaptureWidth, CaptureMetrics>>;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** What a page or a reference is, to its capture source. */
|
|
73
|
+
export interface CaptureTarget {
|
|
74
|
+
name: string;
|
|
75
|
+
/** The address the source renders (iox-render), or the folder it reads (today). */
|
|
76
|
+
at: string;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** The one interface the sheet is built from. Today a folder reader; from AD2, `iox-render`. */
|
|
80
|
+
export interface CaptureSource {
|
|
81
|
+
capture(target: CaptureTarget): Promise<CaptureSet>;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Image tokens a vision model reads for a picture of w × h (ai-cost-plan, ai-designer-plan §6b): ⌈w/28⌉ × ⌈h/28⌉,
|
|
86
|
+
* capped — a bigger picture is scaled down to the cap.
|
|
87
|
+
*/
|
|
88
|
+
export const VISION_TOKEN_TILE = 28;
|
|
89
|
+
export const VISION_TOKEN_CAP = 4_784;
|
|
90
|
+
export function visionImageTokens(w: number, h: number): number {
|
|
91
|
+
return Math.min(Math.ceil(w / VISION_TOKEN_TILE) * Math.ceil(h / VISION_TOKEN_TILE), VISION_TOKEN_CAP);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** One view on the sheet: the reference's and ours. A Scene stop may be OURS ALONE (`reference` absent): a reference is not
|
|
95
|
+
* an IOX site, so its capture has no Scene stills, and without ours the critic judged motion from a whole-page view where a
|
|
96
|
+
* Scene is a blank runway (AD3 calibration; the lead, 2026-12-01). */
|
|
97
|
+
export interface SheetPair {
|
|
98
|
+
width: CaptureWidth;
|
|
99
|
+
view: CaptureView;
|
|
100
|
+
reference?: CaptureShot;
|
|
101
|
+
ours: CaptureShot;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The views the sheet shows of ours even when the reference has none: the Scene stops, where motion is judged. */
|
|
105
|
+
export const OURS_ALONE_VIEWS: ReadonlyArray<CaptureView> = [CaptureView.Scene25, CaptureView.Scene50, CaptureView.Scene90];
|
|
106
|
+
|
|
107
|
+
/** A zoomed crop: the box on a shot, how much it is enlarged, and why it was chosen. `reference` crops the same place on
|
|
108
|
+
* the reference's shot, for a side by side (a flagged defect of ours has none). */
|
|
109
|
+
export interface SheetCrop {
|
|
110
|
+
width: CaptureWidth;
|
|
111
|
+
view: CaptureView;
|
|
112
|
+
why: string;
|
|
113
|
+
ours: { ref: string; box: CaptureBox };
|
|
114
|
+
reference?: { ref: string; box: CaptureBox };
|
|
115
|
+
zoom: number;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface CritiqueSheet {
|
|
119
|
+
pairs: SheetPair[];
|
|
120
|
+
crops: SheetCrop[];
|
|
121
|
+
/** The views one side has and the other has not (`phone/footer: no reference shot`). */
|
|
122
|
+
missing: string[];
|
|
123
|
+
/** What left the sheet to keep it inside `CRITIC_SHEET_MAX_IMAGES` (`phone/first`, `crop: the phone footer`), in order. */
|
|
124
|
+
dropped: string[];
|
|
125
|
+
/** The image tokens the sheet costs a vision model (pairs, then each crop at its zoom). */
|
|
126
|
+
imageTokens: number;
|
|
127
|
+
/** Of those, the reference's views — the share read from the cache from round 2 (`CriticSheetLayout.Cached`). */
|
|
128
|
+
referenceImageTokens: number;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Crops the sheet always looks at when the measures flagged fewer, as fractions of the shot (`box` in 0–1). */
|
|
132
|
+
export interface CropRecipe {
|
|
133
|
+
width: CaptureWidth;
|
|
134
|
+
view: CaptureView;
|
|
135
|
+
box: CaptureBox;
|
|
136
|
+
why: string;
|
|
137
|
+
}
|
|
138
|
+
export const CRITIC_CROP_RECIPES: ReadonlyArray<CropRecipe> = [
|
|
139
|
+
{ width: CaptureWidth.Laptop, view: CaptureView.First, box: { x: 0, y: 0, w: 1, h: 0.16 }, why: 'the header on the opening' },
|
|
140
|
+
{ width: CaptureWidth.Laptop, view: CaptureView.First, box: { x: 0, y: 0.16, w: 0.6, h: 0.6 }, why: 'the opening\'s words' },
|
|
141
|
+
{ width: CaptureWidth.Laptop, view: CaptureView.Footer, box: { x: 0, y: 0.55, w: 1, h: 0.45 }, why: 'the footer\'s name and legal row' },
|
|
142
|
+
{ width: CaptureWidth.Phone, view: CaptureView.First, box: { x: 0, y: 0, w: 1, h: 0.5 }, why: 'the phone opening and its header' },
|
|
143
|
+
{ width: CaptureWidth.Phone, view: CaptureView.Footer, box: { x: 0, y: 0.5, w: 1, h: 0.5 }, why: 'the phone footer' },
|
|
144
|
+
];
|
|
145
|
+
export const CRITIC_CROPS = { min: 4, max: 6 } as const;
|
|
146
|
+
/** Flagged boxes take at most this many crops (one per distinct finding — a clipped button repeated down the page is one),
|
|
147
|
+
* so the recipes always keep the fewest (`CRITIC_CROPS.min`): a page with nine findings still shows its header and footer. */
|
|
148
|
+
export const CRITIC_FLAGGED_CROPS = CRITIC_CROPS.max - CRITIC_CROPS.min;
|
|
149
|
+
/** A crop is enlarged until its long side fills a laptop view, at most this much. */
|
|
150
|
+
export const CRITIC_CROP_MAX_ZOOM = 2;
|
|
151
|
+
/** Room kept around a measured box (the header's), in pixels. */
|
|
152
|
+
const CROP_MARGIN = 16;
|
|
153
|
+
|
|
154
|
+
const shotOf = (set: CaptureSet, width: CaptureWidth, view: CaptureView) => set.shots.find(s => s.width === width && s.view === view);
|
|
155
|
+
const fraction = (shot: CaptureShot, f: CaptureBox): CaptureBox =>
|
|
156
|
+
({ x: Math.round(f.x * shot.w), y: Math.round(f.y * shot.h), w: Math.round(f.w * shot.w), h: Math.round(f.h * shot.h) });
|
|
157
|
+
const clip = (shot: CaptureShot, b: CaptureBox): CaptureBox => {
|
|
158
|
+
const x = Math.max(0, Math.min(b.x, shot.w - 1));
|
|
159
|
+
const y = Math.max(0, Math.min(b.y, shot.h - 1));
|
|
160
|
+
return { x, y, w: Math.max(1, Math.min(b.w, shot.w - x)), h: Math.max(1, Math.min(b.h, shot.h - y)) };
|
|
161
|
+
};
|
|
162
|
+
function zoomOf(box: CaptureBox): number {
|
|
163
|
+
const fill = Math.min(CAPTURE_VIEWPORTS[CaptureWidth.Laptop].w / box.w, CAPTURE_VIEWPORTS[CaptureWidth.Laptop].h / box.h);
|
|
164
|
+
return Math.max(1, Math.min(CRITIC_CROP_MAX_ZOOM, Math.floor(fill * 4) / 4));
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* The most pictures one sheet sends (the lead, 2026-12-01, after AD3's first live call): the Claude API holds every picture
|
|
169
|
+
* of a request with more than 20 to 2000 px a side, which leaves a full-page overview ≈ 290 px wide. At ≤ 20 a picture may
|
|
170
|
+
* be 8000 px a side, so the full page stays readable.
|
|
171
|
+
*/
|
|
172
|
+
export const CRITIC_SHEET_MAX_IMAGES = 20;
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* The order views leave a sheet that is over the limit: first the phone views the sheet already shows another way — the
|
|
176
|
+
* opening and the footer (the phone crops enlarge them), then the rest of the phone's screens, which the laptop's views
|
|
177
|
+
* and the phone's full page cover — then the menu open, phone and laptop. The full pages and the laptop's own screens stay.
|
|
178
|
+
*/
|
|
179
|
+
export const CRITIC_SHEET_DROP_ORDER: ReadonlyArray<readonly [CaptureWidth, CaptureView]> = [
|
|
180
|
+
...[CaptureView.First, CaptureView.Footer, CaptureView.HeaderScrolled, CaptureView.Down1, CaptureView.Down2, CaptureView.List,
|
|
181
|
+
CaptureView.Scene25, CaptureView.Scene50, CaptureView.Scene90, CaptureView.Reduced].map(v => [CaptureWidth.Phone, v] as const),
|
|
182
|
+
[CaptureWidth.Phone, CaptureView.HeaderOpen],
|
|
183
|
+
[CaptureWidth.Laptop, CaptureView.HeaderOpen],
|
|
184
|
+
// the laptop Scene's ends; its middle (50 %) stays as long as any crop beyond the fewest can go
|
|
185
|
+
[CaptureWidth.Laptop, CaptureView.Scene25],
|
|
186
|
+
[CaptureWidth.Laptop, CaptureView.Scene90],
|
|
187
|
+
];
|
|
188
|
+
|
|
189
|
+
/** The pairs no sheet drops, however full: the laptop's opening and both full pages. */
|
|
190
|
+
const SHEET_KEEPS: ReadonlyArray<readonly [CaptureWidth, CaptureView]> = [
|
|
191
|
+
[CaptureWidth.Laptop, CaptureView.First], [CaptureWidth.Laptop, CaptureView.Full], [CaptureWidth.Phone, CaptureView.Full],
|
|
192
|
+
];
|
|
193
|
+
|
|
194
|
+
/** The pictures a sheet sends: ours of every pair and crop, and the reference's where it has one. */
|
|
195
|
+
export function sheetImageCount(sheet: Pick<CritiqueSheet, 'pairs' | 'crops'>): number {
|
|
196
|
+
return sheet.pairs.reduce((n, p) => n + (p.reference ? 2 : 1), 0) + sheet.crops.reduce((n, c) => n + (c.reference ? 2 : 1), 0);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Bring a sheet to at most `max` pictures: the views in `CRITIC_SHEET_DROP_ORDER`, one at a time; then the crops from the
|
|
201
|
+
* last down to the fewest (`CRITIC_CROPS.min`); then, only if still over, the remaining pairs from the last, never the
|
|
202
|
+
* opening or a full page. Every step is recorded in `dropped`.
|
|
203
|
+
*/
|
|
204
|
+
function fitSheet(pairs: SheetPair[], crops: SheetCrop[], max: number): string[] {
|
|
205
|
+
const dropped: string[] = [];
|
|
206
|
+
const over = () => sheetImageCount({ pairs, crops }) > max;
|
|
207
|
+
const dropPair = (width: CaptureWidth, view: CaptureView) => {
|
|
208
|
+
const i = pairs.findIndex(p => p.width === width && p.view === view);
|
|
209
|
+
if (i < 0) return;
|
|
210
|
+
pairs.splice(i, 1);
|
|
211
|
+
dropped.push(`${width}/${view}`);
|
|
212
|
+
};
|
|
213
|
+
for (const [width, view] of CRITIC_SHEET_DROP_ORDER) {
|
|
214
|
+
if (!over()) return dropped;
|
|
215
|
+
dropPair(width, view);
|
|
216
|
+
}
|
|
217
|
+
while (over() && crops.length > CRITIC_CROPS.min) dropped.push(`crop: ${crops.pop()!.why}`);
|
|
218
|
+
const kept = (p: SheetPair) => SHEET_KEEPS.some(([w, v]) => p.width === w && p.view === v);
|
|
219
|
+
for (let i = pairs.length - 1; i >= 0 && over(); i--) if (!kept(pairs[i])) dropPair(pairs[i].width, pairs[i].view);
|
|
220
|
+
return dropped;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* The sheet for one page against one reference: every view both sides have, laptop first, in `CAPTURE_VIEW_ORDER` — and
|
|
225
|
+
* ours alone at a Scene stop the reference lacks (`OURS_ALONE_VIEWS`); then
|
|
226
|
+
* the crops — ours' flagged boxes first (distinct findings, at most `CRITIC_FLAGGED_CROPS`), then the recipes on both
|
|
227
|
+
* sides, up to the most (the recipes alone give the fewest). The header recipe uses the measured header box when ours has one.
|
|
228
|
+
* Then the sheet is brought to `maxImages` pictures (`CRITIC_SHEET_MAX_IMAGES`; `fitSheet`'s order).
|
|
229
|
+
*/
|
|
230
|
+
export function planCritiqueSheet(ours: CaptureSet, reference: CaptureSet, maxImages: number = CRITIC_SHEET_MAX_IMAGES): CritiqueSheet {
|
|
231
|
+
const pairs: SheetPair[] = [];
|
|
232
|
+
const missing: string[] = [];
|
|
233
|
+
for (const width of Object.values(CaptureWidth)) {
|
|
234
|
+
for (const view of CAPTURE_VIEW_ORDER) {
|
|
235
|
+
const o = shotOf(ours, width, view);
|
|
236
|
+
const r = shotOf(reference, width, view);
|
|
237
|
+
if (o && r) pairs.push({ width, view, reference: r, ours: o });
|
|
238
|
+
else if (o && OURS_ALONE_VIEWS.includes(view)) pairs.push({ width, view, ours: o });
|
|
239
|
+
else if (o || r) missing.push(`${width}/${view}: no ${o ? 'reference' : 'page'} shot`);
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
const crops: SheetCrop[] = [];
|
|
243
|
+
const seen = new Set<string>();
|
|
244
|
+
for (const width of Object.values(CaptureWidth)) {
|
|
245
|
+
for (const f of ours.metrics?.[width]?.flagged ?? []) {
|
|
246
|
+
const shot = shotOf(ours, width, f.view);
|
|
247
|
+
if (!shot || crops.length >= CRITIC_FLAGGED_CROPS || seen.has(f.why)) continue;
|
|
248
|
+
seen.add(f.why);
|
|
249
|
+
const box = clip(shot, f.box);
|
|
250
|
+
crops.push({ width, view: f.view, why: f.why, ours: { ref: shot.ref, box }, zoom: zoomOf(box) });
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
for (const recipe of CRITIC_CROP_RECIPES) {
|
|
254
|
+
if (crops.length >= CRITIC_CROPS.max) break;
|
|
255
|
+
const o = shotOf(ours, recipe.width, recipe.view);
|
|
256
|
+
const r = shotOf(reference, recipe.width, recipe.view);
|
|
257
|
+
if (!o || !r) continue;
|
|
258
|
+
const header = recipe === CRITIC_CROP_RECIPES[0] ? ours.metrics?.[recipe.width]?.header : undefined;
|
|
259
|
+
const box = clip(o, header
|
|
260
|
+
? { x: header.x - CROP_MARGIN, y: Math.max(0, header.y - CROP_MARGIN), w: header.w + 2 * CROP_MARGIN, h: header.h + 2 * CROP_MARGIN }
|
|
261
|
+
: fraction(o, recipe.box));
|
|
262
|
+
crops.push({ width: recipe.width, view: recipe.view, why: recipe.why, ours: { ref: o.ref, box }, reference: { ref: r.ref, box: clip(r, fraction(r, recipe.box)) }, zoom: zoomOf(box) });
|
|
263
|
+
}
|
|
264
|
+
const dropped = fitSheet(pairs, crops, maxImages);
|
|
265
|
+
const referenceImageTokens = pairs.reduce((n, p) => n + (p.reference ? visionImageTokens(p.reference.w, p.reference.h) : 0), 0);
|
|
266
|
+
const pairTokens = referenceImageTokens + pairs.reduce((n, p) => n + visionImageTokens(p.ours.w, p.ours.h), 0);
|
|
267
|
+
const cropTokens = crops.reduce((n, c) => n + visionImageTokens(c.ours.box.w * c.zoom, c.ours.box.h * c.zoom)
|
|
268
|
+
+ (c.reference ? visionImageTokens(c.reference.box.w * c.zoom, c.reference.box.h * c.zoom) : 0), 0);
|
|
269
|
+
return { pairs, crops, missing, dropped, imageTokens: pairTokens + cropTokens, referenceImageTokens };
|
|
270
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { CRITIC_RUBRIC_DIMENSIONS, CRITIC_RUBRIC_POLISH } from './critic-rubric.generated';
|
|
2
|
+
import { jsonBoolean, jsonClosedObject, jsonListOf, JsonSchema, jsonText } from './json-schema';
|
|
3
|
+
import { isPlainObject, PathIssue } from './shape-check';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* THE AI DESIGNER'S CRITIC — its answer (ai-designer-plan §2d, AD3, AD-D18). Each round the critic reads the sheet (the
|
|
7
|
+
* reference beside ours, view by view, and zoomed crops) and answers ONE strict object: a score 0–10 and one line of
|
|
8
|
+
* evidence for each of the reference score's eight dimensions (`team/reference-score.md` §2, ported — never retyped —
|
|
9
|
+
* into `critic-rubric.generated.ts`), the polish bugs it saw (a bug a visitor would call broken caps the page), and the
|
|
10
|
+
* 1–3 changes that move the lowest score most, written as a brief for the revise step. The arithmetic — the design mean,
|
|
11
|
+
* the cap, the headline — is this file's, never the model's. Pure.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
/** The eight dimensions, by the key the critic answers under — the rubric's order (a spec holds it to the port). */
|
|
15
|
+
export enum CriticDimension {
|
|
16
|
+
Colour = 'colour',
|
|
17
|
+
Type = 'type',
|
|
18
|
+
Composition = 'composition',
|
|
19
|
+
Imagery = 'imagery',
|
|
20
|
+
Header = 'header',
|
|
21
|
+
Footer = 'footer',
|
|
22
|
+
Motion = 'motion',
|
|
23
|
+
Polish = 'polish',
|
|
24
|
+
}
|
|
25
|
+
export const CRITIC_DIMENSIONS: ReadonlyArray<CriticDimension> = Object.values(CriticDimension);
|
|
26
|
+
/** Dimensions 1–7: the headline is their mean. */
|
|
27
|
+
export const CRITIC_DESIGN_DIMENSIONS: ReadonlyArray<CriticDimension> = CRITIC_DIMENSIONS.filter(d => d !== CriticDimension.Polish);
|
|
28
|
+
/** A score is 0–10 in half points, as the tester scores. */
|
|
29
|
+
export const CRITIC_SCORE = { min: 0, max: 10, step: 0.5 } as const;
|
|
30
|
+
/** How many changes a critique gives the revise step. */
|
|
31
|
+
export const CRITIC_CHANGES = { min: 1, max: 3 } as const;
|
|
32
|
+
/** The answer's format name (the request's output). */
|
|
33
|
+
export const CRITIC_OUTPUT_NAME = 'critique';
|
|
34
|
+
|
|
35
|
+
export interface CriticScore {
|
|
36
|
+
score: number;
|
|
37
|
+
/** One line, read off the sheet as a position, a size or a colour: "<reference> does X; ours does Y". */
|
|
38
|
+
evidence: string;
|
|
39
|
+
}
|
|
40
|
+
export interface CriticBug {
|
|
41
|
+
what: string;
|
|
42
|
+
/** A visitor would call it broken (a 404, text over text, a dead button): the page is capped. */
|
|
43
|
+
broken: boolean;
|
|
44
|
+
}
|
|
45
|
+
export interface CriticChange {
|
|
46
|
+
dimension: CriticDimension;
|
|
47
|
+
/** What the revise step should do, in our own terms — never "make it look like the reference". */
|
|
48
|
+
brief: string;
|
|
49
|
+
}
|
|
50
|
+
export interface CriticAnswer {
|
|
51
|
+
scores: Record<CriticDimension, CriticScore>;
|
|
52
|
+
bugs: CriticBug[];
|
|
53
|
+
changes: CriticChange[];
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The critic's strict output format: every property required, every object closed (`strictSchemaComplexity`). */
|
|
57
|
+
export function criticAnswerSchema(): JsonSchema {
|
|
58
|
+
const score = jsonClosedObject(
|
|
59
|
+
{ score: { type: 'number', description: `0–10 in half points.` }, evidence: { ...jsonText(), description: 'One line read off the sheet: a position, a size or a colour, the reference\'s and ours.' } },
|
|
60
|
+
['score', 'evidence'],
|
|
61
|
+
);
|
|
62
|
+
const byName = Object.fromEntries(CRITIC_RUBRIC_DIMENSIONS.map(d => [d.key, { ...score, description: `${d.name}: ${d.compares}` }]));
|
|
63
|
+
return jsonClosedObject({
|
|
64
|
+
scores: jsonClosedObject(byName, CRITIC_RUBRIC_DIMENSIONS.map(d => d.key), 'One score per dimension of the rubric.'),
|
|
65
|
+
bugs: jsonListOf(jsonClosedObject({ what: jsonText(), broken: jsonBoolean() }, ['what', 'broken'], 'A polish bug; broken = a visitor would call it broken.')),
|
|
66
|
+
changes: jsonListOf(jsonClosedObject(
|
|
67
|
+
{ dimension: { type: 'string', enum: [...CRITIC_DIMENSIONS] }, brief: jsonText() }, ['dimension', 'brief'],
|
|
68
|
+
`${CRITIC_CHANGES.min}–${CRITIC_CHANGES.max} changes that move the lowest score most, as a brief for the next round.`,
|
|
69
|
+
)),
|
|
70
|
+
}, ['scores', 'bugs', 'changes'], 'The critique of one page.');
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export enum CriticIssueCode {
|
|
74
|
+
/** Not the answer's shape. */
|
|
75
|
+
Shape = 'shape',
|
|
76
|
+
/** A score outside 0–10 or not in half points. */
|
|
77
|
+
Range = 'range',
|
|
78
|
+
/** Evidence that is not one line read off the sheet: no number where the rubric measures in numbers, else not ours. */
|
|
79
|
+
Evidence = 'evidence',
|
|
80
|
+
/** Not 1–3 changes, or none aimed at the lowest score. */
|
|
81
|
+
Changes = 'changes',
|
|
82
|
+
/** A brief that asks for resemblance (AD-D18): the reference's name, "copy", "look like". */
|
|
83
|
+
Likeness = 'likeness',
|
|
84
|
+
}
|
|
85
|
+
export type CriticIssue = PathIssue<CriticIssueCode>;
|
|
86
|
+
|
|
87
|
+
export interface CriticContext {
|
|
88
|
+
/** The reference the page is scored against (its name, as the cards are named: `graya-institute`). */
|
|
89
|
+
reference: string;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** A measurement: a number (a size, a position, a share) or a hex colour. */
|
|
93
|
+
const MEASURED = /\d/;
|
|
94
|
+
/** The comparison named: the line says what OURS does (the critic answers in English, as its instructions are). */
|
|
95
|
+
const COMPARED = /\bours?\b/i;
|
|
96
|
+
/** The dimensions the rubric measures in numbers (their row says "Numbers: …"): their evidence must hold one. The rest —
|
|
97
|
+
* the header, the footer, motion, polish — are read as behaviour; a line naming ours (or a number) is evidence. */
|
|
98
|
+
const MEASURED_DIMENSIONS: ReadonlySet<string> = new Set(CRITIC_RUBRIC_DIMENSIONS.filter(d => /\bNumbers:/.test(d.compares)).map(d => d.key));
|
|
99
|
+
/** Asking for likeness. "copy" alone is text (the hero copy, body copy) — only copying a thing is likeness. */
|
|
100
|
+
const LIKENESS_WORDS = /\b(cop(?:y|ies|ying) (?:it|its|them|their|the|this|that)\b|mimic|replicate|imitate|clone|look(?:s|ing)? like|same as|just like)/i;
|
|
101
|
+
const MIN_NAME_PART = 4;
|
|
102
|
+
|
|
103
|
+
/** The words of a reference's name a brief may not say (`graya-institute` → graya, institute). */
|
|
104
|
+
const nameParts = (reference: string) => reference.toLowerCase().split(/[^a-z0-9]+/).filter(p => p.length >= MIN_NAME_PART);
|
|
105
|
+
|
|
106
|
+
/** Why an answer is not a usable critique, each reason with its path. The one gate between the model and the loop. */
|
|
107
|
+
export function criticAnswerIssues(answer: unknown, ctx: CriticContext): CriticIssue[] {
|
|
108
|
+
const out: CriticIssue[] = [];
|
|
109
|
+
const say = (code: CriticIssueCode, path: string, message: string) => out.push({ code, path, message });
|
|
110
|
+
if (!isPlainObject(answer) || !isPlainObject(answer['scores']) || !Array.isArray(answer['bugs']) || !Array.isArray(answer['changes'])) {
|
|
111
|
+
say(CriticIssueCode.Shape, '', 'a critique is { scores, bugs, changes }');
|
|
112
|
+
return out;
|
|
113
|
+
}
|
|
114
|
+
const scores = answer['scores'];
|
|
115
|
+
for (const d of CRITIC_DIMENSIONS) {
|
|
116
|
+
const s = scores[d];
|
|
117
|
+
const path = `scores.${d}`;
|
|
118
|
+
if (!isPlainObject(s) || typeof s['score'] !== 'number' || typeof s['evidence'] !== 'string') { say(CriticIssueCode.Shape, path, 'a score and its evidence'); continue; }
|
|
119
|
+
const v = s['score'];
|
|
120
|
+
if (v < CRITIC_SCORE.min || v > CRITIC_SCORE.max || !Number.isInteger(v / CRITIC_SCORE.step)) say(CriticIssueCode.Range, `${path}.score`, `0–10 in half points, not ${v}`);
|
|
121
|
+
const evidence = s['evidence'].trim();
|
|
122
|
+
const read = MEASURED.test(evidence) || (!MEASURED_DIMENSIONS.has(d) && COMPARED.test(evidence));
|
|
123
|
+
if (!evidence || /\n/.test(evidence) || !read) {
|
|
124
|
+
say(CriticIssueCode.Evidence, `${path}.evidence`, 'one line read off the sheet — a position, a size or a colour, the reference\'s and ours');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
const bugs = answer['bugs'] as unknown[];
|
|
128
|
+
bugs.forEach((b, i) => {
|
|
129
|
+
if (!isPlainObject(b) || typeof b['what'] !== 'string' || typeof b['broken'] !== 'boolean') say(CriticIssueCode.Shape, `bugs[${i}]`, 'a bug is { what, broken }');
|
|
130
|
+
});
|
|
131
|
+
const changes = answer['changes'] as unknown[];
|
|
132
|
+
if (changes.length < CRITIC_CHANGES.min || changes.length > CRITIC_CHANGES.max) say(CriticIssueCode.Changes, 'changes', `${CRITIC_CHANGES.min}–${CRITIC_CHANGES.max} changes, not ${changes.length}`);
|
|
133
|
+
const names = nameParts(ctx.reference);
|
|
134
|
+
changes.forEach((c, i) => {
|
|
135
|
+
const path = `changes[${i}]`;
|
|
136
|
+
if (!isPlainObject(c) || !CRITIC_DIMENSIONS.includes(c['dimension'] as CriticDimension) || typeof c['brief'] !== 'string' || !c['brief'].trim()) {
|
|
137
|
+
say(CriticIssueCode.Shape, path, 'a change is { dimension, brief }');
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const brief = c['brief'].toLowerCase();
|
|
141
|
+
const named = names.find(n => new RegExp(`\\b${n}\\b`).test(brief));
|
|
142
|
+
if (named || LIKENESS_WORDS.test(brief)) {
|
|
143
|
+
say(CriticIssueCode.Likeness, `${path}.brief`, 'a brief asks for the level, in our own terms — never the reference by name, never to copy or look like it (AD-D18)');
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
if (out.length) return out;
|
|
147
|
+
const lowest = lowestDimensions(answer as unknown as CriticAnswer);
|
|
148
|
+
// Every bug travels to the revise step on its own line (`roundBrief`), so a listed bug is a change aimed at polish.
|
|
149
|
+
const aimed = new Set((changes as CriticChange[]).map(c => c.dimension));
|
|
150
|
+
if (bugs.length) aimed.add(CriticDimension.Polish);
|
|
151
|
+
if (!lowest.some(d => aimed.has(d))) {
|
|
152
|
+
say(CriticIssueCode.Changes, 'changes', `no change is aimed at the lowest score (${lowest.join(', ')})`);
|
|
153
|
+
}
|
|
154
|
+
return out;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** The dimensions holding the lowest score (ties together), polish as the rubric's arithmetic leaves it. */
|
|
158
|
+
export function lowestDimensions(answer: CriticAnswer): CriticDimension[] {
|
|
159
|
+
const score = (d: CriticDimension) => (d === CriticDimension.Polish ? polishOf(answer) : answer.scores[d].score);
|
|
160
|
+
const low = Math.min(...CRITIC_DIMENSIONS.map(score));
|
|
161
|
+
return CRITIC_DIMENSIONS.filter(d => score(d) === low);
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Polish by the rubric's arithmetic: the critic's score, never above what its bugs leave (each costs
|
|
165
|
+
* `CRITIC_RUBRIC_POLISH.bugPenalty`), never below 0. The model's count is not refused for a slip of arithmetic — the
|
|
166
|
+
* file does the sum (AD3 calibration: 6 of 48 answers were refused for a polish above it). */
|
|
167
|
+
export function polishOf(answer: CriticAnswer): number {
|
|
168
|
+
const allowed = CRITIC_SCORE.max - CRITIC_RUBRIC_POLISH.bugPenalty * answer.bugs.length;
|
|
169
|
+
return Math.max(CRITIC_SCORE.min, Math.min(answer.scores[CriticDimension.Polish].score, allowed));
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export interface CriticVerdict {
|
|
173
|
+
/** The mean of dimensions 1–7. */
|
|
174
|
+
designMean: number;
|
|
175
|
+
polish: number;
|
|
176
|
+
/** How many bugs a visitor would call broken. */
|
|
177
|
+
broken: number;
|
|
178
|
+
/** The rubric's headline: the design mean, capped when a bug is broken. */
|
|
179
|
+
headline: number;
|
|
180
|
+
capped: boolean;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
/** What a critique comes to, by the rubric's rule (`CRITIC_RUBRIC_HEADLINE`): the mean of 1–7, capped by a broken bug. */
|
|
184
|
+
export function criticVerdict(answer: CriticAnswer): CriticVerdict {
|
|
185
|
+
const designMean = CRITIC_DESIGN_DIMENSIONS.reduce((sum, d) => sum + answer.scores[d].score, 0) / CRITIC_DESIGN_DIMENSIONS.length;
|
|
186
|
+
const broken = answer.bugs.filter(b => b.broken).length;
|
|
187
|
+
const capped = broken > 0 && designMean > CRITIC_RUBRIC_POLISH.brokenCap;
|
|
188
|
+
return { designMean, polish: polishOf(answer), broken, headline: capped ? CRITIC_RUBRIC_POLISH.brokenCap : designMean, capped };
|
|
189
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { DesignDoc } from './design-ops.model';
|
|
2
|
+
import type { SerializedNode } from './serialized-node';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where each node of a design document sits (AD1): the node, the list that holds it (the page's layout, the site's
|
|
6
|
+
* globals, or a parent's children) and that parent. `applyDesignOps` keeps it as it works; the static check reads it.
|
|
7
|
+
*/
|
|
8
|
+
export interface DesignNodePlace {
|
|
9
|
+
node: SerializedNode;
|
|
10
|
+
list: SerializedNode[];
|
|
11
|
+
parent: SerializedNode | null;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export class DesignDocIndex {
|
|
15
|
+
private readonly places = new Map<string, DesignNodePlace>();
|
|
16
|
+
|
|
17
|
+
constructor(readonly doc: DesignDoc) {
|
|
18
|
+
this.rebuild();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Index every node again (after a move, a removal or a wrap). */
|
|
22
|
+
rebuild(): void {
|
|
23
|
+
this.places.clear();
|
|
24
|
+
this.addList(this.doc.layout, null);
|
|
25
|
+
this.addList(this.doc.globals, null);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Index a node and its subtree, just inserted into `list` under `parent`. */
|
|
29
|
+
add(node: SerializedNode, list: SerializedNode[], parent: SerializedNode | null): void {
|
|
30
|
+
this.places.set(node.id, { node, list, parent });
|
|
31
|
+
if (node.children?.length) this.addList(node.children, node);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
find(id: string): DesignNodePlace | undefined {
|
|
35
|
+
return this.places.get(id);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
has(id: string): boolean {
|
|
39
|
+
return this.places.has(id);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Every node, in no promised order. */
|
|
43
|
+
nodes(): SerializedNode[] {
|
|
44
|
+
return [...this.places.values()].map(p => p.node);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Whether `id` is `ancestor` or sits inside it. */
|
|
48
|
+
within(id: string, ancestor: string): boolean {
|
|
49
|
+
for (let at = this.places.get(id); at; at = at.parent ? this.places.get(at.parent.id) : undefined) {
|
|
50
|
+
if (at.node.id === ancestor) return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
private addList(list: SerializedNode[], parent: SerializedNode | null): void {
|
|
56
|
+
for (const node of list) this.add(node, list, parent);
|
|
57
|
+
}
|
|
58
|
+
}
|