ui-director-skill 2.0.0 → 3.0.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.
Files changed (58) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/INSTALL.md +47 -18
  3. package/README.md +34 -31
  4. package/SKILL.md +14 -9
  5. package/assets/bundle-profiles.json +178 -0
  6. package/assets/capabilities.json +259 -0
  7. package/assets/install-manifest.json +27 -0
  8. package/assets/project-profile.example.json +23 -0
  9. package/assets/routing-rules.json +24 -0
  10. package/assets/upstreams.json +100 -0
  11. package/benchmark/README.md +54 -0
  12. package/benchmark/blind.mjs +141 -0
  13. package/benchmark/cases.json +66 -0
  14. package/benchmark/fixtures/reference.html +39 -0
  15. package/bin/ui.mjs +53 -10
  16. package/examples/usage.md +19 -50
  17. package/install.py +304 -0
  18. package/lib/core.mjs +8 -3
  19. package/lib/workflows.mjs +151 -29
  20. package/package.json +8 -3
  21. package/references/delivery-contract.md +5 -0
  22. package/references/design-intelligence.md +2 -0
  23. package/references/integrations/security-policy.md +2 -0
  24. package/references/integrations/skill-manager.md +5 -0
  25. package/references/integrations/upstream-adapters.md +25 -0
  26. package/references/integrations.md +2 -0
  27. package/references/motion-interaction.md +2 -0
  28. package/references/orchestration/context-management.md +14 -0
  29. package/references/orchestration/iteration-loop.md +9 -0
  30. package/references/orchestration/routing.md +13 -0
  31. package/references/platforms/desktop.md +3 -0
  32. package/references/platforms/hmi.md +5 -0
  33. package/references/platforms/mobile.md +3 -0
  34. package/references/platforms/web.md +3 -0
  35. package/references/quality-assurance.md +2 -0
  36. package/references/routing.md +2 -27
  37. package/references/stages/design-research.md +2 -0
  38. package/references/stages/design-system.md +7 -0
  39. package/references/stages/deslop.md +3 -0
  40. package/references/stages/motion-interaction.md +31 -0
  41. package/references/stages/prototyping.md +2 -0
  42. package/references/stages/ux-strategy.md +10 -0
  43. package/references/stages/visual-direction.md +13 -0
  44. package/references/stages/visual-validation.md +25 -0
  45. package/references/visual-direction.md +2 -0
  46. package/skill_manager.py +657 -0
  47. package/templates/DECISIONS.md +2 -3
  48. package/templates/DESIGN.md +9 -10
  49. package/templates/PRODUCT.md +5 -4
  50. package/templates/REVIEW.md +13 -10
  51. package/config/optional-skills.json +0 -16
  52. package/config/quality-rubric.json +0 -13
  53. package/config/workflows.json +0 -15
  54. package/references/design-workflows.md +0 -21
  55. package/references/platforms.md +0 -17
  56. package/references/project-inspection.md +0 -11
  57. package/references/quality-gates.md +0 -16
  58. package/references/specialists.md +0 -9
@@ -0,0 +1,259 @@
1
+ [
2
+ {
3
+ "id": "pro-max",
4
+ "skill": "ui-ux-pro-max",
5
+ "aliases": [
6
+ "ui-ux-pro-max"
7
+ ],
8
+ "source": "https://github.com/nextlevelbuilder/ui-ux-pro-max-skill",
9
+ "capabilities": [
10
+ "research",
11
+ "system"
12
+ ],
13
+ "platforms": [
14
+ "web",
15
+ "mobile",
16
+ "desktop"
17
+ ],
18
+ "notes": "Design knowledge",
19
+ "version": null
20
+ },
21
+ {
22
+ "id": "frontend",
23
+ "skill": "frontend-design",
24
+ "aliases": [
25
+ "frontend-design"
26
+ ],
27
+ "source": "https://github.com/anthropics/skills",
28
+ "capabilities": [
29
+ "visual"
30
+ ],
31
+ "platforms": [
32
+ "web"
33
+ ],
34
+ "notes": "General distinctive web UI; do not apply CSS to native",
35
+ "version": null
36
+ },
37
+ {
38
+ "id": "taste",
39
+ "skill": "design-taste-frontend",
40
+ "aliases": [
41
+ "design-taste-frontend",
42
+ "taste-skill"
43
+ ],
44
+ "source": "https://github.com/Leonxlnx/taste-skill",
45
+ "capabilities": [
46
+ "visual"
47
+ ],
48
+ "platforms": [
49
+ "web"
50
+ ],
51
+ "notes": "Brand/marketing website specialist; discover actual current instructions",
52
+ "version": null
53
+ },
54
+ {
55
+ "id": "taste-classics",
56
+ "skill": "taste-skill-classics",
57
+ "aliases": [
58
+ "high-end-visual-design",
59
+ "minimalist-ui",
60
+ "industrial-brutalist-ui"
61
+ ],
62
+ "source": "https://github.com/Leonxlnx/taste-skill-classics",
63
+ "capabilities": [
64
+ "visual"
65
+ ],
66
+ "platforms": [
67
+ "web"
68
+ ],
69
+ "notes": "Legacy style options, only if requested; verify provenance/version",
70
+ "version": null
71
+ },
72
+ {
73
+ "id": "hallmark",
74
+ "skill": "hallmark",
75
+ "aliases": [
76
+ "hallmark"
77
+ ],
78
+ "source": "https://github.com/Nutlope/hallmark",
79
+ "capabilities": [
80
+ "system"
81
+ ],
82
+ "platforms": [
83
+ "web"
84
+ ],
85
+ "notes": "Web design-system consistency checks",
86
+ "version": null
87
+ },
88
+ {
89
+ "id": "unslop",
90
+ "skill": "unslop",
91
+ "aliases": [
92
+ "unslop"
93
+ ],
94
+ "source": "https://github.com/heydamir/unslop",
95
+ "capabilities": [
96
+ "qa"
97
+ ],
98
+ "platforms": [
99
+ "web"
100
+ ],
101
+ "notes": "Optional targeted cleanup guidance",
102
+ "version": null
103
+ },
104
+ {
105
+ "id": "impeccable",
106
+ "skill": "impeccable",
107
+ "aliases": [
108
+ "impeccable"
109
+ ],
110
+ "source": "https://github.com/pbakaus/impeccable",
111
+ "capabilities": [
112
+ "qa"
113
+ ],
114
+ "platforms": [
115
+ "web"
116
+ ],
117
+ "notes": "Focused design critique and refinement",
118
+ "version": null
119
+ },
120
+ {
121
+ "id": "emil",
122
+ "skill": "animate",
123
+ "aliases": [
124
+ "animate",
125
+ "review-animations",
126
+ "animation-performance",
127
+ "emil-design-eng",
128
+ "ask-emil",
129
+ "find-animation-opportunities"
130
+ ],
131
+ "source": "https://github.com/emilkowalski/skills",
132
+ "capabilities": [
133
+ "motion",
134
+ "motion-review"
135
+ ],
136
+ "platforms": [
137
+ "web"
138
+ ],
139
+ "entryCapabilities": {
140
+ "animate": ["motion"],
141
+ "review-animations": ["motion-review"],
142
+ "animation-performance": ["motion-review"],
143
+ "find-animation-opportunities": ["motion"]
144
+ },
145
+ "notes": "Motion and performance; native use principles only",
146
+ "version": null
147
+ },
148
+ {
149
+ "id": "vercel",
150
+ "skill": "web-design-guidelines",
151
+ "aliases": [
152
+ "web-design-guidelines"
153
+ ],
154
+ "source": "https://github.com/vercel-labs/agent-skills",
155
+ "capabilities": [
156
+ "qa"
157
+ ],
158
+ "platforms": [
159
+ "web"
160
+ ],
161
+ "notes": "Web UX and accessibility review",
162
+ "version": null
163
+ },
164
+ {
165
+ "id": "stitch",
166
+ "skill": "stitch",
167
+ "aliases": [
168
+ "stitch",
169
+ "design-md",
170
+ "stitch-design"
171
+ ],
172
+ "source": "https://github.com/google-labs-code/stitch-skills",
173
+ "capabilities": [
174
+ "prototype"
175
+ ],
176
+ "platforms": [
177
+ "web"
178
+ ],
179
+ "notes": "Optional design conversion; requires available tools and permission",
180
+ "version": null
181
+ },
182
+ {
183
+ "id": "figma",
184
+ "skill": "figma-implement-design",
185
+ "aliases": [
186
+ "figma-implement-design",
187
+ "figma-generate-design",
188
+ "figma"
189
+ ],
190
+ "source": "https://github.com/openai/skills",
191
+ "capabilities": [
192
+ "prototype"
193
+ ],
194
+ "platforms": [
195
+ "web",
196
+ "mobile",
197
+ "desktop"
198
+ ],
199
+ "entryDeliverables": {
200
+ "figma-implement-design": ["implementation"],
201
+ "figma-generate-design": ["prototype"]
202
+ },
203
+ "notes": "Use actual Figma tools and authorization",
204
+ "version": null
205
+ },
206
+ {
207
+ "id": "playwright",
208
+ "skill": "playwright-interactive",
209
+ "aliases": [
210
+ "playwright-interactive",
211
+ "playwright",
212
+ "screenshot"
213
+ ],
214
+ "source": "https://github.com/openai/skills",
215
+ "capabilities": [
216
+ "baseline",
217
+ "qa"
218
+ ],
219
+ "platforms": [
220
+ "web"
221
+ ],
222
+ "notes": "Actual rendered evidence; desktop only if supported",
223
+ "version": null
224
+ },
225
+ {
226
+ "id": "design-qa",
227
+ "skill": "design-qa",
228
+ "aliases": [
229
+ "design-qa"
230
+ ],
231
+ "source": "https://github.com/openai/plugins",
232
+ "capabilities": [
233
+ "qa"
234
+ ],
235
+ "platforms": [
236
+ "web",
237
+ "mobile",
238
+ "desktop"
239
+ ],
240
+ "notes": "Reference vs implementation QA; runtime availability varies",
241
+ "version": null
242
+ },
243
+ {
244
+ "id": "cook",
245
+ "skill": "cook",
246
+ "aliases": [
247
+ "cook"
248
+ ],
249
+ "source": "https://github.com/Leonxlnx/cook",
250
+ "capabilities": [
251
+ "qa"
252
+ ],
253
+ "platforms": [
254
+ "web"
255
+ ],
256
+ "notes": "Optional inspiration for render/critique loop; core loop is independent",
257
+ "version": null
258
+ }
259
+ ]
@@ -0,0 +1,27 @@
1
+ {
2
+ "paths": [
3
+ "SKILL.md", "package.json", "install.py", "skill_manager.py",
4
+ "assets", "references", "bin", "lib", "config", "adapters", "templates"
5
+ ],
6
+ "required": [
7
+ "SKILL.md", "package.json", "install.py", "skill_manager.py",
8
+ "assets/install-manifest.json", "assets/capabilities.json",
9
+ "assets/routing-rules.json",
10
+ "assets/bundle-profiles.json", "assets/project-profile.example.json",
11
+ "bin/ui.mjs", "lib/core.mjs", "lib/workflows.mjs",
12
+ "config/providers.json", "config/capabilities.json",
13
+ "adapters/design-system.json", "adapters/impeccable.json",
14
+ "adapters/jakub-skills.json", "adapters/ui-ux-pro-max.json",
15
+ "references/delivery-contract.md",
16
+ "references/integrations/security-policy.md", "references/integrations/skill-manager.md",
17
+ "references/integrations/upstream-adapters.md",
18
+ "references/orchestration/context-management.md", "references/orchestration/iteration-loop.md",
19
+ "references/orchestration/routing.md",
20
+ "references/platforms/desktop.md", "references/platforms/mobile.md", "references/platforms/web.md", "references/platforms/hmi.md",
21
+ "references/stages/design-research.md", "references/stages/design-system.md",
22
+ "references/stages/ux-strategy.md", "references/stages/motion-interaction.md",
23
+ "references/stages/prototyping.md", "references/stages/visual-direction.md",
24
+ "references/stages/visual-validation.md",
25
+ "templates/DESIGN.md", "templates/PRODUCT.md", "templates/DECISIONS.md", "templates/REVIEW.md"
26
+ ]
27
+ }
@@ -0,0 +1,23 @@
1
+ {
2
+ "project": "Example Product",
3
+ "platform": "web",
4
+ "product_type": "SaaS dashboard",
5
+ "audience": "Operations users",
6
+ "primary_journey": "Find and act on high priority issues",
7
+ "brand_direction": "clear, restrained, information first",
8
+ "design_system": "DESIGN.md",
9
+ "implementation": "existing stack (do not replace)",
10
+ "constraints": [
11
+ "preserve existing API",
12
+ "desktop and mobile",
13
+ "Chinese and English"
14
+ ],
15
+ "success_criteria": [
16
+ "complete core flow",
17
+ "consistent tokens",
18
+ "review evidence"
19
+ ],
20
+ "schema_version": 2,
21
+ "product_spec": "PRODUCT.md",
22
+ "mode": "STANDARD"
23
+ }
@@ -0,0 +1,24 @@
1
+ {
2
+ "modes": ["QUICK", "STANDARD", "HIGH_FIDELITY"],
3
+ "modeAliases": {
4
+ "FAST": "QUICK",
5
+ "CRAFT": "HIGH_FIDELITY",
6
+ "REFERENCE": "HIGH_FIDELITY"
7
+ },
8
+ "intentAliases": {
9
+ "DESLOP": "CLEANUP"
10
+ },
11
+ "workflows": {
12
+ "AUDIT": ["qa"],
13
+ "LOCAL": ["baseline", "prototype", "qa"],
14
+ "MOTION": ["baseline", "motion", "motion-review", "qa"],
15
+ "SYSTEM": ["research", "system", "qa"],
16
+ "CLEANUP": ["baseline", "prototype", "qa"],
17
+ "POLISH": ["baseline", "ux", "system", "visual", "prototype", "qa"],
18
+ "REFERENCE": ["research", "ux", "system", "visual", "prototype", "qa"],
19
+ "NEW_SCREEN": ["research", "ux", "system", "visual", "prototype", "qa"],
20
+ "BRAND": ["research", "ux", "system", "visual", "prototype", "qa"]
21
+ },
22
+ "platforms": ["web", "mobile", "desktop", "hmi", "other"],
23
+ "deliverables": ["concept", "specification", "prototype", "implementation", "audit"]
24
+ }
@@ -0,0 +1,100 @@
1
+ [
2
+ {
3
+ "stage": "system",
4
+ "skill": "ui-ux-pro-max",
5
+ "source": "https://github.com/nextlevelbuilder/ui-ux-pro-max-skill",
6
+ "id": "pro-max",
7
+ "notes": "Design knowledge"
8
+ },
9
+ {
10
+ "stage": "visual",
11
+ "skill": "frontend-design",
12
+ "source": "https://github.com/anthropics/skills",
13
+ "id": "frontend",
14
+ "notes": "General distinctive web UI; do not apply CSS to native"
15
+ },
16
+ {
17
+ "stage": "visual",
18
+ "skill": "design-taste-frontend",
19
+ "source": "https://github.com/Leonxlnx/taste-skill",
20
+ "id": "taste",
21
+ "notes": "Brand/marketing website specialist; discover actual current instructions"
22
+ },
23
+ {
24
+ "stage": "visual",
25
+ "skill": "taste-skill-classics",
26
+ "source": "https://github.com/Leonxlnx/taste-skill-classics",
27
+ "id": "taste-classics",
28
+ "notes": "Legacy style options, only if requested; verify provenance/version"
29
+ },
30
+ {
31
+ "stage": "research",
32
+ "skill": "hallmark",
33
+ "source": "https://github.com/Nutlope/hallmark",
34
+ "id": "hallmark",
35
+ "notes": "Reference extraction, token governance and critique"
36
+ },
37
+ {
38
+ "stage": "deslop",
39
+ "skill": "unslop",
40
+ "source": "https://github.com/heydamir/unslop",
41
+ "id": "unslop",
42
+ "notes": "Anti-template refinement; verify installed entry name"
43
+ },
44
+ {
45
+ "stage": "baseline",
46
+ "skill": "impeccable",
47
+ "source": "https://github.com/pbakaus/impeccable",
48
+ "id": "impeccable",
49
+ "notes": "Design audit, refinement and visual checks"
50
+ },
51
+ {
52
+ "stage": "motion",
53
+ "skill": "animate",
54
+ "source": "https://github.com/emilkowalski/skills",
55
+ "id": "emil",
56
+ "notes": "Motion and performance; native use principles only"
57
+ },
58
+ {
59
+ "stage": "qa",
60
+ "skill": "web-design-guidelines",
61
+ "source": "https://github.com/vercel-labs/agent-skills",
62
+ "id": "vercel",
63
+ "notes": "Web UX and accessibility review"
64
+ },
65
+ {
66
+ "stage": "research",
67
+ "skill": "stitch",
68
+ "source": "https://github.com/google-labs-code/stitch-skills",
69
+ "id": "stitch",
70
+ "notes": "Optional design conversion; requires available tools and permission"
71
+ },
72
+ {
73
+ "stage": "research",
74
+ "skill": "figma-implement-design",
75
+ "source": "https://github.com/openai/skills",
76
+ "id": "figma",
77
+ "notes": "Use actual Figma tools and authorization"
78
+ },
79
+ {
80
+ "stage": "baseline",
81
+ "skill": "playwright-interactive",
82
+ "source": "https://github.com/openai/skills",
83
+ "id": "playwright",
84
+ "notes": "Actual rendered evidence; desktop only if supported"
85
+ },
86
+ {
87
+ "stage": "qa",
88
+ "skill": "design-qa",
89
+ "source": "https://github.com/openai/plugins",
90
+ "id": "design-qa",
91
+ "notes": "Reference vs implementation QA; runtime availability varies"
92
+ },
93
+ {
94
+ "stage": "research",
95
+ "skill": "cook",
96
+ "source": "https://github.com/Leonxlnx/cook",
97
+ "id": "cook",
98
+ "notes": "Optional inspiration for render/critique loop; core loop is independent"
99
+ }
100
+ ]
@@ -0,0 +1,54 @@
1
+ # Design benchmark
2
+
3
+ Compare actual interfaces under controlled conditions. [cases.json](cases.json) fixes briefs, target environments, capture states and task checks for Web, native mobile, desktop and Cocos HMI.
4
+
5
+ | Group | Guidance in the design agent's fresh context |
6
+ | --- | --- |
7
+ | A | No design skill |
8
+ | B | One matching design Skill chosen and pinned for the case |
9
+ | D | UI Director core |
10
+ | E | UI Director with a project Skill list and a multi-specialist workflow |
11
+
12
+ Start with `market-analysis` for Chromium Web, `mobile-notification-preferences` for native Android or `desktop-download-queue` for a desktop app.
13
+
14
+ ## Run a comparison
15
+
16
+ 1. Freeze model, settings, task prompt, seed contents, initial project, tool access, runtime and total budget per case. Pin the available Skill versions. Use fresh isolated tasks and randomize run order. Run each group at least twice for a full comparison. Select a case with at least two eligible specialists for group E. Record the project list, actual assignments and at least one adopted handoff in the examiner's records. Document any unavailable group and report a partial comparison.
17
+ 2. Give only the case prompt, platform constraints, target sizes and required input assets to the design agent. For reference matching, render [the supplied fixture](fixtures/reference.html) at 1440×900 and distribute the same screenshot to each design agent. Give them the screenshot only. Keep the capture state list and examiner scripts with the reviewer.
18
+ 3. Launch each result on its target surface. Use comparable state, viewport or window size, scale, content and input. Exercise the case checks on the running artifact. Save real PNGs with the filenames and dimensions in `captures`. Use browser DPR 1 for Web. On mobile and desktop use the same target runtime and capture scale across all groups.
19
+ 4. Keep each attempted run in a subdirectory of a common input folder. Include its PNGs and a `run.json` similar to the example below. For each unavailable PNG, record its state and reason in `missingCaptures`. Those attempts remain in the private manifest. Use `PASS`, `FAIL` or `NOT VERIFIED` per task check. Set unavailable measurements to `null` and explain them in `metricsNote`. Group E records the actual `specialists` and an adopted handoff, or records the reason in `combinationFailure`.
20
+ 5. Build a randomized blind review packet. Give the Critic only `output/review` and the case's reference image when applicable. Keep `output/private.json` with the examiner until judgments are recorded. Ask the Critic to report usability and visual findings using image IDs. After revealing the groups, compare actual behavior, component and Token reuse, incomplete runs, duration, calls and repairs. Compare D with A and B and E with D. Describe the repeated results and the limits of any exploratory run.
21
+
22
+ ```bash
23
+ node benchmark/blind.mjs market-analysis ./runs ./output
24
+ ```
25
+
26
+ Use `--pilot` for an intentionally incomplete comparison of two or more groups. The manifest also records `pilot: true` if a group has no screenshots to review or no E trial with an adopted handoff has screenshots. Keep these observations separate from replicated findings. Check the review packet for accidental group disclosure.
27
+
28
+ ```json
29
+ {
30
+ "group": "E",
31
+ "trial": 1,
32
+ "environment": {
33
+ "model": "record exact model",
34
+ "settings": "record common model settings",
35
+ "project": "record starter project revision and fixture data",
36
+ "tools": "record common tools and versions",
37
+ "runtime": "record target runtime, density and input",
38
+ "budget": "record common time and token budget"
39
+ },
40
+ "metrics": {"tokens": null, "toolCalls": null, "durationSeconds": 142, "repairCount": 1},
41
+ "metricsNote": "This host did not report token or tool-call counts.",
42
+ "specialists": ["product-tokens", "studio-layout"],
43
+ "handoffs": [
44
+ {"from": "product-tokens", "to": "studio-layout", "adopted": "The screen uses the existing comparison card and the specified warning token."}
45
+ ],
46
+ "taskResults": [
47
+ {"status": "PASS", "observation": "Observed ARB and SES with prices, returns and volume."},
48
+ {"status": "FAIL", "observation": "Retry reset the Technology filter."},
49
+ {"status": "NOT VERIFIED", "observation": "Keyboard flow was not exercised."}
50
+ ]
51
+ }
52
+ ```
53
+
54
+ The packet generator checks PNG structure, dimensions and run records. Judge quality from the actual runtime checks and visual review. Report task completion, critical defects, screenshot evidence and costs separately.
@@ -0,0 +1,141 @@
1
+ import { randomInt } from 'node:crypto';
2
+ import { mkdirSync, readFileSync, readdirSync, writeFileSync } from 'node:fs';
3
+ import { join } from 'node:path';
4
+
5
+ const cases = JSON.parse(readFileSync(new URL('./cases.json', import.meta.url), 'utf8'));
6
+ const groups = ['A', 'B', 'D', 'E'];
7
+ const statuses = ['PASS', 'FAIL', 'NOT VERIFIED'];
8
+ const conditionFields = ['model', 'settings', 'project', 'tools', 'runtime', 'budget'];
9
+ const costFields = ['tokens', 'toolCalls', 'durationSeconds', 'repairCount'];
10
+ const hasText = (value) => typeof value === 'string' && Boolean(value.trim());
11
+
12
+ function hasImageData(bytes) {
13
+ let hasData = false;
14
+ for (let offset = 33; offset + 12 <= bytes.length;) {
15
+ const length = bytes.readUInt32BE(offset);
16
+ const type = bytes.toString('ascii', offset + 4, offset + 8);
17
+ offset += length + 12;
18
+ if (offset > bytes.length) return false;
19
+ if (type === 'IDAT' && length > 0) hasData = true;
20
+ if (type === 'IEND') return hasData && length === 0 && offset === bytes.length;
21
+ }
22
+ return false;
23
+ }
24
+
25
+ function readCapture(path, state, dimensions, absent) {
26
+ let bytes;
27
+ try {
28
+ bytes = readFileSync(join(path, `${state}.png`));
29
+ } catch (error) {
30
+ if (error.code === 'ENOENT' && absent) return [];
31
+ throw error;
32
+ }
33
+ if (absent) throw new Error(`Capture ${state} in ${path} is also marked missing`);
34
+ if (bytes.length < 33 || bytes.subarray(0, 8).toString('hex') !== '89504e470d0a1a0a'
35
+ || bytes.readUInt32BE(8) !== 13 || bytes.toString('ascii', 12, 16) !== 'IHDR' || !hasImageData(bytes)) {
36
+ throw new Error(`Expected a PNG capture with image data for ${state} in ${path}`);
37
+ }
38
+ if (`${bytes.readUInt32BE(16)}x${bytes.readUInt32BE(20)}` !== dimensions) {
39
+ throw new Error(`Expected ${dimensions} capture for ${state} in ${path}`);
40
+ }
41
+ return [[state, bytes]];
42
+ }
43
+
44
+ function readRun(path, scenario) {
45
+ const run = JSON.parse(readFileSync(join(path, 'run.json'), 'utf8'));
46
+ if (!groups.includes(run.group) || !Number.isInteger(run.trial) || run.trial < 1) {
47
+ throw new Error(`Invalid group or trial in ${path}`);
48
+ }
49
+ if (!Array.isArray(run.taskResults) || run.taskResults.length !== scenario.checks.length
50
+ || run.taskResults.some(({ status, observation }) =>
51
+ !statuses.includes(status) || typeof observation !== 'string' || !observation.trim())) {
52
+ throw new Error(`Record a status and observation for each task check in ${path}`);
53
+ }
54
+ const missing = run.missingCaptures ?? {};
55
+ if (typeof missing !== 'object' || Array.isArray(missing)
56
+ || Object.entries(missing).some(([state, reason]) => !Object.hasOwn(scenario.captures, state) || !hasText(reason))) {
57
+ throw new Error(`Record a reason for each missing capture in ${path}`);
58
+ }
59
+ const images = Object.entries(scenario.captures).flatMap(([state, dimensions]) =>
60
+ readCapture(path, state, dimensions, Object.hasOwn(missing, state)));
61
+ return { run, images };
62
+ }
63
+
64
+ function checkComparison(entries) {
65
+ const baseline = entries[0].run.environment;
66
+ for (const { run } of entries) {
67
+ const name = `group ${run.group}, trial ${run.trial}`;
68
+ if (conditionFields.some((field) => !hasText(run.environment?.[field])
69
+ || run.environment[field] !== baseline?.[field])) {
70
+ throw new Error(`Record the same benchmark environment and inputs for every run (${name}).`);
71
+ }
72
+ if (costFields.some((field) => {
73
+ const value = run.metrics?.[field];
74
+ return value === null ? !hasText(run.metricsNote) : !Number.isFinite(value) || value < 0;
75
+ })) {
76
+ throw new Error(`Record costs or explain unavailable metrics for ${name}.`);
77
+ }
78
+ if (run.group !== 'E' || hasText(run.combinationFailure)) continue;
79
+ const specialists = new Set(Array.isArray(run.specialists) ? run.specialists.filter(hasText) : []);
80
+ const handedOff = Array.isArray(run.handoffs) && run.handoffs.some((handoff) =>
81
+ handoff && specialists.has(handoff.from) && specialists.has(handoff.to)
82
+ && handoff.from !== handoff.to && hasText(handoff.adopted));
83
+ if (!handedOff) throw new Error(`Record the adopted handoff between specialists, or the combination failure, for ${name}.`);
84
+ }
85
+ }
86
+
87
+ function blind(caseId, runsPath, outputPath, pilot) {
88
+ const scenario = Object.hasOwn(cases, caseId) && cases[caseId];
89
+ if (!scenario) throw new Error(`Unknown benchmark case: ${caseId}`);
90
+ const entries = readdirSync(runsPath, { withFileTypes: true })
91
+ .filter((entry) => entry.isDirectory())
92
+ .map((entry) => readRun(join(runsPath, entry.name), scenario));
93
+ const keys = new Set(entries.map(({ run }) => `${run.group}:${run.trial}`));
94
+ const counts = groups.map((group) => entries.filter(({ run }) => run.group === group).length);
95
+ if (entries.length !== keys.size || counts.filter(Boolean).length < 2) {
96
+ throw new Error('Use unique group/trial combinations from at least two groups.');
97
+ }
98
+ if (!pilot && (counts[0] < 2 || counts.some((count) => count !== counts[0]))) {
99
+ throw new Error('Use equally repeated trials for groups A, B, D and E, or mark a smaller comparison --pilot.');
100
+ }
101
+ if (!pilot) checkComparison(entries);
102
+ const reviewableGroups = new Set(entries
103
+ .filter(({ run, images }) => images.length && !(run.group === 'E' && hasText(run.combinationFailure)))
104
+ .map(({ run }) => run.group));
105
+ const partial = pilot || groups.some((group) => !reviewableGroups.has(group));
106
+
107
+ for (let i = entries.length - 1; i > 0; i--) {
108
+ const j = randomInt(i + 1);
109
+ [entries[i], entries[j]] = [entries[j], entries[i]];
110
+ }
111
+
112
+ mkdirSync(outputPath);
113
+ const reviewPath = join(outputPath, 'review');
114
+ mkdirSync(reviewPath);
115
+ const privateRuns = {};
116
+ const candidates = entries.flatMap(({ run, images }, i) => {
117
+ const label = `sample-${String(i + 1).padStart(2, '0')}`;
118
+ privateRuns[label] = run;
119
+ if (!images.length) return [];
120
+ mkdirSync(join(reviewPath, label));
121
+ const captures = Object.fromEntries(images.map(([state, bytes]) => {
122
+ const relative = `${label}/${state}.png`;
123
+ writeFileSync(join(reviewPath, relative), bytes);
124
+ return [state, relative];
125
+ }));
126
+ return [{ label, captures }];
127
+ });
128
+ writeFileSync(join(reviewPath, 'review.json'), JSON.stringify({ caseId, ...scenario, candidates }, null, 2)+'\n');
129
+ writeFileSync(join(outputPath, 'private.json'), JSON.stringify({ pilot: partial, runs: privateRuns }, null, 2)+'\n');
130
+ }
131
+
132
+ try {
133
+ const [caseId, runsPath, outputPath, option, extra] = process.argv.slice(2);
134
+ if (!caseId || !runsPath || !outputPath || (option && option !== '--pilot') || extra) {
135
+ throw new Error('Usage: node benchmark/blind.mjs CASE RUNS_DIR NEW_OUTPUT_DIR [--pilot]');
136
+ }
137
+ blind(caseId, runsPath, outputPath, option === '--pilot');
138
+ } catch (error) {
139
+ console.error(error.message);
140
+ process.exitCode = 1;
141
+ }