@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,167 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { cdpSession } from "../browser.mjs";
|
|
3
|
+
|
|
4
|
+
// Sampling limits, not rule cutoffs. The report notes when one of them limits the result.
|
|
5
|
+
// Wait for webfonts at most this long (the same cap value as the v0.1 animation wait).
|
|
6
|
+
export const FONT_WAIT_MS = 3000;
|
|
7
|
+
// How many text elements have their rendered fonts read through the DevTools protocol.
|
|
8
|
+
const MAX_FONT_ELEMENTS = 1500;
|
|
9
|
+
// DevTools calls in flight at once.
|
|
10
|
+
const CDP_BATCH = 50;
|
|
11
|
+
// Fallback entries kept in the report (deduplicated by declared family and rendered families).
|
|
12
|
+
const MAX_FALLBACKS = 20;
|
|
13
|
+
const STASH_KEY = "__lazuliTypeEls";
|
|
14
|
+
|
|
15
|
+
let script;
|
|
16
|
+
|
|
17
|
+
// Chrome reports the font's own name ("Raleway Thin", "Satoshi Medium", "Geist Mono" for geistMono).
|
|
18
|
+
// A rendered name matches a declared one when, ignoring case and punctuation, it is the same or
|
|
19
|
+
// the declared name plus style words only. Another family that shares a prefix ("Noto Sans Mono"
|
|
20
|
+
// for "Noto Sans", "Segoe UI Emoji" for "Segoe UI") is not a match.
|
|
21
|
+
const squash = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
22
|
+
const STYLE_ONLY = /^(?:thin|hairline|extralight|ultralight|light|regular|book|roman|normal|medium|semibold|demibold|bold|extrabold|ultrabold|heavy|black|italic|oblique|variable|vf)+$/;
|
|
23
|
+
const extendsName = (base, name) => {
|
|
24
|
+
const b = squash(base);
|
|
25
|
+
const n = squash(name);
|
|
26
|
+
if (b === "" || !n.startsWith(b)) return false;
|
|
27
|
+
const rest = n.slice(b.length);
|
|
28
|
+
return rest === "" || STYLE_ONLY.test(rest);
|
|
29
|
+
};
|
|
30
|
+
export const nameMatches = (declared, rendered) => rendered.some((r) => extendsName(declared, r));
|
|
31
|
+
|
|
32
|
+
// Groups rendered family names (name -> glyph count): a name joins the longest declared family it
|
|
33
|
+
// extends with style words, else the shortest other rendered name it extends. Shown by its shortest name.
|
|
34
|
+
export function groupFamilies(glyphs, declaredNames = []) {
|
|
35
|
+
const names = [...glyphs.keys()];
|
|
36
|
+
const roots = declaredNames.filter((d) => squash(d) !== "");
|
|
37
|
+
const keyOf = (name) => {
|
|
38
|
+
const declared = roots.filter((d) => extendsName(d, name)).sort((a, b) => squash(b).length - squash(a).length)[0];
|
|
39
|
+
if (declared) return squash(declared);
|
|
40
|
+
const shorter = names.filter((n) => n !== name && extendsName(n, name)).sort((a, b) => a.length - b.length)[0];
|
|
41
|
+
return shorter ? squash(shorter) : squash(name);
|
|
42
|
+
};
|
|
43
|
+
const grouped = new Map();
|
|
44
|
+
for (const [name, count] of glyphs) {
|
|
45
|
+
const key = keyOf(name);
|
|
46
|
+
const g = grouped.get(key) ?? { family: name, glyphs: 0 };
|
|
47
|
+
if (name.length < g.family.length) g.family = name;
|
|
48
|
+
g.glyphs += count;
|
|
49
|
+
grouped.set(key, g);
|
|
50
|
+
}
|
|
51
|
+
return [...grouped.values()].sort((a, b) => b.glyphs - a.glyphs);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// A family counts as one of the page's families when some element asks for it first, or when it paints
|
|
55
|
+
// more than half of the glyphs of some element (that element's face, such as the system font behind a
|
|
56
|
+
// generic family or a fallback for a webfont that failed). A family that only ever paints the minority of
|
|
57
|
+
// an element's glyphs (an arrow, a check mark, an accent the main font lacks) is a per-glyph fallback.
|
|
58
|
+
// The half is the definition of "most of the glyphs", not a rule cutoff.
|
|
59
|
+
const MOST_OF_AN_ELEMENT = 0.5;
|
|
60
|
+
export function countedFamilies(perElement, declaredNames = []) {
|
|
61
|
+
const all = new Map();
|
|
62
|
+
const faces = new Set();
|
|
63
|
+
for (const list of perElement) {
|
|
64
|
+
if (!list || list.length === 0) continue;
|
|
65
|
+
const total = list.reduce((s, f) => s + (f.glyphCount ?? 0), 0);
|
|
66
|
+
for (const f of list) {
|
|
67
|
+
all.set(f.familyName, (all.get(f.familyName) ?? 0) + (f.glyphCount ?? 0));
|
|
68
|
+
if (total > 0 && (f.glyphCount ?? 0) / total > MOST_OF_AN_ELEMENT) faces.add(f.familyName);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const glyphs = new Map();
|
|
72
|
+
const ignored = [];
|
|
73
|
+
for (const [name, count] of all) {
|
|
74
|
+
if (faces.has(name) || declaredNames.some((d) => extendsName(d, name))) glyphs.set(name, count);
|
|
75
|
+
else ignored.push({ family: name, glyphs: count });
|
|
76
|
+
}
|
|
77
|
+
ignored.sort((a, b) => b.glyphs - a.glyphs || a.family.localeCompare(b.family));
|
|
78
|
+
return { glyphs, ignored };
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function renderedFonts(page, count) {
|
|
82
|
+
const client = await cdpSession(page);
|
|
83
|
+
const perElement = new Array(count).fill(null);
|
|
84
|
+
try {
|
|
85
|
+
await client.send("DOM.enable");
|
|
86
|
+
await client.send("CSS.enable");
|
|
87
|
+
await client.send("DOM.getDocument", { depth: 0 });
|
|
88
|
+
const { result } = await client.send("Runtime.evaluate", { expression: `globalThis.${STASH_KEY}` });
|
|
89
|
+
if (!result.objectId) return perElement;
|
|
90
|
+
const { result: props } = await client.send("Runtime.getProperties", { objectId: result.objectId, ownProperties: true });
|
|
91
|
+
const handles = props
|
|
92
|
+
.filter((p) => /^\d+$/.test(p.name) && p.value?.objectId)
|
|
93
|
+
.map((p) => ({ index: Number(p.name), objectId: p.value.objectId }));
|
|
94
|
+
for (let i = 0; i < handles.length; i += CDP_BATCH) {
|
|
95
|
+
await Promise.all(
|
|
96
|
+
handles.slice(i, i + CDP_BATCH).map(async ({ index, objectId }) => {
|
|
97
|
+
try {
|
|
98
|
+
const { nodeId } = await client.send("DOM.requestNode", { objectId });
|
|
99
|
+
const { fonts } = await client.send("CSS.getPlatformFontsForNode", { nodeId });
|
|
100
|
+
perElement[index] = fonts ?? [];
|
|
101
|
+
} catch {
|
|
102
|
+
perElement[index] = null; // a node that went away between the two calls
|
|
103
|
+
}
|
|
104
|
+
}),
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
return perElement;
|
|
108
|
+
} finally {
|
|
109
|
+
await page.evaluate((key) => { delete globalThis[key]; }, STASH_KEY).catch(() => {});
|
|
110
|
+
await client.detach().catch(() => {});
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Rendered fonts, line length, size, line height, scale and heading shape of a page.
|
|
115
|
+
export async function measureType(page, ctx) {
|
|
116
|
+
script ??= await fs.readFile(new URL("./in-page/type.js", import.meta.url), "utf8");
|
|
117
|
+
const notes = [];
|
|
118
|
+
|
|
119
|
+
const settled = await page.evaluate(
|
|
120
|
+
(cap) =>
|
|
121
|
+
Promise.race([
|
|
122
|
+
document.fonts.ready.then(() => true),
|
|
123
|
+
new Promise((resolve) => setTimeout(() => resolve(false), cap)),
|
|
124
|
+
]),
|
|
125
|
+
FONT_WAIT_MS,
|
|
126
|
+
);
|
|
127
|
+
if (!settled) notes.push("Fonts were still loading after 3 s; measured what was rendered.");
|
|
128
|
+
|
|
129
|
+
const opts = { maxFontElements: MAX_FONT_ELEMENTS, stashKey: STASH_KEY };
|
|
130
|
+
const parts = await page.evaluate(`(${script})(${JSON.stringify(opts)})`);
|
|
131
|
+
if (parts.totalTextElements > MAX_FONT_ELEMENTS) {
|
|
132
|
+
notes.push(`Rendered fonts were read for the first ${MAX_FONT_ELEMENTS} of ${parts.totalTextElements} text elements.`);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const fonts = await renderedFonts(page, parts.targetMeta.length);
|
|
136
|
+
|
|
137
|
+
const fallbacks = new Map();
|
|
138
|
+
parts.targetMeta.forEach((meta, i) => {
|
|
139
|
+
const list = fonts[i];
|
|
140
|
+
if (!list || list.length === 0) return;
|
|
141
|
+
const rendered = [...list].sort((a, b) => (b.glyphCount ?? 0) - (a.glyphCount ?? 0)).map((f) => f.familyName);
|
|
142
|
+
// A declared @font-face family that loaded is rendered under whatever name its file carries.
|
|
143
|
+
if (meta.named && meta.webfont !== "loaded" && !nameMatches(meta.declared, rendered)) {
|
|
144
|
+
const key = `${meta.declared}|${rendered.join("|")}`;
|
|
145
|
+
if (!fallbacks.has(key)) fallbacks.set(key, { selector: meta.selector, declared: meta.declared, rendered });
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
const kept = [...fallbacks.values()].slice(0, MAX_FALLBACKS);
|
|
150
|
+
if (fallbacks.size > MAX_FALLBACKS) notes.push(`Showing ${MAX_FALLBACKS} of ${fallbacks.size} distinct fallbacks.`);
|
|
151
|
+
const declared = parts.targetMeta.filter((m) => m.named).map((m) => m.declared);
|
|
152
|
+
const { glyphs, ignored } = countedFamilies(fonts, declared);
|
|
153
|
+
if (ignored.length > 0) {
|
|
154
|
+
const list = ignored.map((f) => `${f.family} (${f.glyphs} ${f.glyphs === 1 ? "glyph" : "glyphs"})`).join(", ");
|
|
155
|
+
notes.push(`Not counted as font families, because no element asks for them first and they paint less than half of the glyphs of every element they appear in: ${list}.`);
|
|
156
|
+
}
|
|
157
|
+
const families = groupFamilies(glyphs, declared);
|
|
158
|
+
return {
|
|
159
|
+
families,
|
|
160
|
+
fallbacks: kept,
|
|
161
|
+
blocks: parts.blocks,
|
|
162
|
+
body: parts.body,
|
|
163
|
+
scale: parts.scale,
|
|
164
|
+
headings: parts.headings,
|
|
165
|
+
notes,
|
|
166
|
+
};
|
|
167
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
|
|
3
|
+
let script;
|
|
4
|
+
|
|
5
|
+
// Visual weight by blur test (hypothesis H9): blur the first viewport, then score
|
|
6
|
+
// each candidate by how much it stands out from the ring around it.
|
|
7
|
+
export async function measureWeight(page, opts = {}) {
|
|
8
|
+
const n = Number(opts.blurPx ?? 20);
|
|
9
|
+
const blurPx = Number.isFinite(n) ? Math.min(100, Math.max(1, n)) : 20;
|
|
10
|
+
script ??= await fs.readFile(new URL("./in-page/weight.js", import.meta.url), "utf8");
|
|
11
|
+
// Weight is about what is seen first, so only the first viewport is captured.
|
|
12
|
+
const buf = await page.screenshot({ type: "png" });
|
|
13
|
+
const dataUrl = `data:image/png;base64,${buf.toString("base64")}`;
|
|
14
|
+
const { order, primary, primaryReason } = await page.evaluate(
|
|
15
|
+
`(${script})(${JSON.stringify(dataUrl)}, ${JSON.stringify(blurPx)})`,
|
|
16
|
+
);
|
|
17
|
+
return { blurPx, order, primary, primaryReason };
|
|
18
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// The strings public text and smoke logs must never hold: the hosts of the real test sites (with and without
|
|
2
|
+
// www.) and the deny list of the untracked .local/private.json. Shared by the test guards
|
|
3
|
+
// (tests/helpers/private.mjs), the smoke log and the release check, so there is one copy of the rule.
|
|
4
|
+
import { readFile } from "node:fs/promises";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
|
|
7
|
+
export const PRIVATE_TOKEN = "<private>";
|
|
8
|
+
|
|
9
|
+
async function readJson(file) {
|
|
10
|
+
try {
|
|
11
|
+
return JSON.parse(await readFile(file, "utf8"));
|
|
12
|
+
} catch (err) {
|
|
13
|
+
if (err?.code === "ENOENT") return null;
|
|
14
|
+
throw err;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// The host of each URL, lower case, with and without a leading www. Values that are not URLs are left out.
|
|
19
|
+
export function hostVariants(urls) {
|
|
20
|
+
const out = new Set();
|
|
21
|
+
for (const url of urls) {
|
|
22
|
+
let host;
|
|
23
|
+
try {
|
|
24
|
+
host = new URL(url).hostname.toLowerCase();
|
|
25
|
+
} catch {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
const bare = host.replace(/^www\./, "");
|
|
29
|
+
out.add(bare);
|
|
30
|
+
out.add(`www.${bare}`);
|
|
31
|
+
}
|
|
32
|
+
return [...out];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// The deny list of <root>/.local/private.json, lower case; [] when the file does not exist.
|
|
36
|
+
export async function readDeny(root) {
|
|
37
|
+
const priv = await readJson(path.join(root, ".local", "private.json"));
|
|
38
|
+
return (priv?.deny ?? []).filter((s) => typeof s === "string" && s.trim() !== "").map((s) => s.toLowerCase());
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Every URL of a smoke config shape ({ sites, screens, task }), tolerant of missing parts.
|
|
42
|
+
export const configUrls = (config) => [...(config?.sites ?? []).map((s) => s?.url), ...(config?.screens ?? []), config?.task?.url].filter((u) => typeof u === "string");
|
|
43
|
+
|
|
44
|
+
// The hosts of <root>/.local/smoke.json plus the deny list; [] when neither file exists.
|
|
45
|
+
export async function privateStrings(root) {
|
|
46
|
+
const smoke = await readJson(path.join(root, ".local", "smoke.json"));
|
|
47
|
+
return [...new Set([...hostVariants(configUrls(smoke)), ...(await readDeny(root))])];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
51
|
+
|
|
52
|
+
// A scrubber for log text: the origin of every known host (http or https, with or without www., any port)
|
|
53
|
+
// is removed so only the path is left, then every private string left is replaced with PRIVATE_TOKEN,
|
|
54
|
+
// case-insensitively. addHost(url) learns a host met at run time, such as the target of a redirect.
|
|
55
|
+
export function makeScrubber({ urls = [], deny = [] } = {}) {
|
|
56
|
+
const hosts = new Set(hostVariants(urls).map((h) => h.replace(/^www\./, "")));
|
|
57
|
+
const strings = new Set(deny.map((s) => s.toLowerCase()));
|
|
58
|
+
let origin;
|
|
59
|
+
let other;
|
|
60
|
+
const rebuild = () => {
|
|
61
|
+
const bare = [...hosts].sort((a, b) => b.length - a.length).map(escape);
|
|
62
|
+
origin = bare.length ? new RegExp(`https?://(?:www\\.)?(?:${bare.join("|")})(?::\\d+)?`, "gi") : null;
|
|
63
|
+
const all = [...hostVariants([...hosts].map((h) => `https://${h}/`)), ...strings].sort((a, b) => b.length - a.length).map(escape);
|
|
64
|
+
other = all.length ? new RegExp(all.join("|"), "gi") : null;
|
|
65
|
+
};
|
|
66
|
+
rebuild();
|
|
67
|
+
const scrub = (text) => {
|
|
68
|
+
let t = String(text);
|
|
69
|
+
if (origin) t = t.replace(origin, "");
|
|
70
|
+
if (other) t = t.replace(other, PRIVATE_TOKEN);
|
|
71
|
+
return t;
|
|
72
|
+
};
|
|
73
|
+
scrub.addHost = (url) => {
|
|
74
|
+
const [h] = hostVariants([url]);
|
|
75
|
+
if (h && !hosts.has(h)) {
|
|
76
|
+
hosts.add(h);
|
|
77
|
+
rebuild();
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
return scrub;
|
|
81
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { randomBytes } from "node:crypto";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
|
|
6
|
+
// Where the blind first-look folders live: the system temp folder, unless that sits inside the project
|
|
7
|
+
// (then the reader could find the project from the path), in which case a folder under the home directory.
|
|
8
|
+
const FALLBACK_NAME = ".lazuli-tmp";
|
|
9
|
+
const BLIND_NAME = /^lz-[0-9a-f]{12}$/;
|
|
10
|
+
|
|
11
|
+
async function real(p) {
|
|
12
|
+
try {
|
|
13
|
+
return await fs.realpath(p);
|
|
14
|
+
} catch {
|
|
15
|
+
return path.resolve(p);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const same = (a, b) => (process.platform === "win32" ? a.toLowerCase() === b.toLowerCase() : a === b);
|
|
20
|
+
|
|
21
|
+
async function inside(root, p) {
|
|
22
|
+
const rel = path.relative(await real(root), await real(p));
|
|
23
|
+
return rel === "" || (!rel.startsWith("..") && !path.isAbsolute(rel));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export async function blindRoot(projectRoot) {
|
|
27
|
+
const tmp = os.tmpdir();
|
|
28
|
+
if (await inside(projectRoot, tmp)) {
|
|
29
|
+
const fallback = path.join(os.homedir(), FALLBACK_NAME);
|
|
30
|
+
await fs.mkdir(fallback, { recursive: true, mode: 0o700 });
|
|
31
|
+
return fallback;
|
|
32
|
+
}
|
|
33
|
+
return tmp;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// A new blind folder, lz-<12 hex>, under blindRoot: private to its owner, nothing of the project in its path.
|
|
37
|
+
export async function makeBlindFolder(projectRoot) {
|
|
38
|
+
const token = randomBytes(6).toString("hex");
|
|
39
|
+
const dir = path.join(await blindRoot(projectRoot), `lz-${token}`);
|
|
40
|
+
await fs.mkdir(dir, { mode: 0o700 });
|
|
41
|
+
return { token, dir };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Deletes the blind folder a capture.json names, and only that kind of folder: a direct child of the temp
|
|
45
|
+
// folder (or the fallback) called lz-<12 hex> that matches the token capture.json stored.
|
|
46
|
+
export async function removeBlindFolder(blind) {
|
|
47
|
+
if (typeof blind?.dir !== "string" || typeof blind?.token !== "string" || !path.isAbsolute(blind.dir)) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
const dir = path.resolve(blind.dir);
|
|
51
|
+
const name = path.basename(dir);
|
|
52
|
+
if (!BLIND_NAME.test(name) || name !== `lz-${blind.token}`) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
try {
|
|
56
|
+
const st = await fs.lstat(dir);
|
|
57
|
+
if (st.isSymbolicLink() || !st.isDirectory()) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
} catch {
|
|
61
|
+
return false;
|
|
62
|
+
}
|
|
63
|
+
const parent = await real(path.dirname(dir));
|
|
64
|
+
const roots = [await real(os.tmpdir()), await real(path.join(os.homedir(), FALLBACK_NAME))];
|
|
65
|
+
if (!roots.some((r) => same(r, parent))) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
await fs.rm(dir, { recursive: true, force: true });
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { readFileSync, statSync } from "node:fs";
|
|
2
|
+
import fs from "node:fs/promises";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { withLock, writeFileAtomic } from "./records.mjs";
|
|
5
|
+
|
|
6
|
+
const EMPTY = () => ({ lastEditAt: null, sessions: {} });
|
|
7
|
+
const isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
8
|
+
const isTime = (v) => typeof v === "string" && !Number.isNaN(Date.parse(v));
|
|
9
|
+
|
|
10
|
+
const time = (iso) => Date.parse(iso);
|
|
11
|
+
|
|
12
|
+
const TAG = /<(?:link|script|img|source|video|audio)\b((?:"[^"]*"|'[^']*'|[^>"'])*)>/gi;
|
|
13
|
+
// One attribute at a time, so a quoted value (an alt text that contains src=) is read as one value.
|
|
14
|
+
const ATTR = /([^\s"'=<>\/]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>]+)))?/g;
|
|
15
|
+
const SCHEME = /^[a-z][a-z0-9+.-]*:/i;
|
|
16
|
+
|
|
17
|
+
// A reference counts only when, once decoded, it is a plain relative path: no scheme or drive letter, no leading
|
|
18
|
+
// slash or backslash (root-relative, UNC), nothing absolute.
|
|
19
|
+
function localRef(raw) {
|
|
20
|
+
let ref = raw.trim().replace(/[?#].*$/, "");
|
|
21
|
+
try {
|
|
22
|
+
ref = decodeURIComponent(ref);
|
|
23
|
+
} catch {
|
|
24
|
+
// keep the raw reference
|
|
25
|
+
}
|
|
26
|
+
if (ref === "" || ref.includes("\0") || SCHEME.test(ref) || /^[\\/]/.test(ref) || path.posix.isAbsolute(ref) || path.win32.isAbsolute(ref)) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
return ref;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Local files an HTML page references directly (link href, script src, img src and the like), resolved next to
|
|
33
|
+
// the page. Remote, absolute and root-relative references are skipped, and so is any file outside root.
|
|
34
|
+
// It does not follow @import, srcset or files those load.
|
|
35
|
+
export function linkedFiles(htmlFile, root = path.dirname(htmlFile)) {
|
|
36
|
+
let html;
|
|
37
|
+
try {
|
|
38
|
+
html = readFileSync(htmlFile, "utf8");
|
|
39
|
+
} catch {
|
|
40
|
+
return [];
|
|
41
|
+
}
|
|
42
|
+
const base = path.resolve(root);
|
|
43
|
+
const found = new Set();
|
|
44
|
+
for (const tag of html.matchAll(TAG)) {
|
|
45
|
+
for (const attr of tag[1].matchAll(ATTR)) {
|
|
46
|
+
if (!["href", "src"].includes(attr[1].toLowerCase())) {
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
const ref = localRef(attr[2] ?? attr[3] ?? attr[4] ?? "");
|
|
50
|
+
if (ref === null) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const resolved = path.resolve(path.dirname(htmlFile), ref);
|
|
54
|
+
const rel = path.relative(base, resolved);
|
|
55
|
+
if (rel === "" || rel === ".." || rel.startsWith("..\\") || rel.startsWith("../") || path.isAbsolute(rel)) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
found.add(resolved);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return [...found];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// True when the page changed after the capture: its file or a local file it links was written later, or the hook
|
|
65
|
+
// recorded an edit later (the latest of the top-level time and every session). A file the page names that does not
|
|
66
|
+
// exist or lies outside the project is ignored; an unreadable page file, or an edits.json that could not be read, counts as changed.
|
|
67
|
+
export function isStale(manifest, edits, root = manifest.targetFile ? path.dirname(manifest.targetFile) : process.cwd()) {
|
|
68
|
+
const capturedAt = time(manifest.capturedAt);
|
|
69
|
+
if (Number.isNaN(capturedAt) || edits?.corrupt) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
if (manifest.targetFile) {
|
|
73
|
+
try {
|
|
74
|
+
if (statSync(manifest.targetFile).mtimeMs > capturedAt) {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
} catch {
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
for (const f of linkedFiles(manifest.targetFile, root)) {
|
|
81
|
+
try {
|
|
82
|
+
if (statSync(f).mtimeMs > capturedAt) {
|
|
83
|
+
return true;
|
|
84
|
+
}
|
|
85
|
+
} catch {
|
|
86
|
+
// a reference to a file that is not there changes nothing we can see
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const times = [edits?.lastEditAt, ...Object.values(edits?.sessions ?? {}).map((s) => s?.lastEditAt)].filter((t) => typeof t === "string").map(time);
|
|
91
|
+
return times.some((t) => t > capturedAt);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function editsFile(cwd) {
|
|
95
|
+
return path.join(path.resolve(cwd), ".lazuli", "edits.json");
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function parseEdits(text) {
|
|
99
|
+
let parsed;
|
|
100
|
+
try {
|
|
101
|
+
parsed = JSON.parse(text.replace(/^\uFEFF/, ""));
|
|
102
|
+
} catch {
|
|
103
|
+
return { ...EMPTY(), corrupt: true };
|
|
104
|
+
}
|
|
105
|
+
if (!isObject(parsed)) {
|
|
106
|
+
return { ...EMPTY(), corrupt: true };
|
|
107
|
+
}
|
|
108
|
+
const sessions = {};
|
|
109
|
+
if (isObject(parsed.sessions)) {
|
|
110
|
+
for (const [id, s] of Object.entries(parsed.sessions)) {
|
|
111
|
+
if (isObject(s) && isTime(s.lastEditAt)) {
|
|
112
|
+
sessions[id] = { files: Array.isArray(s.files) ? s.files.filter((f) => typeof f === "string") : [], lastEditAt: s.lastEditAt };
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return { lastEditAt: isTime(parsed.lastEditAt) ? parsed.lastEditAt : null, sessions };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// .lazuli/edits.json, written by the post-edit hook. A missing file reads as no edits; a file that cannot be read
|
|
120
|
+
// or is not valid is reported with corrupt: true.
|
|
121
|
+
export async function readEdits(cwd = process.cwd()) {
|
|
122
|
+
let text;
|
|
123
|
+
try {
|
|
124
|
+
text = await fs.readFile(editsFile(cwd), "utf8");
|
|
125
|
+
} catch (err) {
|
|
126
|
+
return err?.code === "ENOENT" ? EMPTY() : { ...EMPTY(), corrupt: true };
|
|
127
|
+
}
|
|
128
|
+
return parseEdits(text);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export async function recordEdit({ cwd = process.cwd(), sessionId, file }) {
|
|
132
|
+
const target = editsFile(cwd);
|
|
133
|
+
await fs.mkdir(path.dirname(target), { recursive: true });
|
|
134
|
+
await withLock(target, async () => {
|
|
135
|
+
let text = null;
|
|
136
|
+
try {
|
|
137
|
+
text = await fs.readFile(target, "utf8");
|
|
138
|
+
} catch (err) {
|
|
139
|
+
if (err?.code !== "ENOENT") {
|
|
140
|
+
// A file we cannot read may hold valid sessions; never replace it.
|
|
141
|
+
throw new Error(`Cannot read ${target} (${err?.code ?? err?.message}); it was left as it was.`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
// Text that is not valid JSON holds nothing to keep, so it is replaced.
|
|
145
|
+
const { corrupt, ...edits } = text === null ? EMPTY() : parseEdits(text);
|
|
146
|
+
const at = new Date().toISOString();
|
|
147
|
+
const id = sessionId === undefined || sessionId === null || String(sessionId) === "__proto__" ? "unknown" : String(sessionId);
|
|
148
|
+
const own = Object.hasOwn(edits.sessions, id) ? edits.sessions[id] : { files: [], lastEditAt: at };
|
|
149
|
+
const files = typeof file === "string" && file !== "" && !own.files.includes(file) ? [...own.files, file] : own.files;
|
|
150
|
+
edits.sessions[id] = { files, lastEditAt: at };
|
|
151
|
+
edits.lastEditAt = at;
|
|
152
|
+
await writeFileAtomic(target, JSON.stringify(edits, null, 2));
|
|
153
|
+
});
|
|
154
|
+
}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { toUrl } from "../browser.mjs";
|
|
3
|
+
import { isStale, readEdits } from "./edits.mjs";
|
|
4
|
+
import { isOptionsGoal } from "./lazuli-md.mjs";
|
|
5
|
+
import { matchGoals, targetKey } from "./match.mjs";
|
|
6
|
+
import { findCapture, readRecords } from "./records.mjs";
|
|
7
|
+
|
|
8
|
+
export { isStale };
|
|
9
|
+
|
|
10
|
+
const norm = (s) => String(s ?? "").trim().toLowerCase();
|
|
11
|
+
|
|
12
|
+
const isUrlTarget = (target, cwd) => !toUrl(target, cwd).startsWith("file:");
|
|
13
|
+
|
|
14
|
+
const LEVELS = ["met", "partly", "missed"];
|
|
15
|
+
|
|
16
|
+
// null when a dimension is absent or not one of the three levels: such a record is never read as met.
|
|
17
|
+
function levelOf(judged) {
|
|
18
|
+
const levels = [judged.understand, judged.feel, judged.do];
|
|
19
|
+
if (!levels.every((l) => LEVELS.includes(l))) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
if (levels.includes("missed")) {
|
|
23
|
+
return "missed";
|
|
24
|
+
}
|
|
25
|
+
return levels.includes("partly") ? "partly" : "met";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// What the review saw of the goal and the idea must still be what LAZULI.md says. A record without that text is never fresh.
|
|
29
|
+
function textChanged(data, judged, goal, md) {
|
|
30
|
+
const same = (a, b) => String(a ?? "").trim() === String(b ?? "").trim();
|
|
31
|
+
const t = judged.goalText;
|
|
32
|
+
if (!t || !["understand", "feel", "do"].every((k) => same(t[k], goal[k]))) {
|
|
33
|
+
return `Goal ${goal.piece} changed after it was reviewed.`;
|
|
34
|
+
}
|
|
35
|
+
if (typeof data.ideaText !== "string" || !same(data.ideaText, md?.idea)) {
|
|
36
|
+
return "The idea changed after the review.";
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// The latest review of a page and the capture it was made on. Read once per page.
|
|
42
|
+
async function reviewOf(cwd, target) {
|
|
43
|
+
const records = await readRecords(cwd, target);
|
|
44
|
+
const review = [...records].reverse().find((r) => r.kind === "review") ?? null;
|
|
45
|
+
const manifest = review ? await findCapture(cwd, review.captureId) : null;
|
|
46
|
+
return { review, manifest };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// What the recorded checks say about the goals. It never measures or judges: it only reads records and edit times.
|
|
50
|
+
export async function gateStatus({ cwd = process.cwd(), md, target }) {
|
|
51
|
+
const root = path.resolve(cwd);
|
|
52
|
+
const mode = md?.mode ?? "director";
|
|
53
|
+
const wanted = target ? matchGoals(md, target, root) : (md?.goals ?? []);
|
|
54
|
+
const edits = await readEdits(root);
|
|
55
|
+
const pages = new Map();
|
|
56
|
+
const goals = [];
|
|
57
|
+
const items = [];
|
|
58
|
+
const notes = [];
|
|
59
|
+
let urlChecked = false;
|
|
60
|
+
let fileChecked = false;
|
|
61
|
+
let anyReview = false;
|
|
62
|
+
|
|
63
|
+
for (const g of wanted) {
|
|
64
|
+
if (!g.target) {
|
|
65
|
+
goals.push({ piece: g.piece, target: null, status: "no-target", verdict: null, reviewedAt: null, reviewer: null });
|
|
66
|
+
notes.push(`"${g.piece}" has no Target, so Lazuli cannot check it; check it by hand.`);
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
// An options goal covers option files; an option review never counts for the page.
|
|
70
|
+
if (isOptionsGoal(g)) {
|
|
71
|
+
goals.push({ piece: g.piece, target: g.target, status: "options", verdict: null, reviewedAt: null, reviewer: null });
|
|
72
|
+
notes.push(`"${g.piece}" covers option files (${g.target}); options are not gated. Give the chosen page its own goal.`);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const key = targetKey(g.target, root);
|
|
76
|
+
if (!pages.has(key)) {
|
|
77
|
+
pages.set(key, await reviewOf(root, g.target));
|
|
78
|
+
}
|
|
79
|
+
const { review, manifest } = pages.get(key);
|
|
80
|
+
const base = { piece: g.piece, target: g.target, verdict: review?.data?.verdict ?? null, reviewedAt: review?.at ?? null, reviewer: review?.data?.reviewer ?? null };
|
|
81
|
+
if (!review) {
|
|
82
|
+
goals.push({ ...base, status: "not-checked" });
|
|
83
|
+
items.push(`${g.piece}: no recorded check. Run capture, the first look and review-design.`);
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
anyReview = true;
|
|
87
|
+
if (isUrlTarget(g.target, root)) {
|
|
88
|
+
urlChecked = true;
|
|
89
|
+
} else {
|
|
90
|
+
fileChecked = true;
|
|
91
|
+
}
|
|
92
|
+
if (review.data?.verdict === "pending") {
|
|
93
|
+
const reason = review.data.reason ?? "no reason recorded";
|
|
94
|
+
goals.push({ ...base, status: "pending", reason });
|
|
95
|
+
items.push(`${g.piece}: review pending (${reason}). Run the first look and the review, then record them, before delivery.`);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
if (!manifest) {
|
|
99
|
+
goals.push({ ...base, status: "stale" });
|
|
100
|
+
items.push(`${g.piece}: the capture of the last review is missing. Capture and review again.`);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
const page = pages.get(key);
|
|
104
|
+
// Computed once per page: it stats the page file and every file it links.
|
|
105
|
+
page.stale ??= isStale(manifest, edits, root);
|
|
106
|
+
if (page.stale) {
|
|
107
|
+
goals.push({ ...base, status: "stale" });
|
|
108
|
+
items.push(`${g.piece}: the review is older than the last edit. Capture and review again.`);
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
const judged = (review.data?.goals ?? []).find((j) => norm(j.piece) === norm(g.piece));
|
|
112
|
+
if (!judged) {
|
|
113
|
+
goals.push({ ...base, status: "not-checked" });
|
|
114
|
+
items.push(`${g.piece}: the last review did not judge this goal. Capture and review again.`);
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const status = levelOf(judged);
|
|
118
|
+
if (status === null) {
|
|
119
|
+
goals.push({ ...base, status: "not-checked" });
|
|
120
|
+
items.push(`${g.piece}: the recorded review has a missing or unknown level for this goal. Capture and review again.`);
|
|
121
|
+
continue;
|
|
122
|
+
}
|
|
123
|
+
const changed = textChanged(review.data, judged, g, md);
|
|
124
|
+
if (changed) {
|
|
125
|
+
goals.push({ ...base, status: "stale" });
|
|
126
|
+
if (!items.includes(changed)) {
|
|
127
|
+
items.push(changed);
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
goals.push({ ...base, status });
|
|
132
|
+
if (status !== "met") {
|
|
133
|
+
items.push(`${g.piece}: the reviewer judged this goal ${status === "partly" ? "partly met" : "missed"}. Make the fixes it lists, then capture and review again.`);
|
|
134
|
+
} else if (base.verdict !== "approve") {
|
|
135
|
+
items.push(`${g.piece}: the goals are met but the review verdict is ${base.verdict}. Make the fixes it lists, then capture and review again.`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const isGated = (g) => g.target && g.status !== "options";
|
|
140
|
+
const gated = new Set(goals.filter(isGated).map((g) => norm(g.piece)));
|
|
141
|
+
const tryingBreaks = [];
|
|
142
|
+
for (const b of md?.breaks ?? []) {
|
|
143
|
+
if (b.status === "trying" && gated.has(norm(b.piece)) && !tryingBreaks.some((t) => norm(t.rule) === norm(b.rule) && norm(t.piece) === norm(b.piece))) {
|
|
144
|
+
tryingBreaks.push({ rule: b.rule, piece: b.piece });
|
|
145
|
+
items.push(`Break ${b.rule} on ${b.piece} is still trying. Keep it or revert it.`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (urlChecked) {
|
|
149
|
+
notes.push("A URL target is checked for freshness only from edits the hook recorded; a change made outside the agent is not seen.");
|
|
150
|
+
}
|
|
151
|
+
const gatedGoals = goals.filter(isGated);
|
|
152
|
+
// With only options goals, their note already says why nothing is gated.
|
|
153
|
+
if (gatedGoals.length === 0 && !goals.some((g) => g.status === "options")) {
|
|
154
|
+
if (target && (md?.goals ?? []).length > 0) {
|
|
155
|
+
items.push(`No goal in LAZULI.md has this Target: ${target}`);
|
|
156
|
+
} else {
|
|
157
|
+
notes.push("No goal has a Target, so nothing can be gated.");
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
if (edits.corrupt && anyReview) {
|
|
161
|
+
notes.push(".lazuli/edits.json could not be read, so every review counts as stale until it is fixed or removed.");
|
|
162
|
+
}
|
|
163
|
+
if (fileChecked) {
|
|
164
|
+
notes.push("For a file target, freshness covers the page file, the local stylesheets, scripts and images it references directly, and the edits the hook recorded. It does not follow @import, srcset or files those load.");
|
|
165
|
+
}
|
|
166
|
+
const passed = gatedGoals.length > 0 && gatedGoals.every((g) => g.status === "met" && g.verdict === "approve") && tryingBreaks.length === 0;
|
|
167
|
+
return { mode, passed, goals, tryingBreaks, items, notes };
|
|
168
|
+
}
|