@uselazuli/cli 0.0.0-stage → 1.0.2

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 (179) hide show
  1. package/CHANGELOG.md +120 -0
  2. package/LICENSE +21 -0
  3. package/README.md +202 -2
  4. package/agents/lazuli-design-reviewer.md +30 -0
  5. package/agents/lazuli-first-look.md +22 -0
  6. package/agents/lazuli-task-tester.md +25 -0
  7. package/bin/lazuli.mjs +747 -0
  8. package/package.json +11 -4
  9. package/rules/accessibility/HYPOTHESES.md +8 -0
  10. package/rules/accessibility/_area.yaml +7 -0
  11. package/rules/accessibility/operable.yaml +100 -0
  12. package/rules/accessibility/perceivable.yaml +153 -0
  13. package/rules/accessibility/robust.yaml +24 -0
  14. package/rules/accessibility/understandable.yaml +72 -0
  15. package/rules/color/HYPOTHESES.md +27 -0
  16. package/rules/color/_area.yaml +10 -0
  17. package/rules/color/adapt.yaml +183 -0
  18. package/rules/color/create.yaml +259 -0
  19. package/rules/color/review.yaml +215 -0
  20. package/rules/color/signal.yaml +196 -0
  21. package/rules/content/HYPOTHESES.md +19 -0
  22. package/rules/content/_area.yaml +8 -0
  23. package/rules/content/review.yaml +378 -0
  24. package/rules/content/voice.yaml +144 -0
  25. package/rules/content/writing.yaml +202 -0
  26. package/rules/data/HYPOTHESES.md +11 -0
  27. package/rules/data/_area.yaml +7 -0
  28. package/rules/data/charts.yaml +189 -0
  29. package/rules/data/dashboards.yaml +141 -0
  30. package/rules/data/review.yaml +159 -0
  31. package/rules/graphic/HYPOTHESES.md +18 -0
  32. package/rules/graphic/_area.yaml +8 -0
  33. package/rules/graphic/identity.yaml +141 -0
  34. package/rules/graphic/pieces.yaml +164 -0
  35. package/rules/graphic/review.yaml +271 -0
  36. package/rules/graphic/symbol.yaml +141 -0
  37. package/rules/motion/HYPOTHESES.md +19 -0
  38. package/rules/motion/_area.yaml +7 -0
  39. package/rules/motion/micro.yaml +143 -0
  40. package/rules/motion/review.yaml +347 -0
  41. package/rules/motion/transitions.yaml +169 -0
  42. package/rules/typography/HYPOTHESES.md +12 -0
  43. package/rules/typography/_area.yaml +8 -0
  44. package/rules/typography/adapt.yaml +45 -0
  45. package/rules/typography/create.yaml +126 -0
  46. package/rules/typography/review.yaml +127 -0
  47. package/rules/ui/HYPOTHESES.md +23 -0
  48. package/rules/ui/_area.yaml +9 -0
  49. package/rules/ui/compose.yaml +246 -0
  50. package/rules/ui/grid.yaml +75 -0
  51. package/rules/ui/review.yaml +400 -0
  52. package/rules/ui/states.yaml +257 -0
  53. package/rules/ux/HYPOTHESES.md +13 -0
  54. package/rules/ux/_area.yaml +8 -0
  55. package/rules/ux/flows.yaml +164 -0
  56. package/rules/ux/forms.yaml +142 -0
  57. package/rules/ux/review.yaml +186 -0
  58. package/skills/lazuli/SKILL.md +183 -0
  59. package/skills/lazuli/procedures/create.md +29 -0
  60. package/skills/lazuli/procedures/explain-decisions.md +22 -0
  61. package/skills/lazuli/procedures/improve.md +30 -0
  62. package/skills/lazuli/procedures/remember-this.md +41 -0
  63. package/skills/lazuli/procedures/review-design.md +36 -0
  64. package/skills/lazuli/procedures/show-options.md +33 -0
  65. package/skills/lazuli-accessibility-check/SKILL.md +68 -0
  66. package/skills/lazuli-color-context-and-culture/SKILL.md +53 -0
  67. package/skills/lazuli-color-context-and-culture/references/sectors.md +26 -0
  68. package/skills/lazuli-color-palette-by-intent/SKILL.md +54 -0
  69. package/skills/lazuli-color-palette-by-intent/references/intent-chords.md +51 -0
  70. package/skills/lazuli-color-screen-review/SKILL.md +51 -0
  71. package/skills/lazuli-color-states-and-signals/SKILL.md +53 -0
  72. package/skills/lazuli-content-interface-writing/SKILL.md +53 -0
  73. package/skills/lazuli-content-voice/SKILL.md +40 -0
  74. package/skills/lazuli-data-charts-and-dashboards/SKILL.md +59 -0
  75. package/skills/lazuli-graphic-derived-pieces/SKILL.md +40 -0
  76. package/skills/lazuli-graphic-derived-pieces/references/piece-template.html +24 -0
  77. package/skills/lazuli-graphic-identity/SKILL.md +45 -0
  78. package/skills/lazuli-motion-micro-and-transitions/SKILL.md +49 -0
  79. package/skills/lazuli-typography-choose-and-pair/SKILL.md +50 -0
  80. package/skills/lazuli-typography-screen-review/SKILL.md +51 -0
  81. package/skills/lazuli-ui-composition/SKILL.md +42 -0
  82. package/skills/lazuli-ui-composition/references/option-template.html +34 -0
  83. package/skills/lazuli-ui-layout-review/SKILL.md +47 -0
  84. package/skills/lazuli-ui-states-and-system/SKILL.md +54 -0
  85. package/skills/lazuli-ux-flows-and-forms/SKILL.md +51 -0
  86. package/skills/lazuli-ux-task-test/SKILL.md +44 -0
  87. package/src/browser.mjs +162 -0
  88. package/src/commands/capture.mjs +313 -0
  89. package/src/commands/catalog.mjs +37 -0
  90. package/src/commands/check-design.mjs +463 -0
  91. package/src/commands/check-goals.mjs +57 -0
  92. package/src/commands/compare-designs.mjs +160 -0
  93. package/src/commands/draft-memo.mjs +162 -0
  94. package/src/commands/hooks.mjs +345 -0
  95. package/src/commands/install-hooks.mjs +120 -0
  96. package/src/commands/install.mjs +132 -0
  97. package/src/commands/list-rules.mjs +49 -0
  98. package/src/commands/map-page.mjs +594 -0
  99. package/src/commands/record-answers.mjs +79 -0
  100. package/src/commands/record-log.mjs +325 -0
  101. package/src/commands/record-task.mjs +250 -0
  102. package/src/commands/render-options.mjs +227 -0
  103. package/src/commands/start-project.mjs +32 -0
  104. package/src/measure/a11y.mjs +391 -0
  105. package/src/measure/asset.mjs +206 -0
  106. package/src/measure/at-rest.mjs +49 -0
  107. package/src/measure/cases.mjs +566 -0
  108. package/src/measure/chart-read.mjs +401 -0
  109. package/src/measure/chart.mjs +264 -0
  110. package/src/measure/coherence.mjs +145 -0
  111. package/src/measure/color.mjs +86 -0
  112. package/src/measure/content.mjs +82 -0
  113. package/src/measure/cvd.mjs +24 -0
  114. package/src/measure/extreme.mjs +241 -0
  115. package/src/measure/forms.mjs +150 -0
  116. package/src/measure/in-page/a11y.js +522 -0
  117. package/src/measure/in-page/color.js +348 -0
  118. package/src/measure/in-page/composition.js +1496 -0
  119. package/src/measure/in-page/contrast.js +15 -0
  120. package/src/measure/in-page/cvd.js +173 -0
  121. package/src/measure/in-page/extreme.js +377 -0
  122. package/src/measure/in-page/frames.js +781 -0
  123. package/src/measure/in-page/look.js +28 -0
  124. package/src/measure/in-page/motion-probe.js +171 -0
  125. package/src/measure/in-page/style.js +107 -0
  126. package/src/measure/in-page/svg-strokes.js +112 -0
  127. package/src/measure/in-page/svg-uses.js +50 -0
  128. package/src/measure/in-page/symbol.js +123 -0
  129. package/src/measure/in-page/type.js +269 -0
  130. package/src/measure/in-page/weight.js +207 -0
  131. package/src/measure/layout.mjs +100 -0
  132. package/src/measure/motion.mjs +509 -0
  133. package/src/measure/piece.mjs +195 -0
  134. package/src/measure/registry.mjs +253 -0
  135. package/src/measure/rhythm.mjs +81 -0
  136. package/src/measure/signature.mjs +65 -0
  137. package/src/measure/states.mjs +240 -0
  138. package/src/measure/style.mjs +13 -0
  139. package/src/measure/symbol.mjs +268 -0
  140. package/src/measure/terms.mjs +153 -0
  141. package/src/measure/tiles.mjs +20 -0
  142. package/src/measure/timeline.mjs +621 -0
  143. package/src/measure/type.mjs +167 -0
  144. package/src/measure/weight.mjs +18 -0
  145. package/src/private-strings.mjs +81 -0
  146. package/src/project/blind.mjs +70 -0
  147. package/src/project/edits.mjs +154 -0
  148. package/src/project/gate.mjs +168 -0
  149. package/src/project/lazuli-md.mjs +521 -0
  150. package/src/project/log.mjs +335 -0
  151. package/src/project/match.mjs +200 -0
  152. package/src/project/records.mjs +380 -0
  153. package/src/project/tasks.mjs +153 -0
  154. package/src/report/evaluate.mjs +27 -0
  155. package/src/report/evaluators/a11y.mjs +227 -0
  156. package/src/report/evaluators/chart.mjs +151 -0
  157. package/src/report/evaluators/coherence.mjs +103 -0
  158. package/src/report/evaluators/color.mjs +133 -0
  159. package/src/report/evaluators/content.mjs +112 -0
  160. package/src/report/evaluators/extreme.mjs +87 -0
  161. package/src/report/evaluators/forms.mjs +116 -0
  162. package/src/report/evaluators/layout.mjs +103 -0
  163. package/src/report/evaluators/motion.mjs +280 -0
  164. package/src/report/evaluators/piece.mjs +69 -0
  165. package/src/report/evaluators/rhythm.mjs +99 -0
  166. package/src/report/evaluators/states.mjs +39 -0
  167. package/src/report/evaluators/style.mjs +35 -0
  168. package/src/report/evaluators/symbol.mjs +110 -0
  169. package/src/report/evaluators/terms.mjs +49 -0
  170. package/src/report/evaluators/type.mjs +166 -0
  171. package/src/report/evaluators/weight.mjs +51 -0
  172. package/src/report/evidence.mjs +4 -0
  173. package/src/report/finding.mjs +11 -0
  174. package/src/report/format.mjs +215 -0
  175. package/src/rules/hypotheses.mjs +28 -0
  176. package/src/rules/load.mjs +274 -0
  177. package/src/rules/public-text.mjs +56 -0
  178. package/src/rules/schema.mjs +220 -0
  179. package/templates/LAZULI.md +88 -0
@@ -0,0 +1,49 @@
1
+ import { makeFinding } from "../finding.mjs";
2
+ import { listed } from "../evidence.mjs";
3
+ import { joined, onScreens, screenNames } from "./coherence.mjs";
4
+
5
+ const plural = (n, one, many) => (n === 1 ? one : many);
6
+ // What was not compared is noted by the measurer; the evaluators then return null, never a vacuous pass.
7
+
8
+ function sameTarget(rule, m) {
9
+ const r = m.terms;
10
+ if (!r || !Array.isArray(r.destinations) || r.destinations.length === 0) return null;
11
+ const names = screenNames(r.screens ?? []);
12
+ const paths = screenNames(r.destinations.map((d) => d.href));
13
+ const divergent = r.destinations.map((d, i) => ({ d, path: paths[i] })).filter(({ d }) => d.names.length >= 2);
14
+ const n = divergent.length;
15
+ if (n > 0) {
16
+ return makeFinding(
17
+ rule,
18
+ m.width,
19
+ "hint",
20
+ `${n} ${plural(n, "destination is", "destinations are")} named in more than one way: ${joined(divergent.map((x) => x.path))}.`,
21
+ listed(divergent.map(({ d, path }) => `${path}: ${d.names.map((x) => `"${x.name}" on ${onScreens(names, x.screens)}`).join("; ")}`)),
22
+ );
23
+ }
24
+ const k = r.destinations.length;
25
+ return makeFinding(rule, m.width, "pass", `Each of the ${k} ${plural(k, "destination", "destinations")} linked from navigation more than once keeps one name.`);
26
+ }
27
+
28
+ function spelling(rule, m) {
29
+ const r = m.terms;
30
+ if (!r || !Number.isFinite(r.words) || r.words === 0) return null;
31
+ const list = Array.isArray(r.spellings) ? r.spellings : [];
32
+ if (list.length > 0) {
33
+ const names = screenNames(r.screens ?? []);
34
+ const n = list.length;
35
+ return makeFinding(
36
+ rule,
37
+ m.width,
38
+ "hint",
39
+ `${n} ${plural(n, "term is", "terms are")} written in more than one way: ${list.map((s) => joined(s.forms.map((f) => `"${f.form}"`))).join("; ")}.`,
40
+ listed(list.map((s) => s.forms.map((f) => `"${f.form}" on ${onScreens(names, f.screens)} (${f.count})`).join("; "))),
41
+ );
42
+ }
43
+ return makeFinding(rule, m.width, "pass", `No term among ${r.words} distinct words is written in two ways.`);
44
+ }
45
+
46
+ export const termsEvaluators = {
47
+ "terms.same-target": sameTarget,
48
+ "terms.spelling": spelling,
49
+ };
@@ -0,0 +1,166 @@
1
+ import { makeFinding } from "../finding.mjs";
2
+
3
+ const clip = (s, n = 40) => (s.length > n ? `${s.slice(0, n - 3)}...` : s);
4
+ const hasNumbers = (t, keys) => t && typeof t === "object" && keys.every((k) => Number.isFinite(t[k]));
5
+ const plural = (n, one, many = `${one}s`) => `${n} ${n === 1 ? one : many}`;
6
+ const blockLabel = (b) => `${b.selector}: ${b.charsPerLine} characters per line over ${b.lines} lines`;
7
+
8
+ function families(rule, m) {
9
+ if (!m.type) return null;
10
+ const t = rule.threshold;
11
+ if (!hasNumbers(t, ["maxFamilies"])) return null;
12
+ const list = m.type.families ?? [];
13
+ if (list.length === 0) return null;
14
+ if (list.length <= t.maxFamilies) {
15
+ return makeFinding(rule, m.width, "pass", `${plural(list.length, "font family", "font families")} rendered, within the limit of ${t.maxFamilies}.`);
16
+ }
17
+ const evidence = list.slice(0, 8).map((f) => `${f.family}: ${f.glyphs} glyphs`);
18
+ return makeFinding(
19
+ rule,
20
+ m.width,
21
+ "hint",
22
+ `${plural(list.length, "font family", "font families")} rendered, above the limit of ${t.maxFamilies}.`,
23
+ evidence,
24
+ );
25
+ }
26
+
27
+ function fallback(rule, m) {
28
+ if (!m.type) return null;
29
+ const list = m.type.fallbacks ?? [];
30
+ if (list.length === 0) return makeFinding(rule, m.width, "pass", "Every named first font family was rendered.");
31
+ const evidence = list.slice(0, 5).map((f) => `${f.selector} asks for ${f.declared} and rendered ${f.rendered.join(", ")}`);
32
+ return makeFinding(
33
+ rule,
34
+ m.width,
35
+ "hint",
36
+ `${plural(list.length, "text style")} rendered in a fallback instead of the declared first font family.`,
37
+ evidence,
38
+ );
39
+ }
40
+
41
+ function lineLength(rule, m) {
42
+ if (!m.type) return null;
43
+ const t = rule.threshold;
44
+ if (!hasNumbers(t, ["minChars", "maxChars", "minLines"])) return null;
45
+ // A block with fewer characters in all than minLines full lines at minChars is a caption, not running
46
+ // text: the cutoff is derived from the two rule values, not a third number.
47
+ const captionChars = t.minLines * t.minChars;
48
+ const total = (b) => (Number.isFinite(b.chars) ? b.chars : Number.isFinite(b.charsPerLine * b.lines) ? b.charsPerLine * b.lines : Infinity);
49
+ const tall = (m.type.blocks ?? []).filter((b) => b.lines >= t.minLines);
50
+ const long = tall.filter((b) => total(b) >= captionChars);
51
+ const skipped = long.length < tall.length ? `; blocks under ${captionChars} characters in all were read as captions and not judged` : "";
52
+ if (long.length === 0) return null;
53
+ // Short lines are not the type's fault when a line as wide as the whole viewport could not hold the
54
+ // minimum at this block's size (its own measured character width).
55
+ const roomy = (b) => !(Number.isFinite(b.charAdvancePx) && b.charAdvancePx > 0 && Number.isFinite(m.width) && m.width / b.charAdvancePx < t.minChars);
56
+ const bad = long.filter((b) => (b.charsPerLine < t.minChars && roomy(b)) || b.charsPerLine > t.maxChars);
57
+ const judged = long.filter((b) => b.charsPerLine > t.maxChars || roomy(b));
58
+ if (judged.length === 0) return null;
59
+ if (bad.length === 0) {
60
+ return makeFinding(rule, m.width, "pass", `Line length is between ${t.minChars} and ${t.maxChars} characters in every block of ${t.minLines} lines or more${skipped}.`);
61
+ }
62
+ return makeFinding(
63
+ rule,
64
+ m.width,
65
+ "hint",
66
+ `${plural(bad.length, "text block")} with lines outside ${t.minChars} to ${t.maxChars} characters.`,
67
+ bad.slice(0, 5).map(blockLabel),
68
+ );
69
+ }
70
+
71
+ function bodySize(rule, m) {
72
+ if (!m.type?.body) return null;
73
+ const t = rule.threshold;
74
+ if (!hasNumbers(t, ["minPx", "maxPx"])) return null;
75
+ const px = m.type.body.sizePx;
76
+ if (px >= t.minPx && px <= t.maxPx) {
77
+ return makeFinding(rule, m.width, "pass", `Body text is ${px} px, within ${t.minPx} to ${t.maxPx} px.`);
78
+ }
79
+ return makeFinding(rule, m.width, "hint", `Body text is ${px} px, outside ${t.minPx} to ${t.maxPx} px.`, [
80
+ `${m.type.body.selector}: ${px} px`,
81
+ ]);
82
+ }
83
+
84
+ function lineHeight(rule, m) {
85
+ if (!m.type) return null;
86
+ const t = rule.threshold;
87
+ if (!hasNumbers(t, ["minRatio", "maxRatio"])) return null;
88
+ const multi = (m.type.blocks ?? []).filter((b) => b.lines >= 2);
89
+ if (multi.length === 0) return null;
90
+ // Display type (WCAG large scale) is judged for the upper bound only: large headings need less.
91
+ const bad = multi.filter((b) => (b.large !== true && b.lineHeightRatio < t.minRatio) || b.lineHeightRatio > t.maxRatio);
92
+ if (bad.length === 0) {
93
+ const display = multi.filter((b) => b.large === true).length;
94
+ const tail = display > 0 ? `; ${plural(display, "display block")} (large scale) ${display === 1 ? "was" : "were"} checked for the upper bound only` : "";
95
+ return makeFinding(rule, m.width, "pass", `Line height is between ${t.minRatio} and ${t.maxRatio} times the font size in every multi-line block${tail}.`);
96
+ }
97
+ return makeFinding(
98
+ rule,
99
+ m.width,
100
+ "hint",
101
+ `${plural(bad.length, "text block")} with a line height outside ${t.minRatio} to ${t.maxRatio} times the font size.`,
102
+ bad.slice(0, 5).map((b) => `${b.selector}: ${b.lineHeightRatio} at ${b.sizePx} px`),
103
+ );
104
+ }
105
+
106
+ function scale(rule, m) {
107
+ if (!m.type) return null;
108
+ const t = rule.threshold;
109
+ if (!hasNumbers(t, ["minStepRatio"])) return null;
110
+ const { sizesPx = [], ratios = [] } = m.type.scale ?? {};
111
+ if (ratios.length === 0) return null;
112
+ const bad = ratios.map((r, i) => ({ r, from: sizesPx[i], to: sizesPx[i + 1] })).filter((x) => x.r < t.minStepRatio);
113
+ if (bad.length === 0) {
114
+ return makeFinding(rule, m.width, "pass", `Every step between neighboring sizes is at least ${t.minStepRatio} times.`);
115
+ }
116
+ return makeFinding(
117
+ rule,
118
+ m.width,
119
+ "hint",
120
+ `${plural(bad.length, "step")} between neighboring sizes below ${t.minStepRatio} times.`,
121
+ bad.slice(0, 5).map((x) => `${x.from} px to ${x.to} px is ${x.r} times`),
122
+ );
123
+ }
124
+
125
+ function hierarchy(rule, m) {
126
+ if (!m.type) return null;
127
+ const headings = m.type.headings ?? [];
128
+ const inverted = [];
129
+ for (const high of headings) {
130
+ for (const low of headings) {
131
+ if (high.level < low.level && high.sizePx < low.sizePx) inverted.push([high, low]);
132
+ }
133
+ }
134
+ if (inverted.length === 0) return makeFinding(rule, m.width, "pass", "No heading is smaller than a lower level heading.");
135
+ return makeFinding(
136
+ rule,
137
+ m.width,
138
+ "hint",
139
+ `${plural(inverted.length, "heading pair")} where a higher level renders smaller than a lower level.`,
140
+ inverted.slice(0, 5).map(([h, l]) => `h${h.level} (${h.sizePx} px) is smaller than h${l.level} (${l.sizePx} px)`),
141
+ );
142
+ }
143
+
144
+ function headingRag(rule, m) {
145
+ if (!m.type) return null;
146
+ const bad = (m.type.headings ?? []).filter((h) => h.lines >= 2 && h.lastLineWords === 1);
147
+ if (bad.length === 0) return makeFinding(rule, m.width, "pass", "No heading ends on a line with a single word.");
148
+ return makeFinding(
149
+ rule,
150
+ m.width,
151
+ "hint",
152
+ `${plural(bad.length, "heading")} wrap${bad.length === 1 ? "s" : ""} to a last line with one word.`,
153
+ bad.slice(0, 5).map((h) => `${clip(h.selector)}: ${h.lines} lines, last line has 1 word`),
154
+ );
155
+ }
156
+
157
+ export const typeEvaluators = {
158
+ "type.families": families,
159
+ "type.fallback": fallback,
160
+ "type.line-length": lineLength,
161
+ "type.body-size": bodySize,
162
+ "type.line-height": lineHeight,
163
+ "type.scale": scale,
164
+ "type.hierarchy": hierarchy,
165
+ "type.heading-rag": headingRag,
166
+ };
@@ -0,0 +1,51 @@
1
+ import { makeFinding } from "../finding.mjs";
2
+
3
+ // The opening of every weight.order message about a guessed main action (no data-primary).
4
+ const GUESS = "The first button-like element found";
5
+
6
+ // Where the main action sits against the first view, in page px, when the measure has it.
7
+ function place(p) {
8
+ if (![p.top, p.bottom, p.viewportPx].every(Number.isFinite)) return "";
9
+ return p.top < p.viewportPx
10
+ ? ` Its bottom edge is at ${p.bottom} px of the ${p.viewportPx} px first view.`
11
+ : ` It starts at ${p.top} px, below the ${p.viewportPx} px first view.`;
12
+ }
13
+
14
+ function weightOrder(rule, m) {
15
+ const w = m.weight;
16
+ if (!w) return null;
17
+ const p = w.primary;
18
+ if (!p) {
19
+ return makeFinding(rule, m.width, "hint", "No main action was detected in the first view. Mark it with data-primary.");
20
+ }
21
+ // Without data-primary the main action is a guess; say so instead of stating it as fact.
22
+ const who = p.explicit ? `The main action (${p.selector})` : `${GUESS} (${p.selector})`;
23
+ const exact = p.explicit ? "" : " Mark your main action with data-primary to make this exact.";
24
+ const where = place(p);
25
+ if (p.rank === null || p.rank === undefined) {
26
+ return makeFinding(rule, m.width, "hint", `${who} is not visible in the first view.${exact}${where}`);
27
+ }
28
+ if (p.rank > 1) {
29
+ const stronger = (w.order ?? []).slice(0, Math.min(3, p.rank - 1)).map((o) => o.label);
30
+ const list = stronger.length ? `; stronger: ${stronger.join(", ")}.` : ".";
31
+ return makeFinding(rule, m.width, "hint", `${who} ranks ${p.rank} in visual weight${list}${exact}${where}`);
32
+ }
33
+ return makeFinding(rule, m.width, "pass", `${who} is the most prominent element.${exact}${where}`);
34
+ }
35
+
36
+ // When the main action is guessed (no data-primary) and the guess differs between widths (label or href), every
37
+ // weight.order finding on a guess gains one evidence line naming the guess at each width. Pure.
38
+ export function noteGuessChanges(findings, measures) {
39
+ const guesses = measures
40
+ .filter((m) => m.weight?.primary && !m.weight.primary.explicit)
41
+ .map((m) => ({ width: m.width, label: m.weight.primary.label, href: m.weight.primary.href ?? null }));
42
+ const differs = guesses.some((g) => g.label !== guesses[0].label || g.href !== guesses[0].href);
43
+ if (!differs) return findings;
44
+ const line = `The guessed main action differs between widths: ${guesses.map((g) => `"${g.label}" at ${g.width} px`).join(", ")}. Mark it with data-primary.`;
45
+ const guessed = new Set(guesses.map((g) => g.width));
46
+ return findings.map((f) =>
47
+ guessed.has(f.width) && f.message.startsWith(GUESS) ? { ...f, evidence: [...f.evidence, line] } : f,
48
+ );
49
+ }
50
+
51
+ export const weightEvaluators = { "weight.order": weightOrder };
@@ -0,0 +1,4 @@
1
+ // Display limit, not a rule cutoff: evidence lines shown per finding; a last line says how many were left out.
2
+ export const MAX_EVIDENCE = 5;
3
+ export const listed = (lines) =>
4
+ lines.length > MAX_EVIDENCE ? [...lines.slice(0, MAX_EVIDENCE), `and ${lines.length - MAX_EVIDENCE} more`] : lines;
@@ -0,0 +1,11 @@
1
+ // One finding per rule and width. fail only for norm and project rules; a hypothesis rule gives at most a hint.
2
+ export function makeFinding(rule, width, level, message, evidence = []) {
3
+ let final = level;
4
+ if (final === "fail" && ((rule.origin !== "norm" && rule.origin !== "project") || rule.status === "hypothesis")) final = "hint";
5
+ let tag = "";
6
+ if (rule.hypothesis && final === "hint") {
7
+ const ids = Array.isArray(rule.hypothesis) ? rule.hypothesis : [rule.hypothesis];
8
+ tag = ` (hypothesis ${[...ids, ...(rule.area ? [rule.area] : [])].join(", ")})`;
9
+ }
10
+ return { ruleId: rule.id, name: rule.name, area: rule.area, level: final, width, message: `${message}${tag}`, evidence };
11
+ }
@@ -0,0 +1,215 @@
1
+ const ORDER = { fail: 0, hint: 1, break: 2, declared: 3, pass: 4 };
2
+
3
+ // Rules that share a measure give identical findings; show them once with all rule ids.
4
+ function group(rows) {
5
+ const map = new Map();
6
+ for (const f of rows) {
7
+ const key = JSON.stringify([f.level, f.message, f.evidence ?? [], f.measuredAt ?? null, f.screens ?? null]);
8
+ const g = map.get(key);
9
+ if (g) {
10
+ g.ruleIds.push(f.ruleId);
11
+ g.names.push(f.name);
12
+ } else {
13
+ map.set(key, { level: f.level, message: f.message, evidence: f.evidence ?? [], ruleIds: [f.ruleId], names: [f.name], measuredAt: f.measuredAt, screens: f.screens });
14
+ }
15
+ }
16
+ return [...map.values()];
17
+ }
18
+
19
+ // "RV2, ES5 Name: message" when the rules share a name, else each id with its own name.
20
+ function label(g) {
21
+ const names = g.names.filter(Boolean);
22
+ if (names.length === 0) return `${g.ruleIds.join(", ")} ${g.message}`;
23
+ if (new Set(names).size === 1) return `${g.ruleIds.join(", ")} ${names[0]}: ${g.message}`;
24
+ return `${g.ruleIds.map((id, i) => (g.names[i] ? `${id} (${g.names[i]})` : id)).join(", ")} ${g.message}`;
25
+ }
26
+
27
+ // Each rule counts once, at its worst level across widths.
28
+ function ruleCounts(findings) {
29
+ const worst = new Map();
30
+ for (const f of findings) {
31
+ const cur = worst.get(f.ruleId);
32
+ if (cur === undefined || ORDER[f.level] < ORDER[cur]) worst.set(f.ruleId, f.level);
33
+ }
34
+ const counts = { fail: 0, hint: 0, break: 0, declared: 0, pass: 0 };
35
+ for (const level of worst.values()) counts[level] = (counts[level] ?? 0) + 1;
36
+ return counts;
37
+ }
38
+
39
+ const at = (widths) => `at ${widths.join(", ")} px`;
40
+ // A finding measured once for the whole check (reflow at its rule width) names that width, not the check widths.
41
+ // A site finding compares several screens: "across 3 screens at 1440 px".
42
+ const atOf = (g) => (Array.isArray(g.screens) ? `across ${g.screens.length} screens ` : "") + at(g.measuredAt ?? g.widths);
43
+
44
+ // Group per width first (shared measures), then merge identical groups across widths.
45
+ function mergeAcrossWidths(findings, widths) {
46
+ const merged = new Map();
47
+ for (const width of widths) {
48
+ for (const g of group(findings.filter((f) => f.width === width))) {
49
+ const key = JSON.stringify([g.level, g.message, g.evidence, g.ruleIds, g.measuredAt ?? null, g.screens ?? null]);
50
+ const m = merged.get(key);
51
+ if (m) m.widths.push(width);
52
+ else merged.set(key, { ...g, widths: [width] });
53
+ }
54
+ }
55
+ return [...merged.values()];
56
+ }
57
+
58
+ const capitalize = (s) => s.charAt(0).toUpperCase() + s.slice(1);
59
+
60
+ // A result without areas (v0.1 shape) is split by the area each finding carries.
61
+ function blocksFor(result) {
62
+ if (Array.isArray(result.areas)) {
63
+ const blocks = result.areas.map((a) => ({ ...a, findings: result.findings.filter((f) => f.area === a.area) }));
64
+ const known = new Set(result.areas.map((a) => a.area));
65
+ const stray = result.findings.filter((f) => !known.has(f.area));
66
+ if (stray.length > 0) blocks.push({ area: null, title: "Other", findings: stray });
67
+ return blocks;
68
+ }
69
+ const blocks = [];
70
+ for (const f of result.findings) {
71
+ const name = f.area ?? null;
72
+ let block = blocks.find((b) => b.area === name);
73
+ if (!block) {
74
+ block = { area: name, title: name ? capitalize(name) : "Other", findings: [] };
75
+ blocks.push(block);
76
+ }
77
+ block.findings.push(f);
78
+ }
79
+ const other = blocks.findIndex((b) => b.area === null);
80
+ if (other > -1) blocks.push(...blocks.splice(other, 1));
81
+ return blocks;
82
+ }
83
+
84
+ export function formatReport(result) {
85
+ const { findings, hasLazuliMd, target, asset, measures = [], siteMeasures = [], screens = [], siteSkipped = false, reportPath, copiedTo, mode, goals = [], effects = [], unmatchedGoals = 0, problems = [], projectProblems = [], uncheckedNorms = [], unappliedBreaks = [] } = result;
86
+ // On an asset run a width is a size label ("1200x630", "512 to 16").
87
+ const widths = [...new Set([...measures.map((m) => m.width), ...findings.map((f) => f.width)])];
88
+ const allMeasures = [...measures, ...siteMeasures];
89
+
90
+ // A page run leaves out an area whose measured rules all read assets, unless it has a finding.
91
+ const blocks = blocksFor(result)
92
+ .filter((b) => !(b.assetOnly && b.findings.length === 0))
93
+ .map((b) => ({ ...b, groups: mergeAcrossWidths(b.findings, widths) }));
94
+ const total = ruleCounts(findings);
95
+ const failedCount = new Set(allMeasures.flatMap((m) => Object.keys(m.errors ?? {}))).size;
96
+ const failedText = failedCount > 0 ? `${failedCount} measurer${failedCount === 1 ? "" : "s"} failed` : "";
97
+ const top =
98
+ findings.length === 0
99
+ ? `Nothing was measured${failedText ? `, ${failedText}` : ""}.`
100
+ : `${total.fail} fail, ${total.hint} hint, ${total.pass} pass${total.break > 0 ? `, ${total.break} break` : ""}${total.declared > 0 ? `, ${total.declared} declared` : ""} (rules)${failedText ? `, ${failedText}` : ""}`;
101
+ const lines = [`Lazuli design check: ${top}`];
102
+ if (uncheckedNorms.length > 0) {
103
+ lines.push(`Norms and learned rules not checked because their measurer failed: ${uncheckedNorms.join(", ")}.`);
104
+ }
105
+ if (asset) {
106
+ lines.push(`Asset: ${asset.target} (${asset.kind === "piece" ? (asset.raster ? "piece, raster" : "piece") : "symbol"})`);
107
+ } else if (target) {
108
+ lines.push(`Target: ${target}`);
109
+ }
110
+ // Only when site measures ran: with no site rule selected, nothing is marked "across".
111
+ if (screens.length > 1 && siteMeasures.length > 0) {
112
+ lines.push(`Page findings are for the target. Findings marked "across" compare ${screens.length} screens: ${screens.join(", ")}.`);
113
+ }
114
+ // A report written before the names were kept has only siteSkipped, which then meant coherence.
115
+ const notAcross = result.siteNotMeasured ?? (siteSkipped ? ["coherence"] : []);
116
+ if (notAcross.length > 0) {
117
+ const names = notAcross.length < 2 ? notAcross[0] : `${notAcross.slice(0, -1).join(", ")} and ${notAcross.at(-1)}`;
118
+ // "terms" reads as a plural noun.
119
+ const many = notAcross.length > 1 || notAcross[0] === "terms";
120
+ lines.push(`${capitalize(names)} across screens ${many ? "were" : "was"} not measured: ${many ? "they need" : "it needs"} two or more screens (give more targets or use --site).`);
121
+ }
122
+ // A symbol whose measurer read no size has the label "no size read", printed without "px".
123
+ if (widths.length) lines.push(`${asset ? "Sizes" : "Widths"}: ${widths.join(", ")}${widths.every((w) => /\d$/.test(String(w))) ? " px" : ""}`);
124
+ if (asset?.written?.length) lines.push(`Files written: ${asset.written.join(", ")}`);
125
+ if (asset?.blindSheet) lines.push(`Blind look sheet (GR5, the only path to give a fresh agent): ${asset.blindSheet}`);
126
+
127
+ const declared = [];
128
+ if (hasLazuliMd && mode) declared.push(`Mode: ${mode}`);
129
+ if (goals.length > 0) {
130
+ declared.push("Goals for this page and their recorded check:");
131
+ for (const [i, g] of goals.entries()) {
132
+ const v = (x) => (x ? x : "not set");
133
+ // effects and goals come from the same match, in the same order.
134
+ const e = effects.length === goals.length ? effects[i] : effects.find((x) => x.piece === g.piece);
135
+ const status = e ? ` [${e.status}]${e.verdict ? `, review ${e.verdict}` : ""}` : "";
136
+ declared.push(` ${g.piece}: understand ${v(g.understand)}; feel ${v(g.feel)}; do ${v(g.do)}${status}`);
137
+ if (g.rhythm?.length) declared.push(` Rhythm: ${g.rhythm.join(", ")}`);
138
+ }
139
+ } else if (unmatchedGoals > 0) {
140
+ declared.push(`LAZULI.md has ${unmatchedGoals} ${unmatchedGoals === 1 ? "goal" : "goals"}, none with a Target equal to this page.`);
141
+ }
142
+ if (unappliedBreaks.length > 0) {
143
+ declared.push("Breaks not applied:", ...unappliedBreaks.map((b) => ` ${b.rule} on ${b.piece}: ${b.reason}`));
144
+ }
145
+ if (problems.length > 0) {
146
+ declared.push("LAZULI.md problems:", ...problems.map((p) => ` - ${p}`));
147
+ }
148
+ if (declared.length > 0) lines.push("", ...declared);
149
+ if (projectProblems.length > 0) {
150
+ lines.push("", "Learned rules problems (these rules were skipped):", ...projectProblems.map((p) => ` - ${p}`));
151
+ }
152
+
153
+ for (const b of blocks) {
154
+ const counts = ruleCounts(b.findings);
155
+ const count = (level) => counts[level];
156
+ lines.push("");
157
+ const failedNote = b.failed?.length ? `${b.failed.join(", ")} measurer failed, see notes` : "";
158
+ if (b.measured === 0 && b.findings.length === 0) {
159
+ lines.push(failedNote ? `${b.title}: ${failedNote}.` : `${b.title}: no rule of this area is measured by check-design yet.`);
160
+ continue;
161
+ }
162
+ const coverage =
163
+ b.rules === undefined
164
+ ? ""
165
+ : ` (${b.measured} of ${b.rules} rules measured here; ${failedNote ? `${failedNote}; ` : ""}the others are checked by your agent or by people)`;
166
+ const brk = `${count("break") > 0 ? `, ${count("break")} break` : ""}${count("declared") > 0 ? `, ${count("declared")} declared` : ""}`;
167
+ lines.push(`${b.title}: ${count("fail")} fail, ${count("hint")} hint, ${count("pass")} pass${brk}${coverage}`);
168
+
169
+ const shown = b.groups.filter((g) => g.level !== "pass").sort((a, c) => ORDER[a.level] - ORDER[c.level]);
170
+ for (const g of shown) {
171
+ lines.push(` ${g.level.padEnd(4)} ${label(g)} (${atOf(g)})`);
172
+ for (const e of g.evidence) lines.push(` ${e}`);
173
+ }
174
+
175
+ const passBy = new Map();
176
+ for (const g of b.groups.filter((x) => x.level === "pass")) {
177
+ const key = atOf(g);
178
+ const ids = passBy.get(key) ?? new Set();
179
+ for (const id of g.ruleIds) ids.add(id);
180
+ passBy.set(key, ids);
181
+ }
182
+ for (const [key, ids] of passBy) lines.push(` pass ${[...ids].join(", ")} (${key})`);
183
+ }
184
+
185
+ // Measurement notes, once each, with the widths they came from when not all.
186
+ const notes = new Map();
187
+ // Notes about the asset itself (--size on a symbol) hold for every size.
188
+ for (const n of asset?.notes ?? []) notes.set(n, [...widths]);
189
+ for (const m of allMeasures) {
190
+ const found = [];
191
+ for (const [name, value] of Object.entries(m)) {
192
+ if (name === "width" || name === "errors") continue;
193
+ for (const n of value?.notes ?? []) found.push(`${name}: ${n}`);
194
+ }
195
+ for (const [name, message] of Object.entries(m.errors ?? {})) {
196
+ found.push(`${name}: ${name} measurer failed: ${message}`);
197
+ }
198
+ for (const n of found) {
199
+ const ws = notes.get(n) ?? [];
200
+ ws.push(m.width);
201
+ notes.set(n, ws);
202
+ }
203
+ }
204
+ if (notes.size) {
205
+ lines.push("", "Notes:");
206
+ for (const [n, ws] of notes) lines.push(` - ${n}${ws.length < widths.length ? ` (${at(ws)})` : ""}`);
207
+ }
208
+
209
+ if (reportPath) lines.push("", `Full report (JSON): ${reportPath}`);
210
+ if (copiedTo) lines.push(`Report also written to ${copiedTo}`);
211
+ if (!hasLazuliMd) {
212
+ lines.push("", "Tip: run lazuli start-project (or /lazuli start-project in your agent) to record your goals.");
213
+ }
214
+ return lines.join("\n");
215
+ }
@@ -0,0 +1,28 @@
1
+ const ID_RE = /^H\d{1,3}$/;
2
+
3
+ // Reads the rows of the markdown tables in an area's HYPOTHESES.md.
4
+ // A row counts when its first cell is an id like H3; columns are
5
+ // id, principle, candidate limit, how to validate.
6
+ export function parseHypotheses(text) {
7
+ const map = new Map();
8
+ for (const line of text.replace(/^\uFEFF/, "").split(/\r?\n/)) {
9
+ const trimmed = line.trim();
10
+ if (!trimmed.startsWith("|")) {
11
+ continue;
12
+ }
13
+ const cells = trimmed.replace(/^\|/, "").replace(/\|$/, "").split("|").map((c) => c.trim());
14
+ if (!ID_RE.test(cells[0])) {
15
+ continue;
16
+ }
17
+ if (map.has(cells[0])) {
18
+ throw new Error(`duplicate hypothesis ${cells[0]}`);
19
+ }
20
+ map.set(cells[0], {
21
+ id: cells[0],
22
+ principle: cells[1] ?? "",
23
+ limit: cells[2] ?? "",
24
+ validate: cells[3] ?? "",
25
+ });
26
+ }
27
+ return map;
28
+ }