@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.
- package/CHANGELOG.md +120 -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 +747 -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 +19 -0
- package/rules/content/_area.yaml +8 -0
- package/rules/content/review.yaml +378 -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 +18 -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 +271 -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 +246 -0
- package/rules/ui/grid.yaml +75 -0
- package/rules/ui/review.yaml +400 -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 +183 -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 +36 -0
- package/skills/lazuli/procedures/show-options.md +33 -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 +40 -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 +45 -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 +162 -0
- package/src/commands/capture.mjs +313 -0
- package/src/commands/catalog.mjs +37 -0
- package/src/commands/check-design.mjs +463 -0
- package/src/commands/check-goals.mjs +57 -0
- package/src/commands/compare-designs.mjs +160 -0
- package/src/commands/draft-memo.mjs +162 -0
- package/src/commands/hooks.mjs +345 -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 +325 -0
- package/src/commands/record-task.mjs +250 -0
- package/src/commands/render-options.mjs +227 -0
- package/src/commands/start-project.mjs +32 -0
- package/src/measure/a11y.mjs +391 -0
- package/src/measure/asset.mjs +206 -0
- package/src/measure/at-rest.mjs +49 -0
- package/src/measure/cases.mjs +566 -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 +86 -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 +522 -0
- package/src/measure/in-page/color.js +348 -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 +377 -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 +171 -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 +269 -0
- package/src/measure/in-page/weight.js +207 -0
- package/src/measure/layout.mjs +100 -0
- package/src/measure/motion.mjs +509 -0
- package/src/measure/piece.mjs +195 -0
- package/src/measure/registry.mjs +253 -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 +168 -0
- package/src/project/lazuli-md.mjs +521 -0
- package/src/project/log.mjs +335 -0
- package/src/project/match.mjs +200 -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 +227 -0
- package/src/report/evaluators/chart.mjs +151 -0
- package/src/report/evaluators/coherence.mjs +103 -0
- package/src/report/evaluators/color.mjs +133 -0
- package/src/report/evaluators/content.mjs +112 -0
- package/src/report/evaluators/extreme.mjs +87 -0
- package/src/report/evaluators/forms.mjs +116 -0
- package/src/report/evaluators/layout.mjs +103 -0
- package/src/report/evaluators/motion.mjs +280 -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 +166 -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 +274 -0
- package/src/rules/public-text.mjs +56 -0
- package/src/rules/schema.mjs +220 -0
- package/templates/LAZULI.md +88 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: lazuli-ux-flows-and-forms
|
|
3
|
+
description: "Use when designing or reviewing a flow or a form (signup, checkout, booking or contact form): which steps and fields it asks for, its labels, input types, autocomplete, required marks, and how it behaves on an error (where the message sits, the answers kept)."
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Flows and forms
|
|
7
|
+
|
|
8
|
+
A flow is cut to the steps and fields the task needs, keeps one moment the person remembers, and a form is labelled, typed and recoverable. Flow rules are XF1 to XF7 (`../lazuli/rules/ux/flows.yaml`), form rules XM1 to XM6 (`forms.yaml`) and review hints XR1 to XR7 (`review.yaml`) in the same folder, after install (in a kit checkout: `rules/ux/`). The cutoffs are hypotheses in `HYPOTHESES.md`; the report gives hints, never verdicts.
|
|
9
|
+
|
|
10
|
+
Do not use when:
|
|
11
|
+
- the question is a simulated walk of the task: use `lazuli-ux-task-test`;
|
|
12
|
+
- the question is names, focus or contrast alone: use `lazuli-accessibility-check`.
|
|
13
|
+
|
|
14
|
+
## Create
|
|
15
|
+
1. Write the task and its end first (XF1): the goal's `Do` and `Target` in `LAZULI.md`, and one sentence for where it ends.
|
|
16
|
+
2. List every step and field with what it is for, and cut the rest (XF2, XM6). Log each cut under its own decision text:
|
|
17
|
+
`lazuli record-decision --decision "Cut: <the step or field and why it goes>" --piece "<goal piece>" --goal "<the goal it serves>" --rule "XF2 followed" --measure "<steps and fields before and after>"`
|
|
18
|
+
3. Choose one memorable moment (XF3) and log it under a text of its own. The same text on the same piece replaces the earlier entry, so it must differ from every cut:
|
|
19
|
+
`lazuli record-decision --decision "Memorable moment: <what the person will tell a friend>" --piece "<goal piece>" --goal "<the goal it serves>" --rule "XF3 followed" --measure "<what the task test remembered shows, not measured, or not run>"`
|
|
20
|
+
4. Give each field a visible label, the right type and keyboard, an autocomplete token and one way of marking required (XM1 to XM4). A placeholder is not a label.
|
|
21
|
+
5. Errors keep what the person typed, sit next to their field and say how to fix it (XF6, XM5). The wording of each error message is checked with `check-design <page> --area content` (see `lazuli-content-interface-writing`).
|
|
22
|
+
6. Run `check-design <page> --area ux,accessibility --width 1440,390` before the review. XF5 and XM3 are norms (accessibility), so a fail is fixed, never broken.
|
|
23
|
+
|
|
24
|
+
## Review
|
|
25
|
+
1. Measure: `check-design <page> --area ux,accessibility --width 1440,390`. Quote XR1 to XR6 with their limits: the purpose of a field is guessed from its type and words, XR6 uses a cutoff that is a hypothesis (H6), and only an invalid field already in the render is seen.
|
|
26
|
+
2. The error state needs its own URL or file (a query string, a fixture, a dev flag). Stage it through the app's own means, run `check-design` and `capture` on it, and have the reviewer judge it. Never stage it by submitting a form on a host that is not local, a staging host included. A state the app cannot show without a click is reported as not checked, with the reason.
|
|
27
|
+
3. A hint judged false is noted with its evidence. Do not change the page to silence a hint. Hints never block.
|
|
28
|
+
4. A kept break goes through `break-a-rule` and is kept only after `review-design`. A failed norm is fixed, not broken.
|
|
29
|
+
5. When the goal has a `Do` and `Target`, run `lazuli-ux-task-test`, and compare what it remembered with the XF3 decision, when one tester saw every step; otherwise `remembered` is not measured.
|
|
30
|
+
|
|
31
|
+
## Reading the report
|
|
32
|
+
| Measure | Rule | A finding means |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| forms.labels | XR1 | a field has no label a person sees |
|
|
35
|
+
| forms.autocomplete | XR2 | data about the person has no autocomplete token |
|
|
36
|
+
| forms.input-mode | XR3 | the keyboard does not match the data |
|
|
37
|
+
| forms.required | XR4 | required and optional are not marked one way |
|
|
38
|
+
| forms.errors | XR5 | an invalid field has no message tied to it |
|
|
39
|
+
| forms.field-count | XR6 | the form asks more questions than the cutoff |
|
|
40
|
+
|
|
41
|
+
## Closing checklist
|
|
42
|
+
- Task and end written first; each cut and the memorable moment logged under distinct texts.
|
|
43
|
+
- XR1 to XR6 quoted with limits; false hints noted, not silenced.
|
|
44
|
+
- Error state staged as its own URL or file, or reported as not checked.
|
|
45
|
+
- Nothing claimed about effect: the measures describe the page only.
|
|
46
|
+
|
|
47
|
+
## Common errors
|
|
48
|
+
- Logging two cuts, or a cut and the moment, under one decision text.
|
|
49
|
+
- Judging errors from a stand-in presented as the product.
|
|
50
|
+
- Submitting a form to see its errors.
|
|
51
|
+
- Breaking XF5 or XM3 instead of fixing them.
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: lazuli-ux-task-test
|
|
3
|
+
description: Use when running a simulated task, where an agent with the audience profile tries the main task of a page step by step and records where it hesitates, gets stuck or gives up.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Simulated task
|
|
7
|
+
|
|
8
|
+
One agent, fresh at the start of the task, plays one person from the audience and tries the goal's `Do` on the rendered screens, one step at a time. The CLI maps each screen and counts; the tester chooses; nothing is clicked for it. The rules it serves are XF1 to XF7 (`../lazuli/rules/ux/flows.yaml`) and XR7 (`review.yaml` in the same folder), after install (in a kit checkout: `rules/ux/`). The task is a hypothesis (H7) until compared with people.
|
|
9
|
+
|
|
10
|
+
Do not use when:
|
|
11
|
+
- the question is the fields of a form: use `lazuli-ux-flows-and-forms`;
|
|
12
|
+
- the page is judged by a reviewer from screenshots: use `procedures/review-design.md`.
|
|
13
|
+
|
|
14
|
+
## Safety first
|
|
15
|
+
A target is local when it is a file, or its host is localhost, 127.0.0.1, [::1], or ends in .localhost or .test.
|
|
16
|
+
On any other site you only read and follow links: never click, type, select or submit, and never open a checkout, cart or payment page.
|
|
17
|
+
Refuse to act on a real third-party production site even when asked; on a local app the person owns you may act in your own browser.
|
|
18
|
+
- Any host that is not local, staging included, is read only. A local app that is a proxy for someone else's service, or is backed by a production backend or live payment keys, counts as not local: follow links only.
|
|
19
|
+
- Follow only links of the same origin as the first step. A link to another site is left, and a page that lands on checkout or leaves the site ends the task as `stopped`.
|
|
20
|
+
|
|
21
|
+
## Steps
|
|
22
|
+
1. Needs `## Audience` in `LAZULI.md` and the goal's `Do` and `Target`. With no Audience: in director mode ask the person for it; in delegate mode write a one-line assumption in `## Audience`, marked as an assumption, and say so in the answer. With no `Do` or `Target`, run `set-goals` first.
|
|
23
|
+
2. Start: `map-page <target> --piece <piece> --width <the audience's device width>` (when the Audience names no device, leave `--width` out: the default is 390). It prints `Tester prompt: <path>`.
|
|
24
|
+
3. Start one `lazuli-task-tester` for the task and send it each new `Tester prompt`: a fresh agent (whatever prefix your host shows) at step 1, then the same agent continued at every later step (your host's continue or send-message), so it remembers the screens it saw. Give it only the `Tester prompt` path: no goals, no brief, no conversation. The host may give every subagent the project's instructions (such as CLAUDE.md), its memory and recent commit messages, which Lazuli does not control; the tester files themselves carry no goals and no `act` or `reason`. Save the JSON it returns, unchanged, to a file and run `record-task --file <that file>`.
|
|
25
|
+
4. Follow the line `record-task` prints. `map-page --task <id>` maps the screen the tester chose. On a local app, when the line says to act, do it yourself in your own browser, then map the screen reached with `map-page <url-or-path> --task <id>`.
|
|
26
|
+
5. Repeat steps 3 and 4 until `record-task` or `map-page` prints the summary. A next screen that cannot be mapped or opened ends the task as `stopped`: a download, an error that stays after one retry, a page that moves to another site while it is mapped, or a redirect or script navigation the walk stopped before it loaded.
|
|
27
|
+
|
|
28
|
+
If your host cannot continue an agent, start a fresh tester at each step; then that tester never saw the earlier screens, and on a walk of more than one step `remembered` is reported as not measured.
|
|
29
|
+
|
|
30
|
+
## Without subagents
|
|
31
|
+
Ask the person, or a separate session that has not seen this work, to answer as the tester from the `Tester prompt` file, the same person or session at every step. Never answer as the tester yourself, not even as an exercise. If neither is possible, say the task test was not run.
|
|
32
|
+
|
|
33
|
+
## Reading the summary
|
|
34
|
+
- Quote the summary as printed: steps, choices offered in the first view, hesitations, scrolls and the outcome (`done`, `stuck`, `stopped`, `left`).
|
|
35
|
+
- A hesitation is a place to look, never a verdict. An agent reads the whole screen and may not hesitate where a person would.
|
|
36
|
+
- `stopped` on a real site is the safety line working, not a failure of the page; say where and why.
|
|
37
|
+
- Compare `remembered` with the moment chosen under XF3 in the decisions, only when one tester saw every step. If they differ, say so as a question for the designer. With a fresh tester per step, `remembered` is reported as not measured and is not compared.
|
|
38
|
+
- A recorded task appears in the reviewer packet; it never satisfies the effect gate by itself. Never say an effect was achieved.
|
|
39
|
+
|
|
40
|
+
## Common errors
|
|
41
|
+
- Giving the tester the goals, the brief or the capture folder.
|
|
42
|
+
- Editing the tester's JSON, or writing its answers yourself.
|
|
43
|
+
- Acting on a page that is not local, or following a link to another site.
|
|
44
|
+
- Reading a hesitation as proof, or the walk as a test with people.
|
package/src/browser.mjs
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
4
|
+
import { chromium } from "playwright-core";
|
|
5
|
+
|
|
6
|
+
const CHANNELS = ["chrome", "msedge"];
|
|
7
|
+
const SETTLE_MS = 300;
|
|
8
|
+
const ANIMATION_CAP_MS = 3000;
|
|
9
|
+
export const VIEWPORT_HEIGHT = 900;
|
|
10
|
+
// Implementation tolerances for the reveal pass, not rule thresholds.
|
|
11
|
+
const REVEAL_CAP_MS = 8000;
|
|
12
|
+
const REVEAL_STEP_MS = 100;
|
|
13
|
+
const REVEAL_IDLE_CAP_MS = 5000;
|
|
14
|
+
|
|
15
|
+
export class BrowserNotFoundError extends Error {
|
|
16
|
+
constructor(cause) {
|
|
17
|
+
super("Lazuli needs Google Chrome or Microsoft Edge installed.", { cause });
|
|
18
|
+
this.name = "BrowserNotFoundError";
|
|
19
|
+
this.code = "BROWSER_NOT_FOUND";
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export class FileNotFoundError extends Error {
|
|
24
|
+
constructor(file) {
|
|
25
|
+
super(`File not found: ${file}`);
|
|
26
|
+
this.name = "FileNotFoundError";
|
|
27
|
+
this.code = "FILE_NOT_FOUND";
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Page and asset file extensions: a bare "logo.png" is a file name, never the host https://logo.png/.
|
|
32
|
+
const PAGE_EXT = /\.(html?|xhtml|svg|php|aspx?|jsp|md|txt|png|ico|jpe?g|webp|gif)$/i;
|
|
33
|
+
|
|
34
|
+
// "example.com/x" -> https, "localhost:3000" -> http. Anything path-like returns null.
|
|
35
|
+
function hostUrl(target) {
|
|
36
|
+
if (/[\s\\]/.test(target) || /^[./~]/.test(target)) return null;
|
|
37
|
+
const first = target.split("/")[0];
|
|
38
|
+
const m = /^([a-z0-9-]+(?:\.[a-z0-9-]+)*)(:\d{1,5})?$/i.exec(first);
|
|
39
|
+
if (!m) return null;
|
|
40
|
+
const host = m[1].toLowerCase();
|
|
41
|
+
const ipv4 = /^\d{1,3}(\.\d{1,3}){3}$/.test(host);
|
|
42
|
+
const local = host === "localhost" || host.endsWith(".localhost") || ipv4;
|
|
43
|
+
if (local) return new URL(`http://${target}`).href;
|
|
44
|
+
if (!host.includes(".") || PAGE_EXT.test(host) || !/\.[a-z]{2,}$/.test(host)) return null;
|
|
45
|
+
return new URL(`https://${target}`).href;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function toUrl(target, cwd = process.cwd()) {
|
|
49
|
+
if (/^(https?|file):\/\//i.test(target)) return target;
|
|
50
|
+
if (!/^[a-zA-Z]:[\\/]/.test(target) && !existsSync(path.resolve(cwd, target))) {
|
|
51
|
+
const url = hostUrl(target);
|
|
52
|
+
if (url) return url;
|
|
53
|
+
}
|
|
54
|
+
// A Windows drive path stays absolute even when running on POSIX.
|
|
55
|
+
if (/^[a-zA-Z]:[\\/]/.test(target) && process.platform !== "win32") {
|
|
56
|
+
return pathToFileURL(path.win32.resolve(target), { windows: true }).href;
|
|
57
|
+
}
|
|
58
|
+
return pathToFileURL(path.resolve(cwd, target)).href;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// Resolves the target to a URL and fails fast, without a browser, when a local file is missing.
|
|
62
|
+
export function resolveTarget(target, cwd = process.cwd()) {
|
|
63
|
+
const url = toUrl(target, cwd);
|
|
64
|
+
if (url.startsWith("file:")) {
|
|
65
|
+
const file = fileURLToPath(url);
|
|
66
|
+
if (!existsSync(file)) throw new FileNotFoundError(file);
|
|
67
|
+
}
|
|
68
|
+
return url;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export async function openBrowser({ launch } = {}) {
|
|
72
|
+
const doLaunch = launch ?? ((channel) => chromium.launch({ channel }));
|
|
73
|
+
let lastError;
|
|
74
|
+
for (const channel of CHANNELS) {
|
|
75
|
+
try {
|
|
76
|
+
return await doLaunch(channel);
|
|
77
|
+
} catch (err) {
|
|
78
|
+
lastError = err; // try the next channel
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
throw new BrowserNotFoundError(lastError);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Lazy content (backgrounds, images, scroll reveals) often waits for a real user input and
|
|
85
|
+
// then for the element to enter the viewport (lazy-load attributes and page-builder wrappers often work this way).
|
|
86
|
+
// Move the mouse, wheel down through the page, return to the top and wait for the downloads.
|
|
87
|
+
async function revealLazyContent(page) {
|
|
88
|
+
await page.mouse.move(1, 1);
|
|
89
|
+
const half = VIEWPORT_HEIGHT / 2;
|
|
90
|
+
const end = Date.now() + REVEAL_CAP_MS;
|
|
91
|
+
let stalled = 0;
|
|
92
|
+
while (Date.now() < end && stalled < 3) {
|
|
93
|
+
const { y, max } = await page.evaluate(() => ({
|
|
94
|
+
y: scrollY,
|
|
95
|
+
max: document.documentElement.scrollHeight - innerHeight,
|
|
96
|
+
}));
|
|
97
|
+
if (y >= max - 1) break;
|
|
98
|
+
const before = y;
|
|
99
|
+
await page.mouse.wheel(0, half);
|
|
100
|
+
await page.waitForTimeout(REVEAL_STEP_MS);
|
|
101
|
+
// Three steps without movement: the page does not scroll (an inner scroller, overflow hidden).
|
|
102
|
+
stalled = (await page.evaluate(() => scrollY)) === before ? stalled + 1 : 0;
|
|
103
|
+
}
|
|
104
|
+
await page.evaluate(() => scrollTo({ top: 0, left: 0, behavior: "instant" }));
|
|
105
|
+
// Park the pointer outside the viewport so the top-left element is not measured in :hover.
|
|
106
|
+
await page.mouse.move(-1, -1);
|
|
107
|
+
await page.waitForLoadState("networkidle", { timeout: REVEAL_IDLE_CAP_MS }).catch(() => {});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// A DevTools protocol session for the page (Chromium only). The context closing detaches it.
|
|
111
|
+
export function cdpSession(page) {
|
|
112
|
+
return page.context().newCDPSession(page);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Callers close the returned page's context via page.context().close().
|
|
116
|
+
// opts.height: the viewport height in px, VIEWPORT_HEIGHT when not given.
|
|
117
|
+
export async function openTarget(browser, target, width, opts = {}) {
|
|
118
|
+
const context = await browser.newContext({
|
|
119
|
+
viewport: { width, height: opts.height ?? VIEWPORT_HEIGHT },
|
|
120
|
+
// The measurers load the screenshot back into the page as a data: image; a strict CSP would block it.
|
|
121
|
+
bypassCSP: true,
|
|
122
|
+
...(opts.still === true ? { reducedMotion: "reduce" } : {}),
|
|
123
|
+
// A script-free open (the extreme case pages): no page script runs in any frame of the context.
|
|
124
|
+
...(opts.noScript === true ? { javaScriptEnabled: false } : {}),
|
|
125
|
+
// A guarded load (map-page), a raw open (motion) and a script-free open block service workers: a request a
|
|
126
|
+
// worker answers never reaches the route.
|
|
127
|
+
...(opts.navigate || opts.bare === true || opts.noScript === true ? { serviceWorkers: "block" } : {}),
|
|
128
|
+
});
|
|
129
|
+
try {
|
|
130
|
+
// An opt-in navigation guard (map-page, motion): prepare routes the context (and may add init
|
|
131
|
+
// scripts) before any page opens, and navigate replaces the plain goto. Every other command loads the
|
|
132
|
+
// page as before.
|
|
133
|
+
if (opts.prepare) await opts.prepare(context);
|
|
134
|
+
const page = await context.newPage();
|
|
135
|
+
if (opts.navigate) await opts.navigate(page, toUrl(target, opts.cwd));
|
|
136
|
+
else await page.goto(toUrl(target, opts.cwd), { waitUntil: "load" });
|
|
137
|
+
// A raw open (motion) returns at load: no settle, no reveal pass, no wait for animations.
|
|
138
|
+
if (opts.bare === true) return page;
|
|
139
|
+
await page.waitForTimeout(SETTLE_MS);
|
|
140
|
+
await revealLazyContent(page);
|
|
141
|
+
await waitForAnimations(page);
|
|
142
|
+
return page;
|
|
143
|
+
} catch (err) {
|
|
144
|
+
await context.close();
|
|
145
|
+
throw err;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Entrance fades would otherwise be measured half transparent. Wait for running
|
|
150
|
+
// finite animations and transitions, capped (an implementation tolerance).
|
|
151
|
+
export async function waitForAnimations(page) {
|
|
152
|
+
await page.evaluate(async (cap) => {
|
|
153
|
+
const finite = document.getAnimations().filter((a) => {
|
|
154
|
+
const end = a.effect?.getComputedTiming?.().endTime;
|
|
155
|
+
return a.playState === "running" && Number.isFinite(end);
|
|
156
|
+
});
|
|
157
|
+
await Promise.race([
|
|
158
|
+
Promise.allSettled(finite.map((a) => a.finished)),
|
|
159
|
+
new Promise((r) => setTimeout(r, cap)),
|
|
160
|
+
]);
|
|
161
|
+
}, ANIMATION_CAP_MS);
|
|
162
|
+
}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { VIEWPORT_HEIGHT, openBrowser, openTarget, resolveTarget } from "../browser.mjs";
|
|
5
|
+
import { ASSET_RUN_CAP_MS, loadAssetBytes, withinCap } from "../measure/asset.mjs";
|
|
6
|
+
import { readLazuliMd } from "../project/lazuli-md.mjs";
|
|
7
|
+
import { makeBlindFolder } from "../project/blind.mjs";
|
|
8
|
+
import { PAGE_REPORT } from "./check-design.mjs";
|
|
9
|
+
import { matchGoals, sameTarget, targetKey } from "../project/match.mjs";
|
|
10
|
+
import { readRecords } from "../project/records.mjs";
|
|
11
|
+
import { pageTiles } from "../measure/tiles.mjs";
|
|
12
|
+
|
|
13
|
+
// The tallest single screenshot taken (a technical limit): a taller page is shot in tiles of this height
|
|
14
|
+
// (src/measure/tiles.mjs), by capture and by the color measurer.
|
|
15
|
+
export const FULL_PAGE_CAP_PX = 10000;
|
|
16
|
+
export const FULL_PAGE_CAP_WIDTH_PX = 4000;
|
|
17
|
+
|
|
18
|
+
const norm = (s) => String(s ?? "").trim().toLowerCase();
|
|
19
|
+
const oneLine = (s) => String(s ?? "").replace(/\s+/g, " ").trim();
|
|
20
|
+
const plural = (n, word) => `${n} ${word}${n === 1 ? "" : "s"}`;
|
|
21
|
+
|
|
22
|
+
// UTC time as YYYYMMDDTHHmmssSSSZ.
|
|
23
|
+
export function makeCaptureId(date) {
|
|
24
|
+
return date.toISOString().replace(/[-:]/g, "").replace(".", "");
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// A new folder under parent named by the time (makeCaptureId). The leaf is created without recursive,
|
|
28
|
+
// so a folder made in the same millisecond moves to the next one.
|
|
29
|
+
export async function makeStampedDir(parent) {
|
|
30
|
+
await fs.mkdir(parent, { recursive: true });
|
|
31
|
+
for (let at = Date.now(); ; at += 1) {
|
|
32
|
+
const now = new Date(at);
|
|
33
|
+
const id = makeCaptureId(now);
|
|
34
|
+
const dir = path.join(parent, id);
|
|
35
|
+
try {
|
|
36
|
+
await fs.mkdir(dir);
|
|
37
|
+
return { id, dir, now };
|
|
38
|
+
} catch (err) {
|
|
39
|
+
if (err?.code !== "EEXIST") {
|
|
40
|
+
throw err;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// The clip of a full-page screenshot, capped at FULL_PAGE_CAP_PX tall and FULL_PAGE_CAP_WIDTH_PX wide,
|
|
47
|
+
// and a note for each cap that cut the page.
|
|
48
|
+
export async function fullPageClip(page, width) {
|
|
49
|
+
const size = await page.evaluate(() => ({
|
|
50
|
+
w: Math.max(document.documentElement.scrollWidth, innerWidth),
|
|
51
|
+
h: Math.max(document.documentElement.scrollHeight, innerHeight),
|
|
52
|
+
}));
|
|
53
|
+
const clipWidth = Math.min(size.w, FULL_PAGE_CAP_WIDTH_PX);
|
|
54
|
+
const clipHeight = Math.min(size.h, FULL_PAGE_CAP_PX);
|
|
55
|
+
const notes = [];
|
|
56
|
+
if (clipHeight < size.h) {
|
|
57
|
+
notes.push(`The full capture at ${width} px stops at ${FULL_PAGE_CAP_PX} px; the page is ${size.h} px tall.`);
|
|
58
|
+
}
|
|
59
|
+
if (clipWidth < size.w) {
|
|
60
|
+
notes.push(`The full capture at ${width} px stops at ${FULL_PAGE_CAP_WIDTH_PX} px wide; the page is ${size.w} px wide.`);
|
|
61
|
+
}
|
|
62
|
+
return { clip: { x: 0, y: 0, width: clipWidth, height: clipHeight }, notes };
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// An .svg target (a symbol) is not opened as a document: its bytes are drawn through an <img> on a fixed
|
|
66
|
+
// canvas, the viewport, in a context that aborts every request, so no script in it runs and nothing is fetched.
|
|
67
|
+
// The canvas is split into a white half and a black half with the same symbol on each (the two grounds of GR4
|
|
68
|
+
// and symbol-sheet.png), so a light symbol made for dark grounds still shows. It does not scroll, so its
|
|
69
|
+
// viewport shot stands for the full page too.
|
|
70
|
+
const isSvgUrl = (url) => /\.svg$/i.test(new URL(url).pathname);
|
|
71
|
+
const svgCanvas = (src) =>
|
|
72
|
+
`<!doctype html><html><head><style>html,body{margin:0;height:100%}` +
|
|
73
|
+
`body{display:flex}.half{flex:1;display:flex;align-items:center;justify-content:center}` +
|
|
74
|
+
`.half img{width:40vw;height:80vh;object-fit:contain;display:block}</style></head><body>` +
|
|
75
|
+
`<div class="half" style="background:#ffffff"><img alt="" src="${src}"></div>` +
|
|
76
|
+
`<div class="half" style="background:#000000"><img alt="" src="${src}"></div></body></html>`;
|
|
77
|
+
|
|
78
|
+
async function shootSvg(browser, src, width, file, capMs) {
|
|
79
|
+
const context = await browser.newContext({ viewport: { width, height: VIEWPORT_HEIGHT }, deviceScaleFactor: 1 });
|
|
80
|
+
await withinCap(context, capMs, `The SVG capture at ${width} px`, async () => {
|
|
81
|
+
await context.route("**/*", (route) => route.abort());
|
|
82
|
+
const page = await context.newPage();
|
|
83
|
+
await page.setContent(svgCanvas(src));
|
|
84
|
+
await page.evaluate(() => Promise.all([...document.images].map((img) => img.decode())));
|
|
85
|
+
await page.screenshot({ path: file, type: "png" });
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function readReportOf(cwd, target, name = "report.json") {
|
|
90
|
+
const file = path.join(cwd, ".lazuli", name);
|
|
91
|
+
let text;
|
|
92
|
+
try {
|
|
93
|
+
text = await fs.readFile(file, "utf8");
|
|
94
|
+
} catch {
|
|
95
|
+
return null;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const parsed = JSON.parse(text);
|
|
99
|
+
return typeof parsed?.target === "string" && sameTarget(parsed.target, target, cwd) ? text : null;
|
|
100
|
+
} catch {
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// The blind prompt. It names images only: nothing of the project's goals, idea, decisions or breaks.
|
|
106
|
+
function firstLookText(manifest) {
|
|
107
|
+
const lines = manifest.widths.map((w) => `- ${w} px: ${manifest.blind.images[String(w)]}`);
|
|
108
|
+
return [
|
|
109
|
+
"# First look",
|
|
110
|
+
"",
|
|
111
|
+
"Open only the images listed here, one at a time, and answer from what you see in each. Do not open any other file: this is a blind test, and knowing what the page is meant to do spoils it.",
|
|
112
|
+
"",
|
|
113
|
+
...lines,
|
|
114
|
+
"",
|
|
115
|
+
"For each image answer three questions in a few words:",
|
|
116
|
+
"1. What is this about?",
|
|
117
|
+
"2. What is the main action, the one thing this screen wants you to do?",
|
|
118
|
+
"3. What does it feel like?",
|
|
119
|
+
"",
|
|
120
|
+
"Return only this JSON:",
|
|
121
|
+
`{"captureId": "${manifest.captureId}", "reader": "<who read it>", "answers": [{"width": <w>, "about": "", "mainAction": "", "feeling": ""}]}`,
|
|
122
|
+
"",
|
|
123
|
+
].join("\n");
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
// The simulated tasks recorded for this page, newest first: counts and the tester's words, never the
|
|
127
|
+
// names of what was chosen (page text). A recorded task is context for the reviewer, not a check.
|
|
128
|
+
function tasksText(tasks) {
|
|
129
|
+
const lines = ["## Simulated tasks", ""];
|
|
130
|
+
if (tasks === null) {
|
|
131
|
+
return [...lines, "The records file of this page could not be read, so no simulated task is listed.", ""];
|
|
132
|
+
}
|
|
133
|
+
if (tasks.length === 0) {
|
|
134
|
+
return [...lines, "No simulated task is recorded for this page.", ""];
|
|
135
|
+
}
|
|
136
|
+
for (const r of [...tasks].reverse()) {
|
|
137
|
+
const d = r.data ?? {};
|
|
138
|
+
const steps = Array.isArray(d.steps) ? d.steps : [];
|
|
139
|
+
const c = d.counts ?? {};
|
|
140
|
+
const hes = steps.filter((s) => s?.hesitated);
|
|
141
|
+
lines.push(
|
|
142
|
+
`- ${r.at}, piece ${oneLine(d.piece)}: "${oneLine(d.task)}"`,
|
|
143
|
+
` - Tester: ${oneLine(d.tester) === "" ? "not given" : oneLine(d.tester)}`,
|
|
144
|
+
` - Outcome: ${d.outcome}${d.reason ? ` (${oneLine(d.reason)})` : ""}`,
|
|
145
|
+
` - Counts: ${plural(c.steps ?? 0, "step")}, ${plural(c.hesitations ?? 0, "hesitation")}, ${plural(c.scrolls ?? 0, "scroll")}`,
|
|
146
|
+
` - Hesitations: ${hes.length === 0 ? "none" : hes.map((s) => `step ${s.step}: "${oneLine(s.hesitation)}"`).join("; ")}`,
|
|
147
|
+
` - Remembered: ${oneLine(d.remembered) === "" ? "nothing" : `"${oneLine(d.remembered)}"`}`,
|
|
148
|
+
);
|
|
149
|
+
}
|
|
150
|
+
lines.push("");
|
|
151
|
+
return lines;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// The reviewer packet: declared effects, captures and measures. Never the Decisions log.
|
|
155
|
+
function reviewText(manifest, md, goals, tasks) {
|
|
156
|
+
const pieces = new Set(goals.map((g) => norm(g.piece)));
|
|
157
|
+
const breaks = (md?.breaks ?? []).filter((b) => pieces.has(norm(b.piece)));
|
|
158
|
+
const lines = ["# Review packet", "", `Target: ${oneLine(manifest.target)}`, `Capture: ${manifest.captureId}`, "", "## Idea", "", md?.idea ? oneLine(md.idea) : "No idea is written for this project.", "", "## Goals for this page", ""];
|
|
159
|
+
if (goals.length === 0) {
|
|
160
|
+
lines.push("No goal is written for this page.", "");
|
|
161
|
+
}
|
|
162
|
+
for (const g of goals) {
|
|
163
|
+
lines.push(`- Piece: ${g.piece}`, ` - Understand: ${oneLine(g.understand)}`, ` - Feel: ${oneLine(g.feel)}`, ` - Do: ${oneLine(g.do)}`);
|
|
164
|
+
// The rhythm map, so the reviewer can judge the sequence. Only here: the first look stays blind.
|
|
165
|
+
if (g.rhythm?.length) {
|
|
166
|
+
lines.push(` - Rhythm: ${g.rhythm.join(", ")}`);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
if (goals.length > 0) {
|
|
170
|
+
lines.push("");
|
|
171
|
+
}
|
|
172
|
+
lines.push("## Breaks on these pieces", "");
|
|
173
|
+
if (breaks.length === 0) {
|
|
174
|
+
lines.push("None.", "");
|
|
175
|
+
}
|
|
176
|
+
for (const b of breaks) {
|
|
177
|
+
lines.push(`- Rule: ${b.rule}`, ` - Piece: ${b.piece}`, ` - Effect: ${oneLine(b.effect)}`, ` - Status: ${b.status ?? "no status"}`);
|
|
178
|
+
}
|
|
179
|
+
if (breaks.length > 0) {
|
|
180
|
+
lines.push("");
|
|
181
|
+
}
|
|
182
|
+
lines.push("## Captures", "");
|
|
183
|
+
for (const w of manifest.widths) {
|
|
184
|
+
// A 1.0.0 capture.json has no fullTiles: its one full image is the whole list.
|
|
185
|
+
const tiles = manifest.fullTiles?.[String(w)] ?? [manifest.full[String(w)]];
|
|
186
|
+
if (tiles.length === 1) {
|
|
187
|
+
lines.push(`- ${w} px, full page: ${path.join(manifest.dir, tiles[0])}`);
|
|
188
|
+
} else {
|
|
189
|
+
lines.push(`- ${w} px, full page in ${tiles.length} tiles, top to bottom:`, ...tiles.map((t) => ` - ${path.join(manifest.dir, t)}`));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (manifest.notes.length > 0) {
|
|
193
|
+
lines.push("", ...manifest.notes.map((n) => `Note: ${n}`));
|
|
194
|
+
}
|
|
195
|
+
lines.push("", "## Measures", "");
|
|
196
|
+
lines.push(manifest.report ? `Report: ${path.join(manifest.dir, manifest.report)}` : "No report for this page. Run check-design on it first to have one.", "");
|
|
197
|
+
if (manifest.pageReport) lines.push(`Page report (text contrast and type, read before --asset): ${path.join(manifest.dir, manifest.pageReport)}`, "");
|
|
198
|
+
lines.push("## First look", "", "First-look answers: first-look.json in this folder (written by record-first-look; review only after it exists).", "");
|
|
199
|
+
lines.push(...tasksText(tasks));
|
|
200
|
+
lines.push(
|
|
201
|
+
"## Verdict",
|
|
202
|
+
"",
|
|
203
|
+
"Return only this JSON:",
|
|
204
|
+
`{"captureId": "${manifest.captureId}", "reviewer": "<who reviewed>", "verdict": "redo|fix|approve", "idea": "shown|missing|none", "goals": [{"piece": "<piece>", "understand": "met|partly|missed", "feel": "met|partly|missed", "do": "met|partly|missed", "evidence": "<quote from the first look or the report>"}], "fixes": ["<one change per item>"]}`,
|
|
205
|
+
"",
|
|
206
|
+
"- verdict: redo, fix or approve.",
|
|
207
|
+
"- idea: shown when the capture carries the idea, missing when it does not, none when no idea is written.",
|
|
208
|
+
"- goals: one item per goal listed above; understand, feel and do each met, partly or missed.",
|
|
209
|
+
"- fixes: one change per item.",
|
|
210
|
+
"",
|
|
211
|
+
);
|
|
212
|
+
return lines.join("\n");
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
export async function capture({ target, widths: askedWidths = [1440, 768, 390], cwd = process.cwd(), browser: givenBrowser, capMs = ASSET_RUN_CAP_MS } = {}) {
|
|
216
|
+
const widths = [...new Set(askedWidths)];
|
|
217
|
+
const root = path.resolve(cwd);
|
|
218
|
+
const url = resolveTarget(target, root); // a missing local file fails here, before any browser starts
|
|
219
|
+
const key = targetKey(target, root);
|
|
220
|
+
const parent = path.join(root, ".lazuli", "captures", key);
|
|
221
|
+
|
|
222
|
+
let targetFile = null;
|
|
223
|
+
let targetMtimeMs = null;
|
|
224
|
+
if (url.startsWith("file:")) {
|
|
225
|
+
targetFile = fileURLToPath(url);
|
|
226
|
+
targetMtimeMs = (await fs.stat(targetFile)).mtimeMs;
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
const md = await readLazuliMd(root);
|
|
230
|
+
const goals = matchGoals(md, target, root);
|
|
231
|
+
const reportText = await readReportOf(root, target);
|
|
232
|
+
// With an --asset report, the page report check-design --asset kept beside it (a piece's text contrast and type).
|
|
233
|
+
const pageReportText = reportText !== null && JSON.parse(reportText).asset ? await readReportOf(root, target, PAGE_REPORT) : null;
|
|
234
|
+
|
|
235
|
+
const browser = givenBrowser ?? (await openBrowser());
|
|
236
|
+
let now;
|
|
237
|
+
let captureId;
|
|
238
|
+
let dir;
|
|
239
|
+
const first = {};
|
|
240
|
+
const full = {};
|
|
241
|
+
const fullTiles = {};
|
|
242
|
+
const notes = [];
|
|
243
|
+
try {
|
|
244
|
+
// A missing or unloadable SVG fails here, before the capture folder is made.
|
|
245
|
+
const svgSrc = isSvgUrl(url) ? `data:image/svg+xml;base64,${(await loadAssetBytes({ target, url, ext: ".svg" }, browser)).bytes.toString("base64")}` : null;
|
|
246
|
+
({ id: captureId, dir, now } = await makeStampedDir(parent));
|
|
247
|
+
for (const width of widths) {
|
|
248
|
+
if (svgSrc !== null) {
|
|
249
|
+
first[String(width)] = `first-${width}.png`;
|
|
250
|
+
full[String(width)] = `full-${width}.png`;
|
|
251
|
+
await shootSvg(browser, svgSrc, width, path.join(dir, first[String(width)]), capMs);
|
|
252
|
+
await fs.copyFile(path.join(dir, first[String(width)]), path.join(dir, full[String(width)]));
|
|
253
|
+
fullTiles[String(width)] = [full[String(width)]];
|
|
254
|
+
notes.push(`The target is an SVG: it was drawn through an image on white and on black on a ${width}x${VIEWPORT_HEIGHT} canvas, viewport only, and no script in it ran.`);
|
|
255
|
+
continue;
|
|
256
|
+
}
|
|
257
|
+
const page = await openTarget(browser, target, width, { cwd: root });
|
|
258
|
+
try {
|
|
259
|
+
const viewport = page.viewportSize();
|
|
260
|
+
first[String(width)] = `first-${width}.png`;
|
|
261
|
+
await page.screenshot({ path: path.join(dir, first[String(width)]), type: "png", clip: { x: 0, y: 0, width: viewport.width, height: viewport.height } });
|
|
262
|
+
const { tiles, notes: cut } = await pageTiles(page, width);
|
|
263
|
+
notes.push(...cut);
|
|
264
|
+
// The first tile keeps the 1.0.0 name, so readers of full[<w>] still find the top of the page.
|
|
265
|
+
const names = tiles.map((_, i) => (i === 0 ? `full-${width}.png` : `full-${width}-${i + 1}.png`));
|
|
266
|
+
for (const [i, clip] of tiles.entries()) {
|
|
267
|
+
await page.screenshot({ path: path.join(dir, names[i]), type: "png", fullPage: true, clip });
|
|
268
|
+
}
|
|
269
|
+
full[String(width)] = names[0];
|
|
270
|
+
fullTiles[String(width)] = names;
|
|
271
|
+
} finally {
|
|
272
|
+
await page.context().close();
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
} finally {
|
|
276
|
+
if (!givenBrowser) {
|
|
277
|
+
await browser.close();
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
let report = null;
|
|
282
|
+
if (reportText !== null) {
|
|
283
|
+
report = "report.json";
|
|
284
|
+
await fs.writeFile(path.join(dir, report), reportText);
|
|
285
|
+
}
|
|
286
|
+
let pageReport = null;
|
|
287
|
+
if (pageReportText !== null) {
|
|
288
|
+
pageReport = PAGE_REPORT;
|
|
289
|
+
await fs.writeFile(path.join(dir, pageReport), pageReportText);
|
|
290
|
+
}
|
|
291
|
+
// The blind first look lives in its own opaque folder: neutral file names, no project, page key or host in its path.
|
|
292
|
+
const { token, dir: blindDir } = await makeBlindFolder(root);
|
|
293
|
+
const blindImages = {};
|
|
294
|
+
for (const [i, w] of widths.entries()) {
|
|
295
|
+
const copy = path.join(blindDir, `${i + 1}.png`);
|
|
296
|
+
await fs.copyFile(path.join(dir, first[String(w)]), copy);
|
|
297
|
+
blindImages[String(w)] = copy;
|
|
298
|
+
}
|
|
299
|
+
const blind = { token, dir: blindDir, prompt: path.join(blindDir, "first-look.md"), images: blindImages };
|
|
300
|
+
const manifest = { target, key, captureId, capturedAt: now.toISOString(), widths, first, full, fullTiles, targetMtimeMs, targetFile, report, ...(pageReport ? { pageReport } : {}), notes, dir, blind };
|
|
301
|
+
// capture.json keeps paths relative to the project where it can; blind.dir is outside the project on purpose.
|
|
302
|
+
const inside = (p) => (p !== null && !path.relative(root, p).startsWith("..") && !path.isAbsolute(path.relative(root, p)) ? path.relative(root, p) : p);
|
|
303
|
+
await fs.writeFile(path.join(dir, "capture.json"), JSON.stringify({ ...manifest, dir: inside(dir), targetFile: inside(targetFile) }, null, 2));
|
|
304
|
+
await fs.writeFile(blind.prompt, firstLookText(manifest));
|
|
305
|
+
let tasks;
|
|
306
|
+
try {
|
|
307
|
+
tasks = (await readRecords(root, target)).filter((r) => r.kind === "task");
|
|
308
|
+
} catch {
|
|
309
|
+
tasks = null;
|
|
310
|
+
}
|
|
311
|
+
await fs.writeFile(path.join(dir, "review.md"), reviewText(manifest, md, goals, tasks));
|
|
312
|
+
return manifest;
|
|
313
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// The commands of /lazuli, in the order the router and the usage text show them.
|
|
2
|
+
// runs: "cli" is run by bin/lazuli.mjs, "agent" is a procedure your AI agent follows.
|
|
3
|
+
// available: false means planned. Later sub-plans flip it when the command exists.
|
|
4
|
+
// ask-the-jury is a paid plan and is not part of v1.0, so it is not listed.
|
|
5
|
+
export const COMMANDS = [
|
|
6
|
+
{ name: "start-project", summary: "Creates LAZULI.md for the project, where goals, mode and breaks are recorded.", runs: "cli", available: true },
|
|
7
|
+
{ name: "set-goals", summary: "Writes what each piece must make people understand, feel and do.", runs: "agent", available: true },
|
|
8
|
+
{ name: "show-options", summary: "Shows 6 to 9 measured alternatives as thumbnails to choose from.", runs: "agent", available: true },
|
|
9
|
+
{ name: "create", summary: "Makes the piece you ask for, in any area.", runs: "agent", available: true },
|
|
10
|
+
{ name: "improve", summary: "Makes something that already exists better while keeping its identity.", runs: "agent", available: true },
|
|
11
|
+
{ name: "check-design", summary: "Measures a page against the kit's measurable rules (URL or HTML file) and reports findings by rule.", runs: "cli", available: true },
|
|
12
|
+
{ name: "break-a-rule", summary: "Records a deliberate rule break with the effect you expect and the check planned for it.", runs: "agent", available: true },
|
|
13
|
+
{ name: "review-design", summary: "A reviewer who did not take part in the work gives a verdict: redo, fix or approve.", runs: "agent", available: true },
|
|
14
|
+
{ name: "remember-this", summary: "Turns a correction into a rule with a condition and a test.", runs: "agent", available: true },
|
|
15
|
+
{ name: "explain-decisions", summary: "Writes the memo that explains each decision to the client.", runs: "agent", available: true },
|
|
16
|
+
];
|
|
17
|
+
|
|
18
|
+
export function availableCommands() {
|
|
19
|
+
return COMMANDS.filter((c) => c.available);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Helpers the agent procedures call, in usage order. They are not slash commands; each is a CLI the agent runs.
|
|
23
|
+
// Later sub-plan tasks append theirs.
|
|
24
|
+
export const HELPERS = [
|
|
25
|
+
{ name: "list-rules", summary: "Lists the rules (kit and learned) for a moment or an area, as text or JSON." },
|
|
26
|
+
{ name: "record-break", summary: "Writes or updates one entry of the Breaks log in LAZULI.md." },
|
|
27
|
+
{ name: "record-decision", summary: "Writes or updates one entry of the Decisions log in LAZULI.md." },
|
|
28
|
+
{ name: "capture", summary: "Screenshots a page and writes a blind first-look prompt and a reviewer packet under .lazuli/captures." },
|
|
29
|
+
{ name: "record-first-look", summary: "Stores the blind first-look answers for a capture after checking every width is answered." },
|
|
30
|
+
{ name: "record-review", summary: "Stores a reviewer verdict for a capture after checking it judges every goal of the page." },
|
|
31
|
+
{ name: "check-goals", summary: "Reports each goal's recorded check (met, partly, missed, stale or not checked) and whether the gate passes." },
|
|
32
|
+
{ name: "draft-memo", summary: "Gathers decisions, breaks, first looks and verdicts per goal into a draft for explain-decisions, and lists the gaps." },
|
|
33
|
+
{ name: "render-options", summary: "Renders 6 to 9 option HTML files, measures each and writes one contact sheet per width, with no ranking." },
|
|
34
|
+
{ name: "compare-designs", summary: "Reports the structural distance of a page from a baseline made without the kit, per width, with no verdict (hypothesis H1). `--options <folder>` places each option file of a folder from near to far against the baseline." },
|
|
35
|
+
{ name: "map-page", summary: "Maps one step of a simulated task, read only: screenshots and a numbered list of what can be used, stopping at forms and checkout off local targets." },
|
|
36
|
+
{ name: "record-task", summary: "Stores the tester's answer for the last mapped step of a simulated task and prints the next step, or closes the task with counts." },
|
|
37
|
+
];
|