@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,274 @@
1
+ import { access, readdir, readFile, stat } from "node:fs/promises";
2
+ import { join, relative } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import YAML from "yaml";
5
+ import { parseHypotheses } from "./hypotheses.mjs";
6
+ import { validateArea, validateRule } from "./schema.mjs";
7
+
8
+ export const KIT_RULES_DIR = fileURLToPath(new URL("../../rules", import.meta.url));
9
+
10
+ export class RulesDirNotFoundError extends Error {
11
+ constructor(dir, message = `Rules folder not found: ${dir}`) {
12
+ super(message);
13
+ this.name = "RulesDirNotFoundError";
14
+ this.code = "RULES_DIR_NOT_FOUND";
15
+ }
16
+ }
17
+
18
+ const YAML_FILE_RE = /\.ya?ml$/;
19
+
20
+ async function listYaml(dir, { flat = false } = {}) {
21
+ const entries = await readdir(dir, { withFileTypes: true });
22
+ const files = [];
23
+ for (const entry of entries) {
24
+ const full = join(dir, entry.name);
25
+ if (entry.isDirectory()) {
26
+ if (!flat) {
27
+ files.push(...(await listYaml(full)));
28
+ }
29
+ } else if (
30
+ entry.isFile() &&
31
+ YAML_FILE_RE.test(entry.name) &&
32
+ !entry.name.startsWith("_")
33
+ ) {
34
+ files.push(full);
35
+ }
36
+ }
37
+ return files.sort();
38
+ }
39
+
40
+ async function readText(file) {
41
+ return (await readFile(file, "utf8")).replace(/^\uFEFF/, "");
42
+ }
43
+
44
+ async function exists(file) {
45
+ try {
46
+ await access(file);
47
+ return true;
48
+ } catch (err) {
49
+ if (err?.code === "ENOENT" || err?.code === "ENOTDIR") {
50
+ return false;
51
+ }
52
+ throw err;
53
+ }
54
+ }
55
+
56
+ // Reads and validates every rule file under dir. Problems are pushed, not thrown.
57
+ // File names in messages are relative to base; seen tracks ids across calls.
58
+ async function collectRules(dir, { base = dir, seen = new Map(), problems, flat = false }) {
59
+ const rules = [];
60
+ for (const file of await listYaml(dir, { flat })) {
61
+ const name = relative(base, file) || file;
62
+ let parsed;
63
+ try {
64
+ parsed = YAML.parse(await readText(file));
65
+ } catch (err) {
66
+ problems.push(`${name}: invalid YAML (${err.message})`);
67
+ continue;
68
+ }
69
+ const items = Array.isArray(parsed) ? parsed : [parsed];
70
+ for (const item of items) {
71
+ const { ok, errors } = validateRule(item);
72
+ if (!ok) {
73
+ const label = item && item.id ? ` (${item.id})` : "";
74
+ problems.push(`${name}${label}: ${errors.join("; ")}`);
75
+ continue;
76
+ }
77
+ if (seen.has(item.id)) {
78
+ problems.push(`${name}: duplicate id ${item.id} (also in ${seen.get(item.id)})`);
79
+ continue;
80
+ }
81
+ seen.set(item.id, name);
82
+ rules.push(item);
83
+ }
84
+ }
85
+ return rules;
86
+ }
87
+
88
+ export async function loadRules(dir) {
89
+ const problems = [];
90
+ const rules = await collectRules(dir, { problems });
91
+ if (problems.length > 0) {
92
+ throw new Error(`Invalid rules:\n${problems.join("\n")}`);
93
+ }
94
+ return rules;
95
+ }
96
+
97
+ const PROJECT_AREA = {
98
+ area: "project",
99
+ title: "Learned rules",
100
+ summary: "Rules this project learned from corrections, written by remember-this.",
101
+ order: 1000,
102
+ prefixes: ["LR"],
103
+ skills: [],
104
+ };
105
+
106
+ // Each declared_by id of a rule must be a rule of the kit with moment create (a move).
107
+ function declaredByProblems(own, kit) {
108
+ const problems = [];
109
+ for (const rule of own) {
110
+ for (const id of rule.declared_by ?? []) {
111
+ const move = kit.find((r) => r.id === id);
112
+ if (!move) {
113
+ problems.push(`${rule.id}: declared_by ${id} is not a rule of the kit`);
114
+ } else if (move.moment !== "create") {
115
+ problems.push(`${rule.id}: declared_by ${id} is not a create rule`);
116
+ }
117
+ }
118
+ }
119
+ return problems;
120
+ }
121
+
122
+ export async function loadKit({ dirs, projectDir }) {
123
+ const problems = [];
124
+ const seen = new Map();
125
+ const areas = [];
126
+ const rules = [];
127
+ const hypotheses = new Map();
128
+ const areaNames = new Set();
129
+ const prefixOwner = new Map();
130
+
131
+ for (const dir of dirs) {
132
+ if (!(await exists(dir))) {
133
+ throw new RulesDirNotFoundError(dir);
134
+ }
135
+ if (!(await stat(dir)).isDirectory()) {
136
+ throw new RulesDirNotFoundError(dir, `Rules path is not a folder: ${dir}`);
137
+ }
138
+ const entries = await readdir(dir, { withFileTypes: true });
139
+ const looseFiles = entries
140
+ .filter((e) => e.isFile() && YAML_FILE_RE.test(e.name))
141
+ .map((e) => e.name)
142
+ .sort();
143
+ if (looseFiles.length > 0) {
144
+ problems.push(
145
+ `${dir}: rule files sit directly in this folder (${looseFiles.join(", ")}); each area needs its own folder with _area.yaml`,
146
+ );
147
+ }
148
+ const folders = entries
149
+ .filter((e) => e.isDirectory())
150
+ .map((e) => e.name)
151
+ .sort();
152
+
153
+ for (const folder of folders) {
154
+ const areaDir = join(dir, folder);
155
+ const manifestFile = join(areaDir, "_area.yaml");
156
+ if (!(await exists(manifestFile))) {
157
+ problems.push(`${folder}: missing _area.yaml`);
158
+ continue;
159
+ }
160
+
161
+ let manifest;
162
+ try {
163
+ manifest = YAML.parse(await readText(manifestFile));
164
+ } catch (err) {
165
+ problems.push(`${folder}/_area.yaml: invalid YAML (${err.message})`);
166
+ continue;
167
+ }
168
+ const check = validateArea(manifest, folder);
169
+ if (!check.ok) {
170
+ problems.push(`${folder}/_area.yaml: ${check.errors.join("; ")}`);
171
+ continue;
172
+ }
173
+
174
+ if (areaNames.has(folder)) {
175
+ problems.push(`area ${folder} is defined twice`);
176
+ continue;
177
+ }
178
+ areaNames.add(folder);
179
+
180
+ for (const prefix of manifest.prefixes) {
181
+ if (prefixOwner.has(prefix)) {
182
+ problems.push(`prefix ${prefix} is claimed by ${prefixOwner.get(prefix)} and ${folder}`);
183
+ } else {
184
+ prefixOwner.set(prefix, folder);
185
+ }
186
+ }
187
+
188
+ let hyp = new Map();
189
+ const hypFile = join(areaDir, "HYPOTHESES.md");
190
+ if (await exists(hypFile)) {
191
+ try {
192
+ hyp = parseHypotheses(await readText(hypFile));
193
+ } catch (err) {
194
+ problems.push(`${folder}/HYPOTHESES.md: ${err.message}`);
195
+ }
196
+ }
197
+ hypotheses.set(folder, hyp);
198
+
199
+ areas.push({
200
+ area: folder,
201
+ title: manifest.title,
202
+ summary: manifest.summary,
203
+ order: manifest.order,
204
+ prefixes: manifest.prefixes,
205
+ skills: manifest.skills,
206
+ dir: areaDir,
207
+ });
208
+
209
+ const own = await collectRules(areaDir, { base: dir, seen, problems });
210
+ for (const rule of own) {
211
+ let ok = true;
212
+ if (rule.area !== folder) {
213
+ problems.push(`${rule.id}: area must be ${folder}`);
214
+ ok = false;
215
+ }
216
+ const prefix = rule.id.slice(0, 2);
217
+ if (!manifest.prefixes.includes(prefix)) {
218
+ problems.push(`${rule.id}: prefix ${prefix} is not listed in ${folder}/_area.yaml`);
219
+ ok = false;
220
+ }
221
+ if (rule.hypothesis !== undefined) {
222
+ const ids = Array.isArray(rule.hypothesis) ? rule.hypothesis : [rule.hypothesis];
223
+ for (const id of ids) {
224
+ if (!hyp.has(id)) {
225
+ problems.push(`${rule.id}: hypothesis ${id} is not in ${folder}/HYPOTHESES.md`);
226
+ ok = false;
227
+ }
228
+ }
229
+ }
230
+ if (ok) {
231
+ rules.push(rule);
232
+ }
233
+ }
234
+ }
235
+ }
236
+
237
+ problems.push(...declaredByProblems(rules, rules));
238
+ if (problems.length > 0) {
239
+ throw new Error(`Invalid rules:\n${problems.join("\n")}`);
240
+ }
241
+
242
+ const projectProblems = [];
243
+ if (projectDir && (await exists(projectDir)) && !(await stat(projectDir)).isDirectory()) {
244
+ projectProblems.push(`${projectDir}: the project rules path is not a folder`);
245
+ } else if (projectDir && (await exists(projectDir))) {
246
+ const projectRules = await collectRules(projectDir, { seen, problems: projectProblems, flat: true });
247
+ const kept = [];
248
+ for (const rule of projectRules) {
249
+ const errs = [];
250
+ if (rule.area !== "project") {
251
+ errs.push(`${rule.id}: area must be project`);
252
+ }
253
+ if (!rule.id.startsWith("LR")) {
254
+ errs.push(`${rule.id}: a learned rule id must start with LR`);
255
+ }
256
+ if (rule.origin === "norm") {
257
+ errs.push(`${rule.id}: a learned rule cannot be a norm`);
258
+ }
259
+ errs.push(...declaredByProblems([rule], [...rules, ...projectRules]));
260
+ if (errs.length > 0) {
261
+ projectProblems.push(...errs);
262
+ } else {
263
+ kept.push(rule);
264
+ }
265
+ }
266
+ if (kept.length > 0) {
267
+ areas.push({ ...PROJECT_AREA, dir: projectDir });
268
+ rules.push(...kept);
269
+ }
270
+ }
271
+
272
+ areas.sort((a, b) => a.order - b.order || a.area.localeCompare(b.area));
273
+ return { areas, rules, hypotheses, projectProblems };
274
+ }
@@ -0,0 +1,56 @@
1
+ // Patterns for process language that must not reach public kit text: pointers to the author's working
2
+ // notes, their ids and their wording. The kit text test and the release check both read this list.
3
+ // Names and regex sources are spelled with escapes and character classes so this file never matches
4
+ // its own patterns.
5
+
6
+ // Between the words of a phrase: spaces, or a line break with an optional comment marker, so a phrase
7
+ // wrapped across two comment or prose lines is still one match.
8
+ const GAP = String.raw`(?:[ \t]*\r?\n[ \t]*(?:\/\/+|#|\*)?[ \t]*|[ \t]+)`;
9
+ const words = (...parts) => parts.join(GAP);
10
+
11
+ export const PROCESS_PATTERNS = [
12
+ { name: "pre\u002dflight", re: /\bpre-?fligh[t]\b/i },
13
+ { name: "pre\u002dflight id", re: /(?<![\w-])P\d{1,2}\b/i },
14
+ { name: "plan letter", re: new RegExp(String.raw`\b(?:sub-)?` + words("plans?", String.raw`[A-K]\b`), "i") },
15
+ { name: "plan task", re: new RegExp(String.raw`\b` + words("Task", String.raw`\d+\b`), "i") },
16
+ { name: "ledg\u0065r", re: /\bledge[r]s?\b/i },
17
+ { name: "process folders", re: /docs[/]superpowers|[.]superpowers/i },
18
+ { name: "internal spec", re: new RegExp(String.raw`\b` + words("Lazuli", String.raw`spec\b`), "i") },
19
+ {
20
+ name: "process wording",
21
+ re: new RegExp(
22
+ [
23
+ words("(?:set|fixed|written|chosen)", "in", "the", "plan"),
24
+ words("the", "plan(?:'s|" + GAP + "leaves)"),
25
+ words("kit", "plan"),
26
+ "control[l]er",
27
+ words("fix", "(?:round|wave)"),
28
+ words("final", "review"),
29
+ words("(?:Minor|Important|Critical)", String.raw`\d+`),
30
+ "roadma[p]",
31
+ words("owner", "decision"),
32
+ ].map((p) => String.raw`\b` + p + String.raw`\b`).join("|"),
33
+ "i",
34
+ ),
35
+ },
36
+ ];
37
+
38
+ // Files that must hold matching samples: exempt from the process kind only.
39
+ export const PROCESS_EXEMPT = ["src/rules/public-text.mjs", "tests/kit-text.test.mjs"];
40
+
41
+ // Path prefixes of the release tool and its test, which quote process samples on purpose.
42
+ export const PROCESS_SKIP_PREFIXES = ["scripts/release/", "tests/release-"];
43
+
44
+ export function findProcessRefs(text) {
45
+ // Matched on the whole text, so a phrase may wrap; each match is reported on the line where it starts.
46
+ const all = String(text);
47
+ const found = [];
48
+ for (const { name, re } of PROCESS_PATTERNS) {
49
+ const global = new RegExp(re.source, re.flags.includes("g") ? re.flags : re.flags + "g");
50
+ for (const m of all.matchAll(global)) {
51
+ const line = all.slice(0, m.index).split("\n").length;
52
+ found.push({ name, match: m[0].replace(/\s+/g, " "), line });
53
+ }
54
+ }
55
+ return found.sort((a, b) => a.line - b.line);
56
+ }
@@ -0,0 +1,220 @@
1
+ import { measureIds, needsThreshold } from "../measure/registry.mjs";
2
+
3
+ // When a rule applies. check is for norm checks that run with every area (accessibility).
4
+ export const MOMENTS = ["create", "review", "adapt", "signal", "check"];
5
+ export const ORIGINS = ["source", "norm", "hypothesis", "project"];
6
+ export const STATUSES = ["active", "hypothesis"];
7
+
8
+ const REQUIRED_STRINGS = [
9
+ "area",
10
+ "skill",
11
+ "rule",
12
+ "why",
13
+ "source",
14
+ "when_to_break",
15
+ "break_effect",
16
+ "test",
17
+ "example",
18
+ "counterexample",
19
+ ];
20
+
21
+ const ID_RE = /^[A-Z]{2}\d{1,3}$/;
22
+ const HYPOTHESIS_RE = /^H\d{1,3}$/;
23
+
24
+ const isText = (v) => typeof v === "string" && v.trim() !== "";
25
+ const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
26
+
27
+ const AREA_RE = /^[a-z]+(-[a-z]+)*$/;
28
+ const PREFIX_RE = /^[A-Z]{2}$/;
29
+ const NAME_MAX = 60;
30
+ const TITLE_MAX = 40;
31
+ const SUMMARY_MAX = 200;
32
+
33
+ export function validateArea(manifest, folder) {
34
+ if (!isObject(manifest)) {
35
+ return { ok: false, errors: ["manifest must be an object"] };
36
+ }
37
+ const errors = [];
38
+
39
+ if (manifest.area === undefined) {
40
+ errors.push("area is required");
41
+ } else if (typeof manifest.area !== "string" || !AREA_RE.test(manifest.area)) {
42
+ errors.push(`area must match /${AREA_RE.source}/`);
43
+ } else if (manifest.area !== folder) {
44
+ errors.push(`area must equal the folder name ${folder}`);
45
+ }
46
+
47
+ for (const [key, max] of [["title", TITLE_MAX], ["summary", SUMMARY_MAX]]) {
48
+ if (manifest[key] === undefined) {
49
+ errors.push(`${key} is required`);
50
+ } else if (!isText(manifest[key])) {
51
+ errors.push(`${key} must be a non-empty string`);
52
+ } else if (manifest[key].length > max) {
53
+ errors.push(`${key} must be at most ${max} characters`);
54
+ }
55
+ }
56
+
57
+ if (manifest.order === undefined) {
58
+ errors.push("order is required");
59
+ } else if (!Number.isInteger(manifest.order)) {
60
+ errors.push("order must be an integer");
61
+ }
62
+
63
+ const p = manifest.prefixes;
64
+ if (p === undefined) {
65
+ errors.push("prefixes is required");
66
+ } else if (!Array.isArray(p) || p.length === 0) {
67
+ errors.push("prefixes must be a non-empty array");
68
+ } else {
69
+ if (!p.every((x) => typeof x === "string" && PREFIX_RE.test(x))) {
70
+ errors.push(`prefixes must each match /${PREFIX_RE.source}/`);
71
+ }
72
+ if (new Set(p).size !== p.length) {
73
+ errors.push("prefixes must not repeat");
74
+ }
75
+ }
76
+
77
+ const s = manifest.skills;
78
+ if (s === undefined) {
79
+ errors.push("skills is required");
80
+ } else if (!Array.isArray(s) || !s.every((x) => typeof x === "string" && x !== "")) {
81
+ errors.push("skills must be an array of folder names");
82
+ }
83
+
84
+ return { ok: errors.length === 0, errors };
85
+ }
86
+
87
+ // A learned rule's threshold is read by the style measurer: it needs a selector, a property and a limit.
88
+ function styleThresholdErrors(t) {
89
+ if (!isObject(t)) {
90
+ return ["threshold must be an object for style.value"];
91
+ }
92
+ const errors = [];
93
+ for (const key of ["selector", "property"]) {
94
+ if (typeof t[key] !== "string" || t[key].trim() === "") {
95
+ errors.push(`threshold.${key} must be text`);
96
+ }
97
+ }
98
+ const finite = (v) => typeof v === "number" && Number.isFinite(v);
99
+ if (t.forbid !== undefined && !(Array.isArray(t.forbid) && t.forbid.every((x) => typeof x === "string"))) {
100
+ errors.push("threshold.forbid must be a list of text");
101
+ }
102
+ for (const key of ["min", "max"]) {
103
+ if (t[key] !== undefined && !finite(t[key])) {
104
+ errors.push(`threshold.${key} must be a number`);
105
+ }
106
+ }
107
+ if (t.forbid === undefined && t.min === undefined && t.max === undefined) {
108
+ errors.push("threshold needs forbid (a list of text), min or max (a number)");
109
+ }
110
+ return errors;
111
+ }
112
+
113
+ export function validateRule(rule) {
114
+ if (!isObject(rule)) {
115
+ return { ok: false, errors: ["rule must be an object"] };
116
+ }
117
+ const errors = [];
118
+
119
+ if (rule.id === undefined) {
120
+ errors.push("id is required");
121
+ } else if (typeof rule.id !== "string" || !ID_RE.test(rule.id)) {
122
+ errors.push(`id must match /${ID_RE.source}/`);
123
+ }
124
+
125
+ for (const key of REQUIRED_STRINGS) {
126
+ if (rule[key] === undefined || rule[key] === null || rule[key] === "") {
127
+ errors.push(`${key} is required`);
128
+ } else if (!isText(rule[key])) {
129
+ errors.push(`${key} must be a non-empty string`);
130
+ }
131
+ }
132
+
133
+ // Optional parts of a composition move (ui area): when it works and when it becomes excess.
134
+ for (const key of ["works_when", "excess_when"]) {
135
+ if (rule[key] !== undefined && !isText(rule[key])) {
136
+ errors.push(`${key} must be a non-empty string`);
137
+ }
138
+ }
139
+
140
+ // The moves (create rules) whose declaration can explain this rule's finding; the loader checks they exist.
141
+ if (rule.declared_by !== undefined) {
142
+ const d = rule.declared_by;
143
+ if (!Array.isArray(d) || d.length === 0 || !d.every((x) => typeof x === "string" && ID_RE.test(x))) {
144
+ errors.push("declared_by must be a non-empty list of rule ids");
145
+ }
146
+ }
147
+
148
+ if (rule.name === undefined || rule.name === null || rule.name === "") {
149
+ errors.push("name is required");
150
+ } else if (!isText(rule.name)) {
151
+ errors.push("name must be a non-empty string");
152
+ } else if (rule.name.length > NAME_MAX) {
153
+ errors.push(`name must be at most ${NAME_MAX} characters`);
154
+ }
155
+
156
+ if (rule.moment === undefined) {
157
+ errors.push("moment is required");
158
+ } else if (!MOMENTS.includes(rule.moment)) {
159
+ errors.push(`moment must be one of ${MOMENTS.join("|")}`);
160
+ }
161
+
162
+ if (rule.origin === undefined) {
163
+ errors.push("origin is required");
164
+ } else if (!ORIGINS.includes(rule.origin)) {
165
+ errors.push(`origin must be one of ${ORIGINS.join("|")}`);
166
+ }
167
+
168
+ if (rule.measure !== undefined && !measureIds().includes(rule.measure)) {
169
+ errors.push(`measure must be one of ${measureIds().join("|")}`);
170
+ }
171
+
172
+ if (rule.measure !== undefined && measureIds().includes(rule.measure) && rule.threshold === undefined && needsThreshold(rule.measure)) {
173
+ errors.push(`measure ${rule.measure} needs a threshold`);
174
+ }
175
+
176
+ if (rule.status !== undefined && !STATUSES.includes(rule.status)) {
177
+ errors.push(`status must be one of ${STATUSES.join("|")}`);
178
+ }
179
+
180
+ if (rule.hypothesis !== undefined) {
181
+ const h = rule.hypothesis;
182
+ const ids = Array.isArray(h) ? h : [h];
183
+ const ok =
184
+ ids.length > 0 && ids.every((x) => typeof x === "string" && HYPOTHESIS_RE.test(x));
185
+ if (!ok) {
186
+ errors.push(`hypothesis must match /${HYPOTHESIS_RE.source}/`);
187
+ }
188
+ }
189
+ if (rule.status === "hypothesis" && rule.hypothesis === undefined) {
190
+ errors.push("status hypothesis needs a hypothesis id");
191
+ }
192
+
193
+ // The threshold keys that rest on the rule's hypothesis ids, on a rule that is not itself a hypothesis (ES5).
194
+ if (rule.hypothesis_keys !== undefined) {
195
+ const k = rule.hypothesis_keys;
196
+ const t = rule.threshold;
197
+ const ok = Array.isArray(k) && k.length > 0 && isObject(t) && k.every((x) => typeof x === "string" && Object.hasOwn(t, x));
198
+ if (!ok) {
199
+ errors.push("hypothesis_keys must be a non-empty list of threshold keys");
200
+ }
201
+ if (rule.hypothesis === undefined) {
202
+ errors.push("hypothesis_keys needs a hypothesis id");
203
+ }
204
+ }
205
+
206
+ if (rule.threshold !== undefined) {
207
+ const t = rule.threshold;
208
+ if (!(typeof t === "number" && Number.isFinite(t)) && !isObject(t)) {
209
+ errors.push("threshold must be a number or an object");
210
+ }
211
+ if (rule.origin !== "norm" && rule.origin !== "project" && rule.status !== "hypothesis") {
212
+ errors.push("threshold needs origin norm or project, or status hypothesis");
213
+ }
214
+ if (rule.measure === "style.value") {
215
+ errors.push(...styleThresholdErrors(t));
216
+ }
217
+ }
218
+
219
+ return { ok: errors.length === 0, errors };
220
+ }
@@ -0,0 +1,88 @@
1
+ # LAZULI.md
2
+
3
+ This file is the project memory for Lazuli. Your agent reads it before design work and writes to it.
4
+
5
+ ## Product
6
+
7
+ What it is and what it does, in one or two sentences.
8
+
9
+ ## Audience
10
+
11
+ Who uses it, their age range, country, device and context of use. The simulated task walks the main task as this person.
12
+
13
+ ## Brand
14
+
15
+ Personality in a few words, colors or logos already fixed, references you like or dislike.
16
+
17
+ <!-- Brand tokens: one bullet each, as many as the brand has. Every color, font and symbol of a derived piece is read from these lines.
18
+ - Color: ink #1a1a1a
19
+ - Font: Inter
20
+ - Symbol: brand/symbol.svg
21
+ - Symbol: brand/symbol-small.svg (up to 32 px)
22
+ A color is a name and a hex. One Symbol line is the main symbol; a simplified version for small sizes says up to how many pixels it serves. -->
23
+
24
+ ## Platform and constraints
25
+
26
+ Web, app or print. Fixed fonts, frameworks, accessibility targets, deadlines.
27
+
28
+ ## Language
29
+
30
+ The language of the interface and the copy.
31
+
32
+ ## Voice
33
+
34
+ Three traits of how the product speaks, each as "this, not that", with one sample sentence each. Words you always use and words you avoid. How the tone changes in errors, empty states and success.
35
+
36
+ ## Mode
37
+
38
+ director
39
+
40
+ <!-- director: you decide, the kit asks before it changes anything. delegate: the kit decides and explains. Write one of the two words on the line above. -->
41
+
42
+ ## Idea
43
+
44
+ One sentence that links something only this client has to a visual device. Every screen carries it.
45
+
46
+ ## Goals
47
+
48
+ One entry per screen or piece: what it must make people understand, feel and do.
49
+
50
+ <!-- Do: is written as a task a person can try on that page (for example book a first visit). The simulated task walks it. -->
51
+
52
+ <!-- For the options stage, one goal can cover a folder: Target: ./options/*.html. A break or decision can add Target: <one file> to apply to that file only. -->
53
+
54
+ - Piece: (name)
55
+ - Target: (URL or file path of the page, optional)
56
+ - Understand:
57
+ - Feel:
58
+ - Do:
59
+ - Rhythm: (optional: one beat per section, top to bottom, from breathe, steady, accelerate, climax; exactly one climax)
60
+ - Size: (derived pieces only: the canvas in pixels, 1200x630, or square sizes 16, 32, 180, 512)
61
+
62
+ ## Breaks
63
+
64
+ A log of rules broken on purpose, one entry each. Copy the format below outside the comment.
65
+
66
+ <!--
67
+ - Rule: (rule id, for example PA4)
68
+ - Piece: (name of the piece, as in Goals)
69
+ - Effect: (the effect you intend)
70
+ - Check: (the check planned for the effect when the break is logged: a measurement, a separate reviewer or a test with people)
71
+ - Status: (trying, kept or reverted)
72
+ -->
73
+
74
+ ## Decisions
75
+
76
+ Design decisions that follow or break a rule, one entry each. Copy the format below outside the comment.
77
+
78
+ <!--
79
+ - Decision: (what you decided, in a few words)
80
+ - Piece: (name of the piece, as in Goals)
81
+ - Goal: (the goal it serves)
82
+ - Rule: (rule id and followed, broken or accepted, for example PA4 followed; accepted is a hint left open on purpose, its reason in the decision; none when the decision is tied to no rule)
83
+ - Measure: (what you measured)
84
+ -->
85
+
86
+ ## Learned rules
87
+
88
+ Rules this project discovered by itself, with the evidence that supports them.