@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,132 @@
1
+ import { cp, lstat, mkdir, readdir, realpath, rm, writeFile } from "node:fs/promises";
2
+ import { homedir } from "node:os";
3
+ import { basename, dirname, join, relative, resolve, isAbsolute } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+
6
+ const DEFAULT_KIT = resolve(fileURLToPath(new URL("../../", import.meta.url)));
7
+
8
+ // A kit run through npx lives in the npm cache, which npm can clear at any time.
9
+ export function isEphemeralKit(kitRoot) {
10
+ return resolve(kitRoot).split(/[\\/]/).includes("_npx");
11
+ }
12
+
13
+ export function defaultTarget() {
14
+ return join(homedir(), ".claude", "skills");
15
+ }
16
+
17
+ // Real path of the nearest existing ancestor, plus the part that does not exist yet.
18
+ async function realOrNearest(p) {
19
+ let cur = resolve(p);
20
+ const rest = [];
21
+ for (;;) {
22
+ try {
23
+ return join(await realpath(cur), ...rest);
24
+ } catch {
25
+ const up = dirname(cur);
26
+ if (up === cur) return resolve(p);
27
+ rest.unshift(cur.slice(up.length).replace(/^[\\/]/, ""));
28
+ cur = up;
29
+ }
30
+ }
31
+ }
32
+
33
+ const norm = (p) => (process.platform === "win32" ? p.toLowerCase() : p);
34
+ const isInside = (child, parent) => {
35
+ const rel = relative(norm(parent), norm(child));
36
+ return rel === "" || (!rel.startsWith("..") && !isAbsolute(rel));
37
+ };
38
+
39
+ async function isLink(p) {
40
+ try {
41
+ return (await lstat(p)).isSymbolicLink(); // junctions report as links on Windows
42
+ } catch {
43
+ return false;
44
+ }
45
+ }
46
+
47
+ // Deleting through a symlink or junction would delete its target, and a target inside
48
+ // the kit would delete the kit's own skills. Refuse both before anything is touched.
49
+ async function guard(target, kit, destinations) {
50
+ if (await isLink(target)) throw new Error(`Refusing to install into ${target}: it is a symlink or junction.`);
51
+ const kitReal = await realOrNearest(kit);
52
+ if (isInside(await realOrNearest(target), kitReal)) {
53
+ throw new Error(`Refusing to install into ${target}: it is inside the Lazuli kit (${kit}).`);
54
+ }
55
+ // A destination that is, or contains, the kit would be deleted before it is copied from.
56
+ for (const dest of destinations) {
57
+ if (isInside(kitReal, await realOrNearest(dest))) {
58
+ throw new Error(`Refusing to install into ${target}: ${dest} is or contains the Lazuli kit (${kit}).`);
59
+ }
60
+ }
61
+ }
62
+
63
+ async function replace(src, dest) {
64
+ if (await isLink(dest)) throw new Error(`Refusing to replace ${dest}: it is a symlink or junction.`);
65
+ await rm(dest, { recursive: true, force: true });
66
+ await cp(src, dest, { recursive: true });
67
+ }
68
+
69
+ // Agents go beside a skills folder (~/.claude/skills gives ~/.claude/agents). For any other target they stay
70
+ // inside the folder the person named, and the caller says where to move them.
71
+ export function resolveAgentsTarget({ target, agentsTarget }) {
72
+ if (agentsTarget) return { dir: resolve(agentsTarget), beside: true };
73
+ if (basename(resolve(target)) === "skills") return { dir: join(dirname(resolve(target)), "agents"), beside: true };
74
+ return { dir: join(target, "lazuli", "agents"), beside: false };
75
+ }
76
+
77
+ async function listAgents(kit) {
78
+ try {
79
+ return (await readdir(join(kit, "agents"), { withFileTypes: true })).filter((e) => e.isFile() && /^lazuli-.*\.md$/.test(e.name)).map((e) => e.name);
80
+ } catch {
81
+ return [];
82
+ }
83
+ }
84
+
85
+ export async function install({ target = defaultTarget(), kitRoot = DEFAULT_KIT, agentsTarget } = {}) {
86
+ const KIT = resolve(kitRoot);
87
+ if (isEphemeralKit(KIT)) {
88
+ const err = new Error("Lazuli is running from the npx cache, which npm can clear at any time. Install it for good first: npm i -g @uselazuli/cli, then run lazuli install.");
89
+ err.code = "INSTALL_EPHEMERAL";
90
+ throw err;
91
+ }
92
+ const agentFiles = await listAgents(KIT);
93
+ const agents = resolveAgentsTarget({ target, agentsTarget });
94
+ const skillsDir = join(KIT, "skills");
95
+ const entries = (await readdir(skillsDir, { withFileTypes: true })).filter((e) => e.isDirectory());
96
+ await guard(target, KIT, [
97
+ ...entries.map((e) => join(target, e.name)),
98
+ join(target, "lazuli", "rules"),
99
+ join(target, "lazuli", "templates"),
100
+ ]);
101
+ if (agentFiles.length > 0) {
102
+ await guard(agents.dir, KIT, agentFiles.map((f) => join(agents.dir, f)));
103
+ }
104
+ await mkdir(target, { recursive: true });
105
+ const installed = [];
106
+ for (const { name } of entries) {
107
+ const dest = join(target, name);
108
+ await replace(join(skillsDir, name), dest);
109
+ installed.push(dest);
110
+ }
111
+ // Written after the skills loop, which replaces <target>/lazuli.
112
+ const rulesDest = join(target, "lazuli", "rules");
113
+ await replace(join(KIT, "rules"), rulesDest);
114
+ installed.push(rulesDest);
115
+ const templatesDest = join(target, "lazuli", "templates");
116
+ await replace(join(KIT, "templates"), templatesDest);
117
+ installed.push(templatesDest);
118
+ // The router skill reads this to run `node "<KIT_PATH>/bin/lazuli.mjs" <command>`.
119
+ const kitFile = join(target, "lazuli", "KIT_PATH");
120
+ await writeFile(kitFile, `${KIT}\n`, "utf8");
121
+ installed.push(kitFile);
122
+ // After the skills loop: a default agents folder inside <target>/lazuli would have been replaced by it.
123
+ if (agentFiles.length > 0) {
124
+ await mkdir(agents.dir, { recursive: true });
125
+ for (const f of agentFiles) {
126
+ const dest = join(agents.dir, f);
127
+ await replace(join(KIT, "agents", f), dest);
128
+ installed.push(dest);
129
+ }
130
+ }
131
+ return installed;
132
+ }
@@ -0,0 +1,49 @@
1
+ import path from "node:path";
2
+ import { KIT_RULES_DIR, loadKit } from "../rules/load.mjs";
3
+ import { MOMENTS } from "../rules/schema.mjs";
4
+
5
+ export class ListRulesInputError extends Error {
6
+ constructor(message) {
7
+ super(message);
8
+ this.name = "ListRulesInputError";
9
+ this.code = "LIST_RULES_INPUT";
10
+ }
11
+ }
12
+
13
+ // Kit rules plus the project's learned rules, optionally narrowed to one moment and some areas.
14
+ export async function listRules({ cwd = process.cwd(), moment, areas: wanted } = {}) {
15
+ if (moment !== undefined && !MOMENTS.includes(moment)) {
16
+ throw new ListRulesInputError(`Unknown moment ${moment}. Known moments: ${MOMENTS.join(", ")}.`);
17
+ }
18
+ const kit = await loadKit({
19
+ dirs: [process.env.LAZULI_RULES_DIR ?? KIT_RULES_DIR],
20
+ projectDir: path.join(cwd, ".lazuli", "rules"),
21
+ });
22
+ // The project area exists only once a learned rule loads, but it is always a valid name to ask for.
23
+ const known = [...new Set([...kit.areas.map((a) => a.area), "project"])];
24
+ for (const name of wanted ?? []) {
25
+ if (!known.includes(name)) {
26
+ throw new ListRulesInputError(`Unknown area ${name}. Known areas: ${known.join(", ")}.`);
27
+ }
28
+ }
29
+ const rules = kit.rules.filter((r) => (!moment || r.moment === moment) && (!wanted || wanted.includes(r.area)));
30
+ const noLearned = (wanted ?? []).includes("project") && !rules.some((r) => r.area === "project");
31
+ return { rules, areas: kit.areas, projectProblems: kit.projectProblems, noLearned };
32
+ }
33
+
34
+ export function formatRules({ rules, areas, projectProblems, noLearned }) {
35
+ const lines = [];
36
+ for (const a of areas) {
37
+ const own = rules.filter((r) => r.area === a.area);
38
+ if (own.length === 0) continue;
39
+ if (lines.length) lines.push("");
40
+ lines.push(a.title);
41
+ for (const r of own) lines.push(`${r.id} ${r.name}: ${r.rule}`);
42
+ }
43
+ if (noLearned && projectProblems.length === 0) lines.push("No learned rules yet.");
44
+ if (projectProblems.length > 0) {
45
+ if (lines.length) lines.push("");
46
+ lines.push("Learned rules problems (these rules were skipped):", ...projectProblems.map((p) => ` - ${p}`));
47
+ }
48
+ return lines.join("\n");
49
+ }