@uselazuli/cli 0.0.0-stage → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (179) hide show
  1. package/CHANGELOG.md +98 -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 +699 -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 +18 -0
  22. package/rules/content/_area.yaml +8 -0
  23. package/rules/content/review.yaml +347 -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 +17 -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 +242 -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 +219 -0
  50. package/rules/ui/grid.yaml +75 -0
  51. package/rules/ui/review.yaml +399 -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 +180 -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 +35 -0
  64. package/skills/lazuli/procedures/show-options.md +32 -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 +39 -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 +43 -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 +161 -0
  88. package/src/commands/capture.mjs +313 -0
  89. package/src/commands/catalog.mjs +37 -0
  90. package/src/commands/check-design.mjs +428 -0
  91. package/src/commands/check-goals.mjs +57 -0
  92. package/src/commands/compare-designs.mjs +97 -0
  93. package/src/commands/draft-memo.mjs +161 -0
  94. package/src/commands/hooks.mjs +343 -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 +296 -0
  101. package/src/commands/record-task.mjs +250 -0
  102. package/src/commands/render-options.mjs +164 -0
  103. package/src/commands/start-project.mjs +32 -0
  104. package/src/measure/a11y.mjs +383 -0
  105. package/src/measure/asset.mjs +206 -0
  106. package/src/measure/at-rest.mjs +49 -0
  107. package/src/measure/cases.mjs +549 -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 +79 -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 +489 -0
  117. package/src/measure/in-page/color.js +346 -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 +355 -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 +169 -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 +266 -0
  130. package/src/measure/in-page/weight.js +207 -0
  131. package/src/measure/layout.mjs +91 -0
  132. package/src/measure/motion.mjs +508 -0
  133. package/src/measure/piece.mjs +195 -0
  134. package/src/measure/registry.mjs +252 -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 +159 -0
  149. package/src/project/lazuli-md.mjs +497 -0
  150. package/src/project/log.mjs +329 -0
  151. package/src/project/match.mjs +112 -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 +206 -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 +86 -0
  159. package/src/report/evaluators/content.mjs +112 -0
  160. package/src/report/evaluators/extreme.mjs +53 -0
  161. package/src/report/evaluators/forms.mjs +116 -0
  162. package/src/report/evaluators/layout.mjs +94 -0
  163. package/src/report/evaluators/motion.mjs +273 -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 +163 -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 +256 -0
  177. package/src/rules/public-text.mjs +56 -0
  178. package/src/rules/schema.mjs +212 -0
  179. package/templates/LAZULI.md +86 -0
@@ -0,0 +1,153 @@
1
+ import fs from "node:fs/promises";
2
+ import { restOn, restOff } from "./at-rest.mjs";
3
+ import { WORD, fold } from "./content.mjs";
4
+ import { bounded } from "./states.mjs";
5
+
6
+ // A measurement cap, not a rule value: one screen's at-rest read (style on, read, style off) may take this
7
+ // long; past it the screen is named in the could-not-be-read note and the others are compared. Removing the
8
+ // at-rest style has its own cap of the same length, so a hung screen costs at most two caps.
9
+ export const TERMS_SCREEN_CAP_MS = 15000;
10
+
11
+ let composition;
12
+
13
+ const plural = (n, one, many) => (n === 1 ? one : many);
14
+ // A curly apostrophe (U+2018, U+2019) reads as a straight one, so "It\u2019s" stays one word.
15
+ const straight = (text) => text.replace(/[\u2018\u2019]/g, "'");
16
+ const wordsOf = (text) => straight(text).match(WORD) ?? [];
17
+ // Digits are not words: a word with no letter never enters a pair, a key or the word count.
18
+ const hasLetter = (word) => /\p{L}/u.test(word);
19
+ // A spelling's key: the form with hyphens, periods and spaces removed; accents and apostrophes kept, so "it's"
20
+ // and "its" are two words.
21
+ const keyOf = (form) => form.replace(/[-. ]/g, "");
22
+ // One destination: the href with a trailing slash removed.
23
+ const destinationOf = (href) => href.replace(/\/$/, "");
24
+
25
+ // True when the word sequence a is a contiguous run of b.
26
+ function inside(a, b) {
27
+ if (a.length > b.length) return false;
28
+ for (let i = 0; i + a.length <= b.length; i += 1) if (a.every((w, j) => w === b[i + j])) return true;
29
+ return false;
30
+ }
31
+
32
+ // Distinct names of one destination after merging: a name whose folded word sequence is a contiguous run of
33
+ // a longer surviving name is that name ("contact" inside "contact us"). Longer names are kept first, each
34
+ // shorter one goes into the first surviving name (in order of first appearance) that holds it, so "contact us"
35
+ // and "contact sales" stay two names. A merged name shows the text first seen among its parts.
36
+ function mergeNames(seen) {
37
+ const byLength = [...seen].sort((a, b) => b.words.length - a.words.length || a.first - b.first);
38
+ const groups = [];
39
+ for (const n of byLength) {
40
+ const into = groups.filter((g) => inside(n.words, g.words)).sort((a, b) => a.first - b.first)[0];
41
+ if (into) into.parts.push(n);
42
+ else groups.push({ words: n.words, first: n.first, parts: [n] });
43
+ }
44
+ return groups
45
+ .map((g) => {
46
+ const parts = [...g.parts].sort((a, b) => a.first - b.first);
47
+ const screens = [...new Set(parts.flatMap((p) => p.screens))].sort((a, b) => a - b);
48
+ return { first: parts[0].first, name: parts[0].text, screens, count: parts.reduce((s, p) => s + p.count, 0) };
49
+ })
50
+ .sort((a, b) => a.first - b.first)
51
+ .map(({ name, screens, count }) => ({ name, screens, count }));
52
+ }
53
+
54
+ // Reads the content reader at rest on every screen (fixed and sticky content kept, hidden and clipped content
55
+ // left out) and compares, across screens: the names navigation gives one destination, and the ways one term is
56
+ // written. Nothing on the page is changed beyond the at-rest style and its removal; no link is followed.
57
+ // pages: { target, page }[] in screen order; ctx.screens lists every screen asked for (a screen that could not
58
+ // be opened is absent from pages but keeps its index).
59
+ export async function measureTerms(pages, ctx = {}) {
60
+ composition ??= await fs.readFile(new URL("./in-page/composition.js", import.meta.url), "utf8");
61
+ const screens = Array.isArray(ctx.screens) && ctx.screens.length ? [...ctx.screens] : pages.map((p) => p.target);
62
+ const notes = [];
63
+ const failed = [];
64
+ const opts = { read: "content", keepPinned: true };
65
+ const capMs = Number.isFinite(ctx.screenCapMs) ? ctx.screenCapMs : TERMS_SCREEN_CAP_MS;
66
+
67
+ const read = [];
68
+ const used = new Set();
69
+ for (const { target, page } of pages) {
70
+ let screen = screens.findIndex((s, i) => s === target && !used.has(i));
71
+ if (screen !== -1) used.add(screen);
72
+ else {
73
+ screens.push(target);
74
+ screen = screens.length - 1;
75
+ }
76
+ let out;
77
+ try {
78
+ // Capped (ctx.screenCapMs in tests); the at-rest style is removed on every path, under the same cap.
79
+ const read1 = (async () => {
80
+ await page.evaluate(restOn());
81
+ return page.evaluate(`(${composition})(${JSON.stringify(opts)})`);
82
+ })();
83
+ try {
84
+ out = await bounded(read1, capMs, `reading ${target}`);
85
+ } finally {
86
+ await bounded(Promise.resolve().then(() => page.evaluate(restOff())), capMs, "removing the at-rest style").catch(() => {});
87
+ }
88
+ } catch {
89
+ failed.push(target);
90
+ continue;
91
+ }
92
+ for (const n of out.notes) notes.push(`${target}: ${n}`);
93
+ read.push({ screen, items: out.items });
94
+ }
95
+ read.sort((a, b) => a.screen - b.screen);
96
+ if (failed.length) {
97
+ notes.push(`${failed.length} ${plural(failed.length, "screen", "screens")} could not be read: ${failed.join(", ")}.`);
98
+ }
99
+
100
+ // Destinations: links in navigation regions with an href and text of their own, grouped by href.
101
+ let order = 0;
102
+ const byHref = new Map();
103
+ for (const { screen, items } of read) {
104
+ for (const i of items) {
105
+ if (i.kind !== "link" && i.kind !== "button") continue;
106
+ if (!i.nav || !i.href || !i.ownText) continue;
107
+ const words = wordsOf(fold(i.text));
108
+ if (words.length === 0) continue;
109
+ const href = destinationOf(i.href);
110
+ if (!byHref.has(href)) byHref.set(href, { href, links: 0, names: new Map() });
111
+ const d = byHref.get(href);
112
+ d.links += 1;
113
+ const key = words.join(" ");
114
+ if (!d.names.has(key)) d.names.set(key, { words, text: i.text, first: order, screens: [], count: 0 });
115
+ const n = d.names.get(key);
116
+ n.count += 1;
117
+ if (!n.screens.includes(screen)) n.screens.push(screen);
118
+ order += 1;
119
+ }
120
+ }
121
+ const destinations = [...byHref.values()].filter((d) => d.links >= 2).map((d) => ({ href: d.href, names: mergeNames(d.names.values()) }));
122
+ if (destinations.length === 0) notes.push("No destination is linked from navigation more than once, so names were not compared.");
123
+
124
+ // Spellings: lowercased words and adjacent word pairs of every item's text, keyed with separators removed.
125
+ const byKey = new Map();
126
+ const words = new Set();
127
+ const add = (form, screen) => {
128
+ const key = keyOf(form);
129
+ if (!byKey.has(key)) byKey.set(key, new Map());
130
+ const forms = byKey.get(key);
131
+ if (!forms.has(form)) forms.set(form, { form, screens: [], count: 0 });
132
+ const f = forms.get(form);
133
+ f.count += 1;
134
+ if (!f.screens.includes(screen)) f.screens.push(screen);
135
+ };
136
+ for (const { screen, items } of read) {
137
+ for (const i of items) {
138
+ const list = wordsOf(i.text.toLowerCase());
139
+ list.forEach((w, k) => {
140
+ if (!hasLetter(w)) return;
141
+ words.add(w);
142
+ add(w, screen);
143
+ const next = list[k + 1];
144
+ if (next !== undefined && hasLetter(next)) add(`${w} ${next}`, screen);
145
+ });
146
+ }
147
+ }
148
+ const spellings = [...byKey]
149
+ .filter(([, forms]) => forms.size >= 2)
150
+ .map(([key, forms]) => ({ key, forms: [...forms.values()].map((f) => ({ ...f, screens: [...f.screens].sort((a, b) => a - b) })) }));
151
+
152
+ return { screens, destinations, spellings, words: words.size, notes };
153
+ }
@@ -0,0 +1,20 @@
1
+ import { FULL_PAGE_CAP_PX, FULL_PAGE_CAP_WIDTH_PX } from "../commands/capture.mjs";
2
+
3
+ // The clips that cover a page from y 0 to its full scroll height, each at most FULL_PAGE_CAP_PX tall (a
4
+ // screenshot limit), and at most FULL_PAGE_CAP_WIDTH_PX wide, with a note when the width cap cuts the page.
5
+ export async function pageTiles(page, width) {
6
+ const size = await page.evaluate(() => ({
7
+ w: Math.max(document.documentElement.scrollWidth, innerWidth),
8
+ h: Math.max(document.documentElement.scrollHeight, innerHeight),
9
+ }));
10
+ const clipWidth = Math.min(size.w, FULL_PAGE_CAP_WIDTH_PX);
11
+ const notes = [];
12
+ if (clipWidth < size.w) {
13
+ notes.push(`The full capture at ${width} px stops at ${FULL_PAGE_CAP_WIDTH_PX} px wide; the page is ${size.w} px wide.`);
14
+ }
15
+ const tiles = [];
16
+ for (let y = 0; y < size.h; y += FULL_PAGE_CAP_PX) {
17
+ tiles.push({ x: 0, y, width: clipWidth, height: Math.min(FULL_PAGE_CAP_PX, size.h - y) });
18
+ }
19
+ return { tiles, notes };
20
+ }