@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.
- package/CHANGELOG.md +98 -0
- package/LICENSE +21 -0
- package/README.md +202 -2
- package/agents/lazuli-design-reviewer.md +30 -0
- package/agents/lazuli-first-look.md +22 -0
- package/agents/lazuli-task-tester.md +25 -0
- package/bin/lazuli.mjs +699 -0
- package/package.json +11 -4
- package/rules/accessibility/HYPOTHESES.md +8 -0
- package/rules/accessibility/_area.yaml +7 -0
- package/rules/accessibility/operable.yaml +100 -0
- package/rules/accessibility/perceivable.yaml +153 -0
- package/rules/accessibility/robust.yaml +24 -0
- package/rules/accessibility/understandable.yaml +72 -0
- package/rules/color/HYPOTHESES.md +27 -0
- package/rules/color/_area.yaml +10 -0
- package/rules/color/adapt.yaml +183 -0
- package/rules/color/create.yaml +259 -0
- package/rules/color/review.yaml +215 -0
- package/rules/color/signal.yaml +196 -0
- package/rules/content/HYPOTHESES.md +18 -0
- package/rules/content/_area.yaml +8 -0
- package/rules/content/review.yaml +347 -0
- package/rules/content/voice.yaml +144 -0
- package/rules/content/writing.yaml +202 -0
- package/rules/data/HYPOTHESES.md +11 -0
- package/rules/data/_area.yaml +7 -0
- package/rules/data/charts.yaml +189 -0
- package/rules/data/dashboards.yaml +141 -0
- package/rules/data/review.yaml +159 -0
- package/rules/graphic/HYPOTHESES.md +17 -0
- package/rules/graphic/_area.yaml +8 -0
- package/rules/graphic/identity.yaml +141 -0
- package/rules/graphic/pieces.yaml +164 -0
- package/rules/graphic/review.yaml +242 -0
- package/rules/graphic/symbol.yaml +141 -0
- package/rules/motion/HYPOTHESES.md +19 -0
- package/rules/motion/_area.yaml +7 -0
- package/rules/motion/micro.yaml +143 -0
- package/rules/motion/review.yaml +347 -0
- package/rules/motion/transitions.yaml +169 -0
- package/rules/typography/HYPOTHESES.md +12 -0
- package/rules/typography/_area.yaml +8 -0
- package/rules/typography/adapt.yaml +45 -0
- package/rules/typography/create.yaml +126 -0
- package/rules/typography/review.yaml +127 -0
- package/rules/ui/HYPOTHESES.md +23 -0
- package/rules/ui/_area.yaml +9 -0
- package/rules/ui/compose.yaml +219 -0
- package/rules/ui/grid.yaml +75 -0
- package/rules/ui/review.yaml +399 -0
- package/rules/ui/states.yaml +257 -0
- package/rules/ux/HYPOTHESES.md +13 -0
- package/rules/ux/_area.yaml +8 -0
- package/rules/ux/flows.yaml +164 -0
- package/rules/ux/forms.yaml +142 -0
- package/rules/ux/review.yaml +186 -0
- package/skills/lazuli/SKILL.md +180 -0
- package/skills/lazuli/procedures/create.md +29 -0
- package/skills/lazuli/procedures/explain-decisions.md +22 -0
- package/skills/lazuli/procedures/improve.md +30 -0
- package/skills/lazuli/procedures/remember-this.md +41 -0
- package/skills/lazuli/procedures/review-design.md +35 -0
- package/skills/lazuli/procedures/show-options.md +32 -0
- package/skills/lazuli-accessibility-check/SKILL.md +68 -0
- package/skills/lazuli-color-context-and-culture/SKILL.md +53 -0
- package/skills/lazuli-color-context-and-culture/references/sectors.md +26 -0
- package/skills/lazuli-color-palette-by-intent/SKILL.md +54 -0
- package/skills/lazuli-color-palette-by-intent/references/intent-chords.md +51 -0
- package/skills/lazuli-color-screen-review/SKILL.md +51 -0
- package/skills/lazuli-color-states-and-signals/SKILL.md +53 -0
- package/skills/lazuli-content-interface-writing/SKILL.md +53 -0
- package/skills/lazuli-content-voice/SKILL.md +39 -0
- package/skills/lazuli-data-charts-and-dashboards/SKILL.md +59 -0
- package/skills/lazuli-graphic-derived-pieces/SKILL.md +40 -0
- package/skills/lazuli-graphic-derived-pieces/references/piece-template.html +24 -0
- package/skills/lazuli-graphic-identity/SKILL.md +43 -0
- package/skills/lazuli-motion-micro-and-transitions/SKILL.md +49 -0
- package/skills/lazuli-typography-choose-and-pair/SKILL.md +50 -0
- package/skills/lazuli-typography-screen-review/SKILL.md +51 -0
- package/skills/lazuli-ui-composition/SKILL.md +42 -0
- package/skills/lazuli-ui-composition/references/option-template.html +34 -0
- package/skills/lazuli-ui-layout-review/SKILL.md +47 -0
- package/skills/lazuli-ui-states-and-system/SKILL.md +54 -0
- package/skills/lazuli-ux-flows-and-forms/SKILL.md +51 -0
- package/skills/lazuli-ux-task-test/SKILL.md +44 -0
- package/src/browser.mjs +161 -0
- package/src/commands/capture.mjs +313 -0
- package/src/commands/catalog.mjs +37 -0
- package/src/commands/check-design.mjs +428 -0
- package/src/commands/check-goals.mjs +57 -0
- package/src/commands/compare-designs.mjs +97 -0
- package/src/commands/draft-memo.mjs +161 -0
- package/src/commands/hooks.mjs +343 -0
- package/src/commands/install-hooks.mjs +120 -0
- package/src/commands/install.mjs +132 -0
- package/src/commands/list-rules.mjs +49 -0
- package/src/commands/map-page.mjs +594 -0
- package/src/commands/record-answers.mjs +79 -0
- package/src/commands/record-log.mjs +296 -0
- package/src/commands/record-task.mjs +250 -0
- package/src/commands/render-options.mjs +164 -0
- package/src/commands/start-project.mjs +32 -0
- package/src/measure/a11y.mjs +383 -0
- package/src/measure/asset.mjs +206 -0
- package/src/measure/at-rest.mjs +49 -0
- package/src/measure/cases.mjs +549 -0
- package/src/measure/chart-read.mjs +401 -0
- package/src/measure/chart.mjs +264 -0
- package/src/measure/coherence.mjs +145 -0
- package/src/measure/color.mjs +79 -0
- package/src/measure/content.mjs +82 -0
- package/src/measure/cvd.mjs +24 -0
- package/src/measure/extreme.mjs +241 -0
- package/src/measure/forms.mjs +150 -0
- package/src/measure/in-page/a11y.js +489 -0
- package/src/measure/in-page/color.js +346 -0
- package/src/measure/in-page/composition.js +1496 -0
- package/src/measure/in-page/contrast.js +15 -0
- package/src/measure/in-page/cvd.js +173 -0
- package/src/measure/in-page/extreme.js +355 -0
- package/src/measure/in-page/frames.js +781 -0
- package/src/measure/in-page/look.js +28 -0
- package/src/measure/in-page/motion-probe.js +169 -0
- package/src/measure/in-page/style.js +107 -0
- package/src/measure/in-page/svg-strokes.js +112 -0
- package/src/measure/in-page/svg-uses.js +50 -0
- package/src/measure/in-page/symbol.js +123 -0
- package/src/measure/in-page/type.js +266 -0
- package/src/measure/in-page/weight.js +207 -0
- package/src/measure/layout.mjs +91 -0
- package/src/measure/motion.mjs +508 -0
- package/src/measure/piece.mjs +195 -0
- package/src/measure/registry.mjs +252 -0
- package/src/measure/rhythm.mjs +81 -0
- package/src/measure/signature.mjs +65 -0
- package/src/measure/states.mjs +240 -0
- package/src/measure/style.mjs +13 -0
- package/src/measure/symbol.mjs +268 -0
- package/src/measure/terms.mjs +153 -0
- package/src/measure/tiles.mjs +20 -0
- package/src/measure/timeline.mjs +621 -0
- package/src/measure/type.mjs +167 -0
- package/src/measure/weight.mjs +18 -0
- package/src/private-strings.mjs +81 -0
- package/src/project/blind.mjs +70 -0
- package/src/project/edits.mjs +154 -0
- package/src/project/gate.mjs +159 -0
- package/src/project/lazuli-md.mjs +497 -0
- package/src/project/log.mjs +329 -0
- package/src/project/match.mjs +112 -0
- package/src/project/records.mjs +380 -0
- package/src/project/tasks.mjs +153 -0
- package/src/report/evaluate.mjs +27 -0
- package/src/report/evaluators/a11y.mjs +206 -0
- package/src/report/evaluators/chart.mjs +151 -0
- package/src/report/evaluators/coherence.mjs +103 -0
- package/src/report/evaluators/color.mjs +86 -0
- package/src/report/evaluators/content.mjs +112 -0
- package/src/report/evaluators/extreme.mjs +53 -0
- package/src/report/evaluators/forms.mjs +116 -0
- package/src/report/evaluators/layout.mjs +94 -0
- package/src/report/evaluators/motion.mjs +273 -0
- package/src/report/evaluators/piece.mjs +69 -0
- package/src/report/evaluators/rhythm.mjs +99 -0
- package/src/report/evaluators/states.mjs +39 -0
- package/src/report/evaluators/style.mjs +35 -0
- package/src/report/evaluators/symbol.mjs +110 -0
- package/src/report/evaluators/terms.mjs +49 -0
- package/src/report/evaluators/type.mjs +163 -0
- package/src/report/evaluators/weight.mjs +51 -0
- package/src/report/evidence.mjs +4 -0
- package/src/report/finding.mjs +11 -0
- package/src/report/format.mjs +215 -0
- package/src/rules/hypotheses.mjs +28 -0
- package/src/rules/load.mjs +256 -0
- package/src/rules/public-text.mjs +56 -0
- package/src/rules/schema.mjs +212 -0
- package/templates/LAZULI.md +86 -0
package/bin/lazuli.mjs
ADDED
|
@@ -0,0 +1,699 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { checkDesign } from "../src/commands/check-design.mjs";
|
|
5
|
+
import { startProject } from "../src/commands/start-project.mjs";
|
|
6
|
+
import { install, defaultTarget, resolveAgentsTarget } from "../src/commands/install.mjs";
|
|
7
|
+
import { listRules, formatRules } from "../src/commands/list-rules.mjs";
|
|
8
|
+
import { recordBreak, recordDecision } from "../src/commands/record-log.mjs";
|
|
9
|
+
import { capture } from "../src/commands/capture.mjs";
|
|
10
|
+
import { recordFirstLook, recordReview } from "../src/commands/record-answers.mjs";
|
|
11
|
+
import { checkGoals, formatGate } from "../src/commands/check-goals.mjs";
|
|
12
|
+
import { draftMemo } from "../src/commands/draft-memo.mjs";
|
|
13
|
+
import { optionLabel, renderOptions } from "../src/commands/render-options.mjs";
|
|
14
|
+
import { compareDesigns, formatCompare } from "../src/commands/compare-designs.mjs";
|
|
15
|
+
import { mapPage } from "../src/commands/map-page.mjs";
|
|
16
|
+
import { recordTaskStep } from "../src/commands/record-task.mjs";
|
|
17
|
+
import { handlePostEdit, handleStop } from "../src/commands/hooks.mjs";
|
|
18
|
+
import { installHooks } from "../src/commands/install-hooks.mjs";
|
|
19
|
+
import { COMMANDS, HELPERS, availableCommands } from "../src/commands/catalog.mjs";
|
|
20
|
+
import { formatReport } from "../src/report/format.mjs";
|
|
21
|
+
import { parseSizes } from "../src/project/lazuli-md.mjs";
|
|
22
|
+
|
|
23
|
+
// The one place usage text lives: the lines each command prints on bad input and on --help.
|
|
24
|
+
const USAGE = {
|
|
25
|
+
"start-project": ["Usage: lazuli start-project [--mode director|delegate]"],
|
|
26
|
+
"check-design": [
|
|
27
|
+
"Usage: lazuli check-design <url-or-path> [<more screens>...] [--site] [--width 1440,390] [--area color,typography] [--json] [--out <file>]",
|
|
28
|
+
" lazuli check-design --asset <file-or-url> [--size 1200x630] [--area graphic] [--json] [--out <file>]",
|
|
29
|
+
],
|
|
30
|
+
capture: ["Usage: lazuli capture <url-or-path> [--width 1440,390]"],
|
|
31
|
+
"check-goals": ["Usage: lazuli check-goals [<url-or-path>]"],
|
|
32
|
+
"draft-memo": ["Usage: lazuli draft-memo [<url-or-path>] [--out <file>]"],
|
|
33
|
+
"list-rules": ["Usage: lazuli list-rules [--moment create] [--area color,project] [--json]"],
|
|
34
|
+
"render-options": ["Usage: lazuli render-options <folder> [--width 1440|390] [--json]"],
|
|
35
|
+
"compare-designs": ["Usage: lazuli compare-designs <url-or-path> --baseline <url-or-path> [--width 1440,390] [--json]"],
|
|
36
|
+
"map-page": ["Usage: lazuli map-page <url-or-path> --piece <name> [--width 390]", " lazuli map-page --task <id> [<url-or-path>]"],
|
|
37
|
+
"record-task": ["Usage: lazuli record-task --file <json>"],
|
|
38
|
+
"record-break": ["Usage: lazuli record-break --rule <id>[,<id>...] --piece <name> [--effect <text>] [--check <text>] --status trying|kept|reverted"],
|
|
39
|
+
"record-decision": ['Usage: lazuli record-decision --decision <text> --piece <name> --goal <text> --rule "<id> followed|broken|accepted|none" --measure <text>'],
|
|
40
|
+
"record-first-look": ["Usage: lazuli record-first-look --file <json>"],
|
|
41
|
+
"record-review": ["Usage: lazuli record-review --file <json>"],
|
|
42
|
+
install: ["Usage: lazuli install [--target <dir>] [--agents-target <dir>]"],
|
|
43
|
+
"install-hooks": ["Usage: lazuli install-hooks [--project <dir>] [--remove]"],
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
function printUsage(name) {
|
|
47
|
+
for (const line of USAGE[name]) console.error(line);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function usage() {
|
|
51
|
+
const setup = [
|
|
52
|
+
{ name: "install", summary: "Copy the Lazuli skills into your agent (default ~/.claude/skills). Options: --target <dir>, --agents-target <dir>." },
|
|
53
|
+
{ name: "install-hooks", summary: "Add the opt-in Claude Code hooks to .claude/settings.local.json. Options: --project <dir>, --remove." },
|
|
54
|
+
];
|
|
55
|
+
const cli = availableCommands().filter((c) => c.runs === "cli");
|
|
56
|
+
const agent = availableCommands().filter((c) => c.runs === "agent");
|
|
57
|
+
// Commands, agent procedures and Setup share one column, wide enough for the longest name.
|
|
58
|
+
const cpad = Math.max(...[...cli, ...agent, ...setup].map((c) => c.name.length)) + 2;
|
|
59
|
+
const lines = ["Usage: lazuli <command>", "", "Commands (run here):"];
|
|
60
|
+
for (const c of cli) lines.push(` ${c.name.padEnd(cpad)}${c.summary}`);
|
|
61
|
+
lines.push("", "In your AI agent (type /lazuli <name>):");
|
|
62
|
+
for (const c of agent) lines.push(` ${c.name.padEnd(cpad)}${c.summary}`);
|
|
63
|
+
const pad = Math.max(...HELPERS.map((h) => h.name.length)) + 2;
|
|
64
|
+
lines.push("", "Agent helpers:");
|
|
65
|
+
for (const h of HELPERS) lines.push(` ${h.name.padEnd(pad)}${h.summary}`);
|
|
66
|
+
lines.push("", "Setup:");
|
|
67
|
+
for (const s of setup) lines.push(` ${s.name.padEnd(cpad)}${s.summary}`);
|
|
68
|
+
return lines.join("\n");
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async function readStdin() {
|
|
72
|
+
if (process.stdin.isTTY) return "";
|
|
73
|
+
let text = "";
|
|
74
|
+
process.stdin.setEncoding("utf8");
|
|
75
|
+
for await (const chunk of process.stdin) text += chunk;
|
|
76
|
+
return text;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Hooks always exit 0 (exit 2 would block the agent); every problem becomes a systemMessage. The process exits
|
|
80
|
+
// as soon as the output is written, so nothing left open can hold the agent.
|
|
81
|
+
async function runHook(event, options = []) {
|
|
82
|
+
let stdout;
|
|
83
|
+
// --project <dir>, written by install-hooks. Missing or without a value, the hook uses the cwd of its input.
|
|
84
|
+
const at = options.indexOf("--project");
|
|
85
|
+
const projectDir = at !== -1 && typeof options[at + 1] === "string" && options[at + 1] !== "" && !options[at + 1].startsWith("--") ? options[at + 1] : undefined;
|
|
86
|
+
try {
|
|
87
|
+
const handlers = { "post-edit": handlePostEdit, stop: handleStop };
|
|
88
|
+
if (!Object.hasOwn(handlers, event)) {
|
|
89
|
+
stdout = JSON.stringify({ systemMessage: `Lazuli has no hook named "${event}"; nothing was checked. Run lazuli install-hooks again.` });
|
|
90
|
+
} else {
|
|
91
|
+
let input;
|
|
92
|
+
try {
|
|
93
|
+
input = JSON.parse((await readStdin()).replace(/^/, ""));
|
|
94
|
+
} catch {
|
|
95
|
+
input = undefined;
|
|
96
|
+
}
|
|
97
|
+
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
98
|
+
stdout = JSON.stringify({ systemMessage: `Lazuli could not read the hook input (not a JSON object), so the ${event} hook checked nothing.` });
|
|
99
|
+
} else {
|
|
100
|
+
stdout = (await handlers[event](input, projectDir ? { projectDir } : {})).stdout;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
} catch (err) {
|
|
104
|
+
const line = String(err?.message ?? err).split(/\r?\n/)[0];
|
|
105
|
+
stdout = JSON.stringify({ systemMessage: `Lazuli ${event} hook failed: ${line}. Nothing was blocked.` });
|
|
106
|
+
}
|
|
107
|
+
process.stdout.write(stdout, () => process.exit(0));
|
|
108
|
+
return new Promise(() => {});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function runInstallHooks(rest) {
|
|
112
|
+
let projectDir;
|
|
113
|
+
let remove = false;
|
|
114
|
+
for (let i = 0; i < rest.length; i++) {
|
|
115
|
+
const a = rest[i];
|
|
116
|
+
if (a === "--remove") {
|
|
117
|
+
remove = true;
|
|
118
|
+
} else if (a === "--project" && rest[i + 1] && !rest[i + 1].startsWith("--")) {
|
|
119
|
+
projectDir = rest[++i];
|
|
120
|
+
} else {
|
|
121
|
+
console.error(a === "--project" ? "--project needs a folder." : `Unknown argument ${a}.`);
|
|
122
|
+
printUsage("install-hooks");
|
|
123
|
+
return 2;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
try {
|
|
127
|
+
const r = await installHooks({ ...(projectDir ? { projectDir } : {}), remove });
|
|
128
|
+
if (remove) {
|
|
129
|
+
console.log(r.removed > 0 ? `Removed ${r.removed} Lazuli hook handler${r.removed === 1 ? "" : "s"} from ${r.file}.` : `No Lazuli hooks in ${r.file}; nothing removed.`);
|
|
130
|
+
} else {
|
|
131
|
+
console.log(
|
|
132
|
+
[
|
|
133
|
+
`${r.changed ? "Added" : "Already installed in"} ${r.file}${r.changed ? ":" : "."}`,
|
|
134
|
+
...(r.changed ? [" PostToolUse (Edit|Write): lazuli hook post-edit runs check-design after a design file edit.", " Stop: lazuli hook stop runs the effect gate at the end of a turn."] : []),
|
|
135
|
+
"Remove with: lazuli install-hooks --remove",
|
|
136
|
+
].join("\n"),
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
return 0;
|
|
140
|
+
} catch (err) {
|
|
141
|
+
console.error(err?.code === "SETTINGS_INVALID" ? `${err.file} is not valid JSON; left untouched.` : `Error: ${err?.message ?? err}`);
|
|
142
|
+
return 2;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function parseCheckArgs(args) {
|
|
147
|
+
let target;
|
|
148
|
+
const screens = [];
|
|
149
|
+
let site = false;
|
|
150
|
+
let widths;
|
|
151
|
+
let areas;
|
|
152
|
+
let json = false;
|
|
153
|
+
let asset;
|
|
154
|
+
let sizes;
|
|
155
|
+
let copyTo;
|
|
156
|
+
for (let i = 0; i < args.length; i++) {
|
|
157
|
+
const a = args[i];
|
|
158
|
+
if (a === "--out") {
|
|
159
|
+
const raw = args[++i];
|
|
160
|
+
if (!raw || raw.startsWith("--")) return { error: "--out needs a file path." };
|
|
161
|
+
copyTo = raw;
|
|
162
|
+
} else if (a === "--asset") {
|
|
163
|
+
const raw = args[++i];
|
|
164
|
+
if (!raw || raw.startsWith("--")) {
|
|
165
|
+
return { error: "--asset needs a file path or URL of an SVG, PNG or ICO symbol, or an HTML, PNG, JPG or WebP piece." };
|
|
166
|
+
}
|
|
167
|
+
asset = raw;
|
|
168
|
+
} else if (a === "--size") {
|
|
169
|
+
sizes = parseSizes(args[++i]);
|
|
170
|
+
if (!sizes) return { error: "--size needs sizes such as 1200x630 or 16,32,180." };
|
|
171
|
+
} else if (a === "--json") {
|
|
172
|
+
json = true;
|
|
173
|
+
} else if (a === "--site") {
|
|
174
|
+
site = true;
|
|
175
|
+
} else if (a === "--width") {
|
|
176
|
+
const raw = args[++i];
|
|
177
|
+
const parts = (raw ?? "").split(",");
|
|
178
|
+
if (!raw || parts.some((p) => !/^\d+$/.test(p) || Number(p) < 200 || Number(p) > 4000)) {
|
|
179
|
+
return { error: "--width needs a comma list of pixel widths, for example --width 1440,390." };
|
|
180
|
+
}
|
|
181
|
+
widths = parts.map(Number);
|
|
182
|
+
} else if (a === "--area") {
|
|
183
|
+
const raw = args[++i];
|
|
184
|
+
const parts = (raw ?? "").split(",");
|
|
185
|
+
if (!raw || parts.some((p) => !p)) {
|
|
186
|
+
return { error: "--area needs a comma list of area names, for example --area color,typography." };
|
|
187
|
+
}
|
|
188
|
+
areas = parts;
|
|
189
|
+
} else if (a.startsWith("--")) {
|
|
190
|
+
return { error: `Unknown option ${a}.` };
|
|
191
|
+
} else if (!target) {
|
|
192
|
+
target = a;
|
|
193
|
+
} else {
|
|
194
|
+
screens.push(a);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
if (sizes && asset === undefined) return { error: "--size only applies with --asset." };
|
|
198
|
+
if (asset !== undefined) {
|
|
199
|
+
if (target) return { error: "check-design --asset checks one asset; give no page target with it." };
|
|
200
|
+
if (site || widths) return { error: "--site and --width do not apply to --asset; a piece takes its size from Size: or --size." };
|
|
201
|
+
return { asset, sizes, areas, json, copyTo };
|
|
202
|
+
}
|
|
203
|
+
if (!target) return { error: "check-design needs a URL or an HTML file path." };
|
|
204
|
+
return { target, screens, site, widths, areas, json, copyTo };
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
function parseCaptureArgs(args) {
|
|
208
|
+
let target;
|
|
209
|
+
let widths;
|
|
210
|
+
for (let i = 0; i < args.length; i++) {
|
|
211
|
+
const a = args[i];
|
|
212
|
+
if (a === "--width") {
|
|
213
|
+
const raw = args[++i];
|
|
214
|
+
const parts = (raw ?? "").split(",");
|
|
215
|
+
if (!raw || parts.some((p) => !/^\d+$/.test(p) || Number(p) < 200 || Number(p) > 4000)) {
|
|
216
|
+
return { error: "--width needs a comma list of pixel widths, for example --width 1440,390." };
|
|
217
|
+
}
|
|
218
|
+
widths = [...new Set(parts.map(Number))];
|
|
219
|
+
} else if (a.startsWith("--")) {
|
|
220
|
+
return { error: `Unknown option ${a}.` };
|
|
221
|
+
} else if (!target) {
|
|
222
|
+
target = a;
|
|
223
|
+
} else {
|
|
224
|
+
return { error: "capture takes one URL or file path." };
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
if (!target) return { error: "capture needs a URL or an HTML file path." };
|
|
228
|
+
return { target, widths };
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function parseListRulesArgs(args) {
|
|
232
|
+
let moment;
|
|
233
|
+
let areas;
|
|
234
|
+
let json = false;
|
|
235
|
+
for (let i = 0; i < args.length; i++) {
|
|
236
|
+
const a = args[i];
|
|
237
|
+
if (a === "--json") {
|
|
238
|
+
json = true;
|
|
239
|
+
} else if (a === "--moment") {
|
|
240
|
+
moment = args[++i];
|
|
241
|
+
if (!moment) return { error: "--moment needs a name, for example --moment create." };
|
|
242
|
+
} else if (a === "--area") {
|
|
243
|
+
const raw = args[++i];
|
|
244
|
+
const parts = (raw ?? "").split(",");
|
|
245
|
+
if (!raw || parts.some((p) => !p)) {
|
|
246
|
+
return { error: "--area needs a comma list of area names, for example --area color,project." };
|
|
247
|
+
}
|
|
248
|
+
areas = parts;
|
|
249
|
+
} else if (a.startsWith("--")) {
|
|
250
|
+
return { error: `Unknown option ${a}.` };
|
|
251
|
+
} else {
|
|
252
|
+
return { error: "list-rules takes no arguments, only options." };
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return { moment, areas, json };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
// Reads `--name value` pairs. Returns { values } or { errors } with one message per problem.
|
|
259
|
+
function parseRecordArgs(args, names, required) {
|
|
260
|
+
const values = {};
|
|
261
|
+
const errors = [];
|
|
262
|
+
for (let i = 0; i < args.length; i++) {
|
|
263
|
+
const a = args[i];
|
|
264
|
+
if (!a.startsWith("--")) {
|
|
265
|
+
errors.push(`Unexpected argument ${a}.`);
|
|
266
|
+
} else if (!names.includes(a.slice(2))) {
|
|
267
|
+
errors.push(`Unknown option ${a}.`);
|
|
268
|
+
} else if (args[i + 1] === undefined || args[i + 1].startsWith("--")) {
|
|
269
|
+
errors.push(`${a} needs a value.`);
|
|
270
|
+
} else {
|
|
271
|
+
values[a.slice(2)] = args[++i];
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
for (const name of required) {
|
|
275
|
+
if (values[name] === undefined && !errors.some((e) => e.startsWith(`--${name} `))) errors.push(`--${name} is required.`);
|
|
276
|
+
}
|
|
277
|
+
return errors.length > 0 ? { errors } : { values };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async function runRecord(rest, names, required, usageName, act) {
|
|
281
|
+
const parsed = parseRecordArgs(rest, names, required);
|
|
282
|
+
if (parsed.errors) {
|
|
283
|
+
for (const e of parsed.errors) console.error(e);
|
|
284
|
+
printUsage(usageName);
|
|
285
|
+
return 2;
|
|
286
|
+
}
|
|
287
|
+
try {
|
|
288
|
+
console.log(await act(parsed.values));
|
|
289
|
+
return 0;
|
|
290
|
+
} catch (err) {
|
|
291
|
+
if (err?.code === "RECORD_INPUT" || err?.code === "RECORD_INVALID") {
|
|
292
|
+
for (const p of err.problems) console.error(p);
|
|
293
|
+
} else {
|
|
294
|
+
const known = err?.code === "RULES_DIR_NOT_FOUND";
|
|
295
|
+
console.error(known ? err.message : `Error: ${err?.message ?? err}`);
|
|
296
|
+
}
|
|
297
|
+
return 2;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
async function main(argv) {
|
|
302
|
+
const [cmd, ...rest] = argv;
|
|
303
|
+
// --help or -h anywhere in the arguments prints that command's usage, before any parsing.
|
|
304
|
+
if (Object.hasOwn(USAGE, cmd) && rest.some((a) => a === "--help" || a === "-h")) {
|
|
305
|
+
console.log(USAGE[cmd].join("\n"));
|
|
306
|
+
return 0;
|
|
307
|
+
}
|
|
308
|
+
if (cmd === "hook") {
|
|
309
|
+
return runHook(rest[0], rest.slice(1));
|
|
310
|
+
}
|
|
311
|
+
if (cmd === "install-hooks") {
|
|
312
|
+
return runInstallHooks(rest);
|
|
313
|
+
}
|
|
314
|
+
if (cmd === "--help" || cmd === "-h") {
|
|
315
|
+
console.log(usage());
|
|
316
|
+
return 0;
|
|
317
|
+
}
|
|
318
|
+
if (cmd === "check-design") {
|
|
319
|
+
const parsed = parseCheckArgs(rest);
|
|
320
|
+
if (parsed.error) {
|
|
321
|
+
console.error(parsed.error);
|
|
322
|
+
printUsage("check-design");
|
|
323
|
+
return 2;
|
|
324
|
+
}
|
|
325
|
+
// Set by the post-edit hook: past this many milliseconds the check exits, and Playwright closes the browser it started on exit.
|
|
326
|
+
const deadline = Number(process.env.LAZULI_DEADLINE_MS);
|
|
327
|
+
if (Number.isFinite(deadline) && deadline > 0) {
|
|
328
|
+
setTimeout(() => {
|
|
329
|
+
process.stderr.write(`check-design stopped: it ran past its deadline of ${Math.round(deadline / 100) / 10} s.\n`);
|
|
330
|
+
process.exit(2);
|
|
331
|
+
}, deadline).unref();
|
|
332
|
+
}
|
|
333
|
+
try {
|
|
334
|
+
const result = parsed.asset
|
|
335
|
+
? await checkDesign({ asset: parsed.asset, ...(parsed.sizes ? { sizes: parsed.sizes } : {}), ...(parsed.areas ? { areas: parsed.areas } : {}), ...(parsed.copyTo ? { copyTo: parsed.copyTo } : {}) })
|
|
336
|
+
: await checkDesign({ target: parsed.target, screens: parsed.screens, site: parsed.site, ...(parsed.widths ? { widths: parsed.widths } : {}), ...(parsed.areas ? { areas: parsed.areas } : {}), ...(parsed.copyTo ? { copyTo: parsed.copyTo } : {}) });
|
|
337
|
+
console.log(parsed.json ? JSON.stringify(result, null, 2) : formatReport(result));
|
|
338
|
+
// A norm that could not be checked (its measurer failed) exits 1 like a fail.
|
|
339
|
+
return result.findings.some((f) => f.level === "fail") || result.uncheckedNorms?.length > 0 ? 1 : 0;
|
|
340
|
+
} catch (err) {
|
|
341
|
+
const known = err?.code === "BROWSER_NOT_FOUND" || err?.code === "FILE_NOT_FOUND" || err?.code === "UNKNOWN_AREA" || err?.code === "RULES_DIR_NOT_FOUND" || err?.code === "SCREENS_INPUT" || err?.code === "ASSET_INPUT";
|
|
342
|
+
console.error(known ? err.message : `Error: ${err?.message ?? err}`);
|
|
343
|
+
return 2;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
if (cmd === "capture") {
|
|
347
|
+
const parsed = parseCaptureArgs(rest);
|
|
348
|
+
if (parsed.error) {
|
|
349
|
+
console.error(parsed.error);
|
|
350
|
+
printUsage("capture");
|
|
351
|
+
return 2;
|
|
352
|
+
}
|
|
353
|
+
try {
|
|
354
|
+
const m = await capture({ target: parsed.target, ...(parsed.widths ? { widths: parsed.widths } : {}) });
|
|
355
|
+
for (const n of m.notes) console.error(n);
|
|
356
|
+
console.log(
|
|
357
|
+
[
|
|
358
|
+
`Capture folder: ${m.dir}`,
|
|
359
|
+
"Next, in this order:",
|
|
360
|
+
` 1. First look: give ${m.blind.prompt} to a reader who has not seen the project.`,
|
|
361
|
+
" 2. lazuli record-first-look --file <answers.json>",
|
|
362
|
+
` 3. Review: give ${path.join(m.dir, "review.md")} to a separate reviewer; it reads the stored first look.`,
|
|
363
|
+
" 4. lazuli record-review --file <verdict.json>",
|
|
364
|
+
'No reader or reviewer available: record the review as pending (verdict "pending" with a reason). The gate stays closed.',
|
|
365
|
+
"The first look folder is outside the project on purpose and lives until record-first-look removes it. If the system cleaned it first, run capture again.",
|
|
366
|
+
].join("\n"),
|
|
367
|
+
);
|
|
368
|
+
return 0;
|
|
369
|
+
} catch (err) {
|
|
370
|
+
const known = err?.code === "BROWSER_NOT_FOUND" || err?.code === "FILE_NOT_FOUND";
|
|
371
|
+
console.error(known ? err.message : `Error: ${err?.message ?? err}`);
|
|
372
|
+
return 2;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
if (cmd === "check-goals") {
|
|
376
|
+
const bad = rest.find((a) => a.startsWith("--"));
|
|
377
|
+
if (bad || rest.length > 1) {
|
|
378
|
+
console.error(bad ? `Unknown option ${bad}.` : "check-goals takes at most one URL or file path.");
|
|
379
|
+
printUsage("check-goals");
|
|
380
|
+
return 2;
|
|
381
|
+
}
|
|
382
|
+
try {
|
|
383
|
+
const gate = await checkGoals({ cwd: process.cwd(), ...(rest[0] ? { target: rest[0] } : {}) });
|
|
384
|
+
console.log(formatGate(gate));
|
|
385
|
+
return gate.passed ? 0 : 1;
|
|
386
|
+
} catch (err) {
|
|
387
|
+
if (err?.code === "RECORD_INVALID") {
|
|
388
|
+
for (const p of err.problems) console.error(p);
|
|
389
|
+
} else {
|
|
390
|
+
console.error(err?.code === "NO_LAZULI_MD" ? err.message : `Error: ${err?.message ?? err}`);
|
|
391
|
+
}
|
|
392
|
+
return 2;
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
if (cmd === "draft-memo") {
|
|
396
|
+
let target;
|
|
397
|
+
let out;
|
|
398
|
+
const errors = [];
|
|
399
|
+
for (let i = 0; i < rest.length; i++) {
|
|
400
|
+
const a = rest[i];
|
|
401
|
+
if (a === "--out") {
|
|
402
|
+
out = rest[++i];
|
|
403
|
+
if (!out || out.startsWith("--")) {
|
|
404
|
+
errors.push("--out needs a file path.");
|
|
405
|
+
out = undefined;
|
|
406
|
+
}
|
|
407
|
+
} else if (a.startsWith("--")) {
|
|
408
|
+
errors.push(`Unknown option ${a}.`);
|
|
409
|
+
} else if (target === undefined) {
|
|
410
|
+
target = a;
|
|
411
|
+
} else {
|
|
412
|
+
errors.push("draft-memo takes at most one URL or file path.");
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
if (errors.length > 0) {
|
|
416
|
+
for (const e of errors) console.error(e);
|
|
417
|
+
printUsage("draft-memo");
|
|
418
|
+
return 2;
|
|
419
|
+
}
|
|
420
|
+
try {
|
|
421
|
+
const memo = await draftMemo({ cwd: process.cwd(), ...(target ? { target } : {}) });
|
|
422
|
+
const file = path.resolve(process.cwd(), out ?? path.join(".lazuli", "decisions-draft.md"));
|
|
423
|
+
await mkdir(path.dirname(file), { recursive: true });
|
|
424
|
+
await writeFile(file, memo.text);
|
|
425
|
+
console.log(`Wrote ${file}`);
|
|
426
|
+
if (memo.gaps.length > 0) {
|
|
427
|
+
console.log(["Gaps:", ...memo.gaps.map((g) => ` - ${g}`)].join("\n"));
|
|
428
|
+
}
|
|
429
|
+
return memo.gaps.length > 0 ? 1 : 0;
|
|
430
|
+
} catch (err) {
|
|
431
|
+
if (err?.code === "RECORD_INVALID") {
|
|
432
|
+
for (const p of err.problems) console.error(p);
|
|
433
|
+
} else {
|
|
434
|
+
const known = err?.code === "NO_LAZULI_MD" || err?.code === "RULES_DIR_NOT_FOUND";
|
|
435
|
+
console.error(known ? err.message : `Error: ${err?.message ?? err}`);
|
|
436
|
+
}
|
|
437
|
+
return 2;
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
if (cmd === "list-rules") {
|
|
441
|
+
const parsed = parseListRulesArgs(rest);
|
|
442
|
+
if (parsed.error) {
|
|
443
|
+
console.error(parsed.error);
|
|
444
|
+
printUsage("list-rules");
|
|
445
|
+
return 2;
|
|
446
|
+
}
|
|
447
|
+
try {
|
|
448
|
+
const out = await listRules({ cwd: process.cwd(), ...(parsed.moment ? { moment: parsed.moment } : {}), ...(parsed.areas ? { areas: parsed.areas } : {}) });
|
|
449
|
+
console.log(parsed.json ? JSON.stringify({ rules: out.rules, projectProblems: out.projectProblems }, null, 2) : formatRules(out));
|
|
450
|
+
return out.projectProblems.length > 0 ? 1 : 0;
|
|
451
|
+
} catch (err) {
|
|
452
|
+
const known = err?.code === "LIST_RULES_INPUT" || err?.code === "RULES_DIR_NOT_FOUND";
|
|
453
|
+
console.error(known ? err.message : `Error: ${err?.message ?? err}`);
|
|
454
|
+
return 2;
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (cmd === "render-options") {
|
|
458
|
+
let folder;
|
|
459
|
+
let widths;
|
|
460
|
+
let json = false;
|
|
461
|
+
let error;
|
|
462
|
+
for (let i = 0; i < rest.length && !error; i++) {
|
|
463
|
+
const a = rest[i];
|
|
464
|
+
if (a === "--json") {
|
|
465
|
+
json = true;
|
|
466
|
+
} else if (a === "--width") {
|
|
467
|
+
const raw = rest[++i];
|
|
468
|
+
const parts = (raw ?? "").split(",");
|
|
469
|
+
if (!raw || parts.some((p) => !/^\d+$/.test(p) || Number(p) < 200 || Number(p) > 4000)) {
|
|
470
|
+
error = "--width needs a comma list of pixel widths, for example --width 1440.";
|
|
471
|
+
} else {
|
|
472
|
+
widths = [...new Set(parts.map(Number))];
|
|
473
|
+
}
|
|
474
|
+
} else if (a.startsWith("--")) {
|
|
475
|
+
error = `Unknown option ${a}.`;
|
|
476
|
+
} else if (folder === undefined) {
|
|
477
|
+
folder = a;
|
|
478
|
+
} else {
|
|
479
|
+
error = "render-options takes one folder.";
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
if (!error && folder === undefined) error = "render-options needs the folder that holds the option HTML files.";
|
|
483
|
+
if (error) {
|
|
484
|
+
console.error(error);
|
|
485
|
+
printUsage("render-options");
|
|
486
|
+
return 2;
|
|
487
|
+
}
|
|
488
|
+
try {
|
|
489
|
+
const r = await renderOptions({ folder, ...(widths ? { widths } : {}) });
|
|
490
|
+
if (json) {
|
|
491
|
+
console.log(JSON.stringify(r, null, 2));
|
|
492
|
+
} else {
|
|
493
|
+
const lines = r.widths.map((w) => `Sheet at ${w} px: ${r.sheets[String(w)]}`);
|
|
494
|
+
for (const o of r.options) {
|
|
495
|
+
lines.push(`${o.file} ${r.widths.map((w) => `${w}: ${optionLabel(o.measures[String(w)], o.findings.filter((f) => f.width === w), o.notes?.[String(w)]).join("; ")}`).join(" | ")}`);
|
|
496
|
+
}
|
|
497
|
+
if (r.kept?.length) lines.push(...r.kept.map((w) => `Kept the earlier measures at ${w} px.`));
|
|
498
|
+
if (r.dropped?.length) lines.push(...r.dropped.map((w) => `Option files changed since the last run; the earlier measures at ${w} px were dropped.`));
|
|
499
|
+
lines.push(`Measures: ${r.jsonPath}`);
|
|
500
|
+
console.log(lines.join("\n"));
|
|
501
|
+
}
|
|
502
|
+
return 0;
|
|
503
|
+
} catch (err) {
|
|
504
|
+
const known = err?.code === "OPTIONS_INPUT" || err?.code === "BROWSER_NOT_FOUND" || err?.code === "RULES_DIR_NOT_FOUND";
|
|
505
|
+
console.error(known ? err.message : `Error: ${err?.message ?? err}`);
|
|
506
|
+
return 2;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
if (cmd === "compare-designs") {
|
|
510
|
+
let target;
|
|
511
|
+
let baseline;
|
|
512
|
+
let widths;
|
|
513
|
+
let json = false;
|
|
514
|
+
let error;
|
|
515
|
+
for (let i = 0; i < rest.length && !error; i++) {
|
|
516
|
+
const a = rest[i];
|
|
517
|
+
if (a === "--json") {
|
|
518
|
+
json = true;
|
|
519
|
+
} else if (a === "--baseline") {
|
|
520
|
+
baseline = rest[++i];
|
|
521
|
+
if (!baseline || baseline.startsWith("--")) error = "--baseline needs a URL or an HTML file path made without the kit for the same brief.";
|
|
522
|
+
} else if (a === "--width") {
|
|
523
|
+
const raw = rest[++i];
|
|
524
|
+
const parts = (raw ?? "").split(",");
|
|
525
|
+
if (!raw || parts.some((p) => !/^\d+$/.test(p) || Number(p) < 200 || Number(p) > 4000)) {
|
|
526
|
+
error = "--width needs a comma list of pixel widths, for example --width 1440,390.";
|
|
527
|
+
} else {
|
|
528
|
+
widths = [...new Set(parts.map(Number))];
|
|
529
|
+
}
|
|
530
|
+
} else if (a.startsWith("--")) {
|
|
531
|
+
error = `Unknown option ${a}.`;
|
|
532
|
+
} else if (target === undefined) {
|
|
533
|
+
target = a;
|
|
534
|
+
} else {
|
|
535
|
+
error = "compare-designs takes one target; give the baseline with --baseline.";
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
if (!error && target === undefined) error = "compare-designs needs a URL or an HTML file path.";
|
|
539
|
+
if (!error && baseline === undefined) error = "compare-designs needs --baseline <url-or-path>, a page made without the kit for the same brief.";
|
|
540
|
+
if (error) {
|
|
541
|
+
console.error(error);
|
|
542
|
+
printUsage("compare-designs");
|
|
543
|
+
return 2;
|
|
544
|
+
}
|
|
545
|
+
try {
|
|
546
|
+
const r = await compareDesigns({ target, baseline, ...(widths ? { widths } : {}) });
|
|
547
|
+
console.log(json ? JSON.stringify(r, null, 2) : formatCompare(r));
|
|
548
|
+
return 0;
|
|
549
|
+
} catch (err) {
|
|
550
|
+
const known = err?.code === "COMPARE_INPUT" || err?.code === "FILE_NOT_FOUND" || err?.code === "BROWSER_NOT_FOUND";
|
|
551
|
+
console.error(known ? err.message : `Error: ${err?.message ?? err}`);
|
|
552
|
+
return 2;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
if (cmd === "map-page") {
|
|
556
|
+
let target;
|
|
557
|
+
let piece;
|
|
558
|
+
let task;
|
|
559
|
+
let width;
|
|
560
|
+
let error;
|
|
561
|
+
for (let i = 0; i < rest.length && !error; i++) {
|
|
562
|
+
const a = rest[i];
|
|
563
|
+
if (a === "--piece" || a === "--task") {
|
|
564
|
+
const value = rest[++i];
|
|
565
|
+
if (!value || value.startsWith("--")) error = a === "--piece" ? "--piece needs the name of a goal's piece." : "--task needs a task id.";
|
|
566
|
+
else if (a === "--piece") piece = value;
|
|
567
|
+
else task = value;
|
|
568
|
+
} else if (a === "--width") {
|
|
569
|
+
const raw = rest[++i];
|
|
570
|
+
if (!raw || !/^\d+$/.test(raw) || Number(raw) < 200 || Number(raw) > 4000) error = "--width needs one pixel width, for example --width 390.";
|
|
571
|
+
else width = Number(raw);
|
|
572
|
+
} else if (a.startsWith("--")) {
|
|
573
|
+
error = `Unknown option ${a}.`;
|
|
574
|
+
} else if (target === undefined) {
|
|
575
|
+
target = a;
|
|
576
|
+
} else {
|
|
577
|
+
error = "map-page takes one URL or file path.";
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
if (!error && piece === undefined && task === undefined) error = "map-page needs --piece <name> to start a task or --task <id> to continue one.";
|
|
581
|
+
if (error) {
|
|
582
|
+
console.error(error);
|
|
583
|
+
printUsage("map-page");
|
|
584
|
+
return 2;
|
|
585
|
+
}
|
|
586
|
+
try {
|
|
587
|
+
const { manifest, step, summary } = await mapPage({ cwd: process.cwd(), ...(target !== undefined ? { target } : {}), ...(piece !== undefined ? { piece } : {}), ...(task !== undefined ? { task } : {}), ...(width !== undefined ? { width } : {}) });
|
|
588
|
+
for (const n of step.notes) console.error(n);
|
|
589
|
+
// A step that ends the task (a navigation stopped, a page that could not be opened) prints the summary.
|
|
590
|
+
if (summary) {
|
|
591
|
+
console.log(summary);
|
|
592
|
+
return 0;
|
|
593
|
+
}
|
|
594
|
+
console.log([`Task ${manifest.taskId}, step ${step.step}: ${step.offered.total} actions, ${step.offered.firstView} in the first view.`, `Tester prompt: ${path.join(manifest.dir, "tester.md")}`].join("\n"));
|
|
595
|
+
return 0;
|
|
596
|
+
} catch (err) {
|
|
597
|
+
if (err?.code === "TASK_INPUT") {
|
|
598
|
+
for (const p of err.problems) console.error(p);
|
|
599
|
+
} else {
|
|
600
|
+
const known = err?.code === "FILE_NOT_FOUND" || err?.code === "BROWSER_NOT_FOUND";
|
|
601
|
+
console.error(known ? err.message : `Error: ${err?.message ?? err}`);
|
|
602
|
+
}
|
|
603
|
+
return 2;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
if (cmd === "record-task") {
|
|
607
|
+
return runRecord(rest, ["file"], ["file"], "record-task", async (v) => {
|
|
608
|
+
const r = await recordTaskStep({ cwd: process.cwd(), file: v.file });
|
|
609
|
+
return r.summary ?? r.next;
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
if (cmd === "record-break") {
|
|
613
|
+
return runRecord(rest, ["rule", "piece", "effect", "check", "status"], ["rule", "piece", "status"],
|
|
614
|
+
"record-break",
|
|
615
|
+
async (v) => {
|
|
616
|
+
const r = await recordBreak({ cwd: process.cwd(), ...v });
|
|
617
|
+
for (const n of r.notes) console.error(n);
|
|
618
|
+
return r.rules.map((id) => `Recorded break ${id} on ${r.piece} (${r.status}) in ${r.path}`).join("\n");
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
if (cmd === "record-decision") {
|
|
622
|
+
return runRecord(rest, ["decision", "piece", "goal", "rule", "measure"], ["decision", "piece", "goal", "rule", "measure"],
|
|
623
|
+
"record-decision",
|
|
624
|
+
async (v) => {
|
|
625
|
+
const r = await recordDecision({ cwd: process.cwd(), ...v });
|
|
626
|
+
for (const n of r.notes) console.error(n);
|
|
627
|
+
return `Recorded decision "${r.decision}" on ${r.piece} in ${r.path}`;
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
if (cmd === "record-first-look") {
|
|
631
|
+
return runRecord(rest, ["file"], ["file"], "record-first-look", (v) => recordFirstLook({ cwd: process.cwd(), file: v.file }));
|
|
632
|
+
}
|
|
633
|
+
if (cmd === "record-review") {
|
|
634
|
+
return runRecord(rest, ["file"], ["file"], "record-review", (v) => recordReview({ cwd: process.cwd(), file: v.file }));
|
|
635
|
+
}
|
|
636
|
+
const known = COMMANDS.find((c) => c.name === cmd);
|
|
637
|
+
if (known?.runs === "agent") {
|
|
638
|
+
console.log(`This runs inside your AI agent: /lazuli ${cmd}`);
|
|
639
|
+
return 0;
|
|
640
|
+
}
|
|
641
|
+
if (cmd === "start-project") {
|
|
642
|
+
let mode;
|
|
643
|
+
for (let i = 0; i < rest.length; i++) {
|
|
644
|
+
if (rest[i] === "--mode" && (rest[i + 1] === "director" || rest[i + 1] === "delegate")) {
|
|
645
|
+
mode = rest[++i];
|
|
646
|
+
} else if (rest[i] === "--mode") {
|
|
647
|
+
console.error("--mode needs director or delegate.");
|
|
648
|
+
return 2;
|
|
649
|
+
} else {
|
|
650
|
+
console.error(`Unknown argument ${rest[i]}.`);
|
|
651
|
+
printUsage("start-project");
|
|
652
|
+
return 2;
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
try {
|
|
656
|
+
const { created, path } = await startProject({ cwd: process.cwd(), ...(mode ? { mode } : {}) });
|
|
657
|
+
console.log(created ? `Created ${path}` : `LAZULI.md already exists at ${path}, left untouched.${mode ? " Its mode was not changed." : ""}`);
|
|
658
|
+
return 0;
|
|
659
|
+
} catch (err) {
|
|
660
|
+
console.error(`Error: ${err?.message ?? err}`);
|
|
661
|
+
return 2;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
if (cmd === "install") {
|
|
665
|
+
let target;
|
|
666
|
+
let agentsTarget;
|
|
667
|
+
for (let i = 0; i < rest.length; i++) {
|
|
668
|
+
if ((rest[i] === "--target" || rest[i] === "--agents-target") && rest[i + 1] && !rest[i + 1].startsWith("--")) {
|
|
669
|
+
if (rest[i] === "--target") target = rest[i + 1];
|
|
670
|
+
else agentsTarget = rest[i + 1];
|
|
671
|
+
i += 1;
|
|
672
|
+
} else if (rest[i] === "--target" || rest[i] === "--agents-target") {
|
|
673
|
+
console.error(`${rest[i]} needs a folder.`);
|
|
674
|
+
return 2;
|
|
675
|
+
} else {
|
|
676
|
+
printUsage("install");
|
|
677
|
+
return 2;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
try {
|
|
681
|
+
const options = { ...(target ? { target } : {}), ...(agentsTarget ? { agentsTarget } : {}) };
|
|
682
|
+
const done = await install(options);
|
|
683
|
+
const lines = ["Installed (existing lazuli* copies in the target were replaced):", ...done.map((d) => ` ${d}`)];
|
|
684
|
+
const where = resolveAgentsTarget({ target: target ?? defaultTarget(), agentsTarget });
|
|
685
|
+
if (!where.beside && done.some((d) => d.endsWith(".md") && path.resolve(d).startsWith(path.resolve(where.dir)))) {
|
|
686
|
+
lines.push(`The agents (lazuli-first-look, lazuli-design-reviewer, lazuli-task-tester) are in ${where.dir}. To use them in Claude Code, move them to your agents folder (for example ~/.claude/agents), or run install again with --agents-target <dir>.`);
|
|
687
|
+
}
|
|
688
|
+
console.log(lines.join("\n"));
|
|
689
|
+
return 0;
|
|
690
|
+
} catch (err) {
|
|
691
|
+
console.error(`Error: ${err?.message ?? err}`);
|
|
692
|
+
return 2;
|
|
693
|
+
}
|
|
694
|
+
}
|
|
695
|
+
console.log(usage());
|
|
696
|
+
return 2;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
process.exitCode = await main(process.argv.slice(2));
|