@uselazuli/cli 1.0.1 → 1.0.3
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 +39 -0
- package/README.md +5 -5
- package/bin/lazuli.mjs +69 -19
- package/package.json +1 -1
- package/rules/content/HYPOTHESES.md +3 -2
- package/rules/content/review.yaml +33 -2
- package/rules/graphic/HYPOTHESES.md +1 -0
- package/rules/graphic/review.yaml +29 -0
- package/rules/motion/HYPOTHESES.md +3 -3
- package/rules/motion/review.yaml +4 -4
- package/rules/typography/HYPOTHESES.md +1 -1
- package/rules/typography/review.yaml +2 -2
- package/rules/ui/HYPOTHESES.md +3 -3
- package/rules/ui/compose.yaml +28 -1
- package/rules/ui/review.yaml +4 -3
- package/skills/lazuli/SKILL.md +9 -6
- package/skills/lazuli/procedures/review-design.md +1 -0
- package/skills/lazuli/procedures/show-options.md +2 -1
- package/skills/lazuli-content-interface-writing/SKILL.md +1 -1
- package/skills/lazuli-content-voice/SKILL.md +1 -0
- package/skills/lazuli-graphic-identity/SKILL.md +3 -1
- package/skills/lazuli-ui-composition/SKILL.md +4 -4
- package/skills/lazuli-ui-layout-review/SKILL.md +2 -2
- package/src/browser.mjs +2 -1
- package/src/commands/capture.mjs +1 -1
- package/src/commands/catalog.mjs +1 -1
- package/src/commands/check-design.mjs +62 -17
- package/src/commands/compare-designs.mjs +73 -6
- package/src/commands/draft-memo.mjs +7 -3
- package/src/commands/hooks.mjs +7 -5
- package/src/commands/record-log.mjs +87 -25
- package/src/commands/render-options.mjs +81 -15
- package/src/measure/a11y.mjs +8 -0
- package/src/measure/cases.mjs +24 -5
- package/src/measure/color.mjs +7 -0
- package/src/measure/in-page/a11y.js +84 -0
- package/src/measure/in-page/color.js +3 -1
- package/src/measure/in-page/composition.js +10 -3
- package/src/measure/in-page/extreme.js +42 -9
- package/src/measure/in-page/motion-probe.js +2 -0
- package/src/measure/in-page/type.js +3 -0
- package/src/measure/layout.mjs +21 -3
- package/src/measure/motion.mjs +2 -1
- package/src/measure/registry.mjs +3 -2
- package/src/measure/rhythm.mjs +8 -0
- package/src/measure/timeline.mjs +5 -5
- package/src/project/gate.mjs +12 -3
- package/src/project/lazuli-md.mjs +35 -5
- package/src/project/log.mjs +18 -12
- package/src/project/match.mjs +102 -5
- package/src/report/evaluators/a11y.mjs +24 -0
- package/src/report/evaluators/color.mjs +77 -1
- package/src/report/evaluators/extreme.mjs +45 -9
- package/src/report/evaluators/layout.mjs +10 -1
- package/src/report/evaluators/motion.mjs +10 -3
- package/src/report/evaluators/rhythm.mjs +1 -1
- package/src/report/evaluators/type.mjs +6 -3
- package/src/report/format.mjs +4 -4
- package/src/rules/load.mjs +18 -0
- package/src/rules/schema.mjs +8 -0
- package/templates/LAZULI.md +3 -1
|
@@ -1,16 +1,37 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { openBrowser, openTarget, resolveTarget } from "../browser.mjs";
|
|
3
|
+
import { VIEWPORT_HEIGHT, openBrowser, openTarget, resolveTarget } from "../browser.mjs";
|
|
4
|
+
import { FULL_PAGE_CAP_PX } from "./capture.mjs";
|
|
4
5
|
import { MEASURERS, measurersFor } from "../measure/registry.mjs";
|
|
5
6
|
import { KIT_RULES_DIR, loadKit } from "../rules/load.mjs";
|
|
6
7
|
import { evaluate } from "../report/evaluate.mjs";
|
|
8
|
+
import { formatReport } from "../report/format.mjs";
|
|
7
9
|
import { noteGuessChanges } from "../report/evaluators/weight.mjs";
|
|
8
|
-
import { emptyBrand, isAssetGoal, readLazuliMd } from "../project/lazuli-md.mjs";
|
|
10
|
+
import { emptyBrand, isAssetGoal, isOptionsGoal, readLazuliMd } from "../project/lazuli-md.mjs";
|
|
9
11
|
import { AssetInputError, assetDir, assetOfType, loadAssetBytes, resolveAsset } from "../measure/asset.mjs";
|
|
10
|
-
import { applyBreaks, matchGoals, sameTarget } from "../project/match.mjs";
|
|
12
|
+
import { applyBreaks, applyDeclarations, matchGoals, sameTarget } from "../project/match.mjs";
|
|
11
13
|
import { gateStatus } from "../project/gate.mjs";
|
|
12
14
|
import { makeBlindFolder, removeBlindFolder } from "../project/blind.mjs";
|
|
13
15
|
|
|
16
|
+
// Technical limits of the viewport height in px, not rules: below 100 px no page lays out as a screen, and
|
|
17
|
+
// above the full-page capture cap (FULL_PAGE_CAP_PX) a first view would be taller than anything the kit captures.
|
|
18
|
+
// capture.mjs imports this file, so the cap is read when called, never while this module loads.
|
|
19
|
+
export const MIN_HEIGHT_PX = 100;
|
|
20
|
+
export const maxHeightPx = () => FULL_PAGE_CAP_PX;
|
|
21
|
+
|
|
22
|
+
export class HeightInputError extends Error {
|
|
23
|
+
constructor() {
|
|
24
|
+
super(`--height needs a whole number of px from ${MIN_HEIGHT_PX} to ${maxHeightPx()}.`);
|
|
25
|
+
this.name = "HeightInputError";
|
|
26
|
+
this.code = "HEIGHT_INPUT";
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// A height is a whole number from MIN_HEIGHT_PX to maxHeightPx(); anything else is refused, never turned into the default.
|
|
31
|
+
export function checkHeight(height) {
|
|
32
|
+
if (height !== undefined && !(Number.isInteger(height) && height >= MIN_HEIGHT_PX && height <= maxHeightPx())) throw new HeightInputError();
|
|
33
|
+
}
|
|
34
|
+
|
|
14
35
|
export class UnknownAreaError extends Error {
|
|
15
36
|
constructor(name, known) {
|
|
16
37
|
super(`Unknown area ${name}. Known areas: ${known.join(", ")}.`);
|
|
@@ -60,14 +81,14 @@ export function areaCoverage(areas, rules, measurers, { failed = new Set(), site
|
|
|
60
81
|
|
|
61
82
|
// Opens every screen at one width and runs the site measurers on them. A screen that cannot be opened
|
|
62
83
|
// stops the site measurers at that width with an error naming it. Every context closes in finally.
|
|
63
|
-
async function measureSite({ browser, screens, width, cwd, siteMeasurers, rules, goals }) {
|
|
64
|
-
const m = { width, errors: {} };
|
|
84
|
+
async function measureSite({ browser, screens, width, height, cwd, siteMeasurers, rules, goals }) {
|
|
85
|
+
const m = { width, height, errors: {} };
|
|
65
86
|
const pages = [];
|
|
66
87
|
try {
|
|
67
88
|
let failure = null;
|
|
68
89
|
for (const target of screens) {
|
|
69
90
|
try {
|
|
70
|
-
pages.push({ target, page: await openTarget(browser, target, width, { cwd }) });
|
|
91
|
+
pages.push({ target, page: await openTarget(browser, target, width, { cwd, height }) });
|
|
71
92
|
} catch (err) {
|
|
72
93
|
failure = `Screen ${target} could not be opened: ${String(err?.message ?? err).split("\n")[0]}`;
|
|
73
94
|
break;
|
|
@@ -246,6 +267,8 @@ export async function checkDesign({
|
|
|
246
267
|
screens: more = [],
|
|
247
268
|
site = false,
|
|
248
269
|
widths = [1440, 768, 390],
|
|
270
|
+
// The viewport height of every page this run opens, in px.
|
|
271
|
+
height = VIEWPORT_HEIGHT,
|
|
249
272
|
out = ".lazuli/report.json",
|
|
250
273
|
// A second file the report is also written to (CLI --out); the report at `out` is always written.
|
|
251
274
|
copyTo,
|
|
@@ -259,6 +282,7 @@ export async function checkDesign({
|
|
|
259
282
|
// Review sheets (the chart sheet) are written unless the post-edit hook turned them off (LAZULI_SHEETS=off).
|
|
260
283
|
sheets = process.env.LAZULI_SHEETS !== "off",
|
|
261
284
|
}) {
|
|
285
|
+
checkHeight(height);
|
|
262
286
|
if (asset !== undefined) {
|
|
263
287
|
return checkAsset({ asset, sizes, target, more, out, copyTo, cwd, givenBrowser, registered, allMeasurers, wanted });
|
|
264
288
|
}
|
|
@@ -282,8 +306,8 @@ export async function checkDesign({
|
|
|
282
306
|
const md = await readLazuliMd(cwd);
|
|
283
307
|
const goals = matchGoals(md, target, cwd);
|
|
284
308
|
// The distinct screens, in order: the target, the other targets given, then with --site the Target of
|
|
285
|
-
// every goal that is a page (a derived piece or a
|
|
286
|
-
const fromGoals = site ? (md?.goals ?? []).filter((g) => g.target && !isAssetGoal(g)) : [];
|
|
309
|
+
// every goal that is a page (a derived piece, a symbol or a folder of options is not a screen). The same page written two ways counts once.
|
|
310
|
+
const fromGoals = site ? (md?.goals ?? []).filter((g) => g.target && !isAssetGoal(g) && !isOptionsGoal(g)) : [];
|
|
287
311
|
const candidates = [...more, ...fromGoals.map((g) => g.target)];
|
|
288
312
|
const screens = [target];
|
|
289
313
|
for (const s of candidates) if (!screens.some((x) => sameTarget(x, s, cwd))) screens.push(s);
|
|
@@ -317,6 +341,9 @@ export async function checkDesign({
|
|
|
317
341
|
width,
|
|
318
342
|
target,
|
|
319
343
|
goals,
|
|
344
|
+
// A file an options goal covers is read as an option, by its data-block marks, as render-options reads it.
|
|
345
|
+
options: goals.some(isOptionsGoal),
|
|
346
|
+
brand: md?.brand ?? emptyBrand(),
|
|
320
347
|
once,
|
|
321
348
|
cwd,
|
|
322
349
|
sheets,
|
|
@@ -324,14 +351,14 @@ export async function checkDesign({
|
|
|
324
351
|
// bare and prepare: a raw open with an init script and a route (the motion recorder); noScript and
|
|
325
352
|
// navigate: a script-free open whose document the caller serves (the extreme case pages).
|
|
326
353
|
openPage: async (opts = {}) => {
|
|
327
|
-
const p = await openTarget(browser, target, opts.width ?? width, { still: opts.still, bare: opts.bare, prepare: opts.prepare, noScript: opts.noScript, navigate: opts.navigate, cwd });
|
|
354
|
+
const p = await openTarget(browser, target, opts.width ?? width, { still: opts.still, bare: opts.bare, prepare: opts.prepare, noScript: opts.noScript, navigate: opts.navigate, cwd, height });
|
|
328
355
|
opened.push(p.context());
|
|
329
356
|
return p;
|
|
330
357
|
},
|
|
331
358
|
};
|
|
332
|
-
const page = await openTarget(browser, target, width, { cwd });
|
|
359
|
+
const page = await openTarget(browser, target, width, { cwd, height });
|
|
333
360
|
try {
|
|
334
|
-
const m = { width, errors: {} };
|
|
361
|
+
const m = { width, height, errors: {} };
|
|
335
362
|
for (const measurer of pageMeasurers) {
|
|
336
363
|
try {
|
|
337
364
|
// ctx.rules: the selected rules whose measure is one of this measurer's ids.
|
|
@@ -350,19 +377,19 @@ export async function checkDesign({
|
|
|
350
377
|
// Site measurers compare the screens after the page phase, once per width.
|
|
351
378
|
if (siteMeasurers.length > 0 && screens.length >= 2) {
|
|
352
379
|
for (const width of widths) {
|
|
353
|
-
siteMeasures.push(await measureSite({ browser, screens, width, cwd, siteMeasurers, rules, goals }));
|
|
380
|
+
siteMeasures.push(await measureSite({ browser, screens, width, height, cwd, siteMeasurers, rules, goals }));
|
|
354
381
|
}
|
|
355
382
|
}
|
|
356
383
|
} finally {
|
|
357
384
|
for (const c of opened) await c.close().catch(() => {});
|
|
358
385
|
if (!givenBrowser) await browser.close();
|
|
359
386
|
}
|
|
360
|
-
return summarize({ kit, chosen, rules, measurers, registered, measures, siteMeasures, siteMeasurers, screens, siteShort, siteSkipped, md, goals, target, cwd, out, copyTo });
|
|
387
|
+
return summarize({ kit, chosen, rules, measurers, registered, measures, siteMeasures, siteMeasurers, screens, siteShort, siteSkipped, md, goals, target, cwd, out, copyTo, viewportHeight: height });
|
|
361
388
|
}
|
|
362
389
|
|
|
363
390
|
// Coverage, findings, breaks and recorded effects of a run, written to the report file. kind and asset are set
|
|
364
391
|
// on an asset run.
|
|
365
|
-
async function summarize({ kit, chosen, rules, measurers, registered, measures, siteMeasures, siteMeasurers, screens, siteShort, siteSkipped, md, goals, target, cwd, out, copyTo, kind = null, asset }) {
|
|
392
|
+
async function summarize({ kit, chosen, rules, measurers, registered, measures, siteMeasures, siteMeasurers, screens, siteShort, siteSkipped, md, goals, target, cwd, out, copyTo, kind = null, asset, viewportHeight }) {
|
|
366
393
|
const failedNames = new Set([...measures, ...siteMeasures].flatMap((m) => Object.keys(m.errors)));
|
|
367
394
|
const areas = areaCoverage(chosen, rules, measurers, { failed: failedNames, siteSkipped: siteShort, kind, all: registered });
|
|
368
395
|
// The site measurers that did not run for want of a second screen, named in the report: every one when more
|
|
@@ -380,10 +407,24 @@ async function summarize({ kit, chosen, rules, measurers, registered, measures,
|
|
|
380
407
|
// Every kit and project rule id counts as known, not only the selected areas, so --area never makes a break look misspelled.
|
|
381
408
|
// Site findings carry the screens they compare. A guessed main action that differs between widths says so.
|
|
382
409
|
const siteFindings = evaluate(rules, siteMeasures, siteMeasurers).map((f) => ({ ...f, screens: [...screens] }));
|
|
383
|
-
const
|
|
410
|
+
const broken = applyBreaks([...noteGuessChanges(evaluate(rules, measures, measurers), measures), ...siteFindings], md?.breaks ?? [], goals, kit.rules, new Set(kit.rules.map((r) => r.id)), target, cwd);
|
|
411
|
+
const { applied, unapplied: allUnapplied } = broken;
|
|
412
|
+
// A declared move (UC9 for UR3) changes a hint only where the finding measured the move.
|
|
413
|
+
const { findings, applied: declarations, notHeld } = applyDeclarations(broken.findings, md, goals, kit.rules, target, cwd);
|
|
384
414
|
// With --area, a break on a rule of an area that was not selected has no findings here, which is not a fault of the break.
|
|
385
415
|
const selected = new Set(rules.map((r) => r.id.toLowerCase()));
|
|
386
|
-
|
|
416
|
+
// A break on a move that declared a finding did its work, so it is not listed as unapplied.
|
|
417
|
+
const declaredBy = (u) => declarations.some((d) => d.by === "break" && d.move.toLowerCase() === String(u.rule).trim().toLowerCase() && d.piece === u.piece);
|
|
418
|
+
// A break on a move that a finding read here for its piece, where the move did not hold, was measured: it says so,
|
|
419
|
+
// and says the move is not on the page when every such reading was absent.
|
|
420
|
+
const readReason = (u) => {
|
|
421
|
+
const reads = notHeld.filter((n) => n.move.toLowerCase() === String(u.rule).trim().toLowerCase() && n.piece.trim().toLowerCase() === String(u.piece).trim().toLowerCase());
|
|
422
|
+
if (reads.length === 0) return null;
|
|
423
|
+
return reads.every((n) => n.absent) ? "the move was read and is not on this page" : "the move was read and did not hold on this page";
|
|
424
|
+
};
|
|
425
|
+
const unapplied = allUnapplied
|
|
426
|
+
.filter((u) => (!(u.reason.startsWith("no fail or hint") || u.reason === "not measured by check-design") || selected.has(String(u.rule).trim().toLowerCase())) && !declaredBy(u))
|
|
427
|
+
.map((u) => (u.reason === "not measured by check-design" && readReason(u) ? { ...u, reason: readReason(u) } : u));
|
|
387
428
|
// A records file that cannot be read never stops the measuring: the goals just show no recorded check.
|
|
388
429
|
let effects = [];
|
|
389
430
|
const problems = [...(md?.problems ?? [])];
|
|
@@ -397,6 +438,7 @@ async function summarize({ kit, chosen, rules, measurers, registered, measures,
|
|
|
397
438
|
const result = {
|
|
398
439
|
target,
|
|
399
440
|
...(asset ? { asset } : {}),
|
|
441
|
+
...(viewportHeight ? { viewportHeight } : {}),
|
|
400
442
|
screens,
|
|
401
443
|
areas,
|
|
402
444
|
findings,
|
|
@@ -411,6 +453,7 @@ async function summarize({ kit, chosen, rules, measurers, registered, measures,
|
|
|
411
453
|
effects,
|
|
412
454
|
unmatchedGoals: (md?.goals.length ?? 0) - goals.length,
|
|
413
455
|
breaks: applied,
|
|
456
|
+
declarations,
|
|
414
457
|
unappliedBreaks: unapplied,
|
|
415
458
|
problems,
|
|
416
459
|
projectProblems: kit.projectProblems,
|
|
@@ -422,7 +465,9 @@ async function summarize({ kit, chosen, rules, measurers, registered, measures,
|
|
|
422
465
|
await fs.writeFile(outFile, JSON.stringify(result, null, 2));
|
|
423
466
|
if (copyFile) {
|
|
424
467
|
await fs.mkdir(path.dirname(copyFile), { recursive: true });
|
|
425
|
-
|
|
468
|
+
// A .txt name (any case) gets the text report the CLI prints; any other name gets the JSON.
|
|
469
|
+
const asText = path.extname(copyFile).toLowerCase() === ".txt";
|
|
470
|
+
await fs.writeFile(copyFile, asText ? formatReport(result) + "\n" : JSON.stringify(result, null, 2));
|
|
426
471
|
}
|
|
427
472
|
return result;
|
|
428
473
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
|
+
import { existsSync, statSync } from "node:fs";
|
|
2
3
|
import path from "node:path";
|
|
3
4
|
import { openBrowser, openTarget, resolveTarget } from "../browser.mjs";
|
|
5
|
+
import { checkHeight } from "./check-design.mjs";
|
|
4
6
|
import { measureLayout } from "../measure/layout.mjs";
|
|
5
7
|
import { measureRhythm } from "../measure/rhythm.mjs";
|
|
6
8
|
import { distance, signatureOf } from "../measure/signature.mjs";
|
|
@@ -9,9 +11,11 @@ import { sameTarget } from "../project/match.mjs";
|
|
|
9
11
|
// Listing limit, not a rule: how many of the most different components the text names per width.
|
|
10
12
|
const TOP_PARTS = 3;
|
|
11
13
|
|
|
12
|
-
export const H1_LINE = 'This is hypothesis H1 (ui): it is not yet validated that this distance tracks what people call "looks different".';
|
|
14
|
+
export const H1_LINE = 'This is hypothesis H1 (ui): it is not yet validated that this structure distance tracks what people call "looks different".';
|
|
13
15
|
// Carried by the text output, --json and compare.json, so the number never travels without it.
|
|
14
|
-
export const COMPARE_NOTE = 'Hypothesis H1 (ui): a measurement, not a verdict. No cutoff says what distance is "different enough".';
|
|
16
|
+
export const COMPARE_NOTE = 'Hypothesis H1 (ui): a measurement, not a verdict. No cutoff says what structure distance is "different enough".';
|
|
17
|
+
// Printed after the value of a compare and after the per-option lines of --options, so the number never travels without what it reads.
|
|
18
|
+
export const STRUCTURE_READS = "It reads layout structure only: sections (height, density, scale), section count, centering, uniform grid, text and area scale, empty space and the focal point. It does not read color, typefaces, images or texture, so it does not rank how different the options look.";
|
|
15
19
|
|
|
16
20
|
export class CompareInputError extends Error {
|
|
17
21
|
constructor(message) {
|
|
@@ -23,8 +27,8 @@ export class CompareInputError extends Error {
|
|
|
23
27
|
|
|
24
28
|
const round = (n) => Math.round(n * 100) / 100;
|
|
25
29
|
|
|
26
|
-
async function signatureAt(browser, target, width, cwd) {
|
|
27
|
-
const page = await openTarget(browser, target, width, { cwd });
|
|
30
|
+
export async function signatureAt(browser, target, width, cwd, height) {
|
|
31
|
+
const page = await openTarget(browser, target, width, { cwd, ...(height === undefined ? {} : { height }) });
|
|
28
32
|
try {
|
|
29
33
|
const layout = await measureLayout(page);
|
|
30
34
|
const rhythm = await measureRhythm(page, {});
|
|
@@ -34,7 +38,7 @@ async function signatureAt(browser, target, width, cwd) {
|
|
|
34
38
|
}
|
|
35
39
|
}
|
|
36
40
|
|
|
37
|
-
//
|
|
41
|
+
// Structure distance of a page from a baseline made without the kit for the same brief, per width.
|
|
38
42
|
// It measures; it gives no verdict, because no cutoff for "different enough" exists yet (H1).
|
|
39
43
|
export async function compareDesigns({ target, baseline, widths = [1440, 390], cwd = process.cwd(), out = path.join(".lazuli", "compare.json"), browser: givenBrowser }) {
|
|
40
44
|
if (typeof baseline !== "string" || baseline.trim() === "") {
|
|
@@ -90,8 +94,71 @@ export function formatCompare(r) {
|
|
|
90
94
|
.map(({ c }) => `${c.name} ${c.diff} (target ${shown(c.name, c.a)}, baseline ${shown(c.name, c.b)})`);
|
|
91
95
|
lines.push(`At ${w.width} px: ${w.value}; differs most in ${top.join("; ")}`);
|
|
92
96
|
}
|
|
93
|
-
lines.push(`
|
|
97
|
+
lines.push(`Structure distance from default: ${r.value} (0 is the same structure, 1 shares nothing). ${H1_LINE}`);
|
|
98
|
+
lines.push(STRUCTURE_READS);
|
|
94
99
|
lines.push(COMPARE_NOTE);
|
|
95
100
|
lines.push(`Measures: ${r.path}`);
|
|
96
101
|
return lines.join("\n");
|
|
97
102
|
}
|
|
103
|
+
|
|
104
|
+
// The name a baseline goes by in a label: its file name, or the URL as given.
|
|
105
|
+
export const baselineName = (baseline) => (/^https?:\/\//i.test(baseline.trim()) ? baseline.trim() : path.basename(baseline.trim()));
|
|
106
|
+
|
|
107
|
+
// A folder of options placed from low to high structure distance against one baseline, per width (1440 by default, like render-options: an option is one canvas).
|
|
108
|
+
// Give it the same widths and height render-options used, so each option is read at its own canvas.
|
|
109
|
+
// The baseline is read once per width; ties keep file order. Like compareDesigns, it measures and gives no verdict (H1).
|
|
110
|
+
export async function compareOptions({ folder: given, baseline, widths = [1440], height, cwd = process.cwd(), out = path.join(".lazuli", "compare.json"), browser: givenBrowser }) {
|
|
111
|
+
if (typeof baseline !== "string" || baseline.trim() === "") {
|
|
112
|
+
throw new CompareInputError("compare-designs needs a baseline: a page made without the kit for the same brief.");
|
|
113
|
+
}
|
|
114
|
+
checkHeight(height);
|
|
115
|
+
const folder = path.resolve(cwd, given);
|
|
116
|
+
if (!existsSync(folder) || !statSync(folder).isDirectory()) throw new CompareInputError(`Options folder not found: ${folder}`);
|
|
117
|
+
resolveTarget(baseline, cwd);
|
|
118
|
+
const entries = await fs.readdir(folder, { withFileTypes: true });
|
|
119
|
+
const files = entries
|
|
120
|
+
.filter((e) => e.isFile() && /\.html$/i.test(e.name))
|
|
121
|
+
.map((e) => e.name)
|
|
122
|
+
.sort()
|
|
123
|
+
.filter((name) => !sameTarget(path.join(folder, name), baseline, cwd));
|
|
124
|
+
if (files.length === 0) throw new CompareInputError(`No .html option file in ${folder}.`);
|
|
125
|
+
|
|
126
|
+
const options = files.map((file) => ({ file, value: 0, widths: [] }));
|
|
127
|
+
const browser = givenBrowser ?? (await openBrowser());
|
|
128
|
+
try {
|
|
129
|
+
for (const width of widths) {
|
|
130
|
+
const b = await signatureAt(browser, baseline, width, cwd, height);
|
|
131
|
+
for (const option of options) {
|
|
132
|
+
const a = await signatureAt(browser, path.join(folder, option.file), width, cwd, height);
|
|
133
|
+
const d = distance(a, b);
|
|
134
|
+
option.widths.push({ width, value: d.value, components: d.components });
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
} finally {
|
|
138
|
+
if (!givenBrowser) await browser.close();
|
|
139
|
+
}
|
|
140
|
+
for (const option of options) option.value = round(option.widths.reduce((s, w) => s + w.value, 0) / option.widths.length);
|
|
141
|
+
const order = options
|
|
142
|
+
.map((o, i) => ({ o, i }))
|
|
143
|
+
.sort((x, y) => x.o.value - y.o.value || x.i - y.i)
|
|
144
|
+
.map(({ o }) => o.file);
|
|
145
|
+
|
|
146
|
+
const file = path.resolve(cwd, out);
|
|
147
|
+
const result = { baseline, options, order, widths, ...(height === undefined ? {} : { height }), path: file, note: COMPARE_NOTE };
|
|
148
|
+
await fs.mkdir(path.dirname(file), { recursive: true });
|
|
149
|
+
await fs.writeFile(file, JSON.stringify(result, null, 2));
|
|
150
|
+
return result;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Each option in file order with its value, then the low-to-high line, the H1 caveat and the measures path.
|
|
154
|
+
export function formatCompareOptions(r) {
|
|
155
|
+
const value = (file) => r.options.find((o) => o.file === file).value;
|
|
156
|
+
const lines = [`Baseline: ${r.baseline}`];
|
|
157
|
+
for (const o of r.options) lines.push(`${o.file}: ${o.value}`);
|
|
158
|
+
lines.push(`Structure distance, low to high: ${r.order.map((f) => `${f} ${value(f)}`).join(", ")}`);
|
|
159
|
+
lines.push(`Structure distance from the baseline: 0 is the same structure, 1 shares nothing. ${H1_LINE}`);
|
|
160
|
+
lines.push(STRUCTURE_READS);
|
|
161
|
+
lines.push(r.note ?? COMPARE_NOTE);
|
|
162
|
+
lines.push(`Measures: ${r.path}`);
|
|
163
|
+
return lines.join("\n");
|
|
164
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import fs from "node:fs/promises";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { readLazuliMd } from "../project/lazuli-md.mjs";
|
|
3
|
+
import { isOptionsGoal, readLazuliMd } from "../project/lazuli-md.mjs";
|
|
4
4
|
import { gateStatus } from "../project/gate.mjs";
|
|
5
5
|
import { matchGoals, sameTarget } from "../project/match.mjs";
|
|
6
6
|
import { readRecords } from "../project/records.mjs";
|
|
@@ -94,6 +94,9 @@ export async function draftMemo({ cwd = process.cwd(), target } = {}) {
|
|
|
94
94
|
// Every break on a piece that is not a goal, and every break whose rule does not exist, once.
|
|
95
95
|
const unknownBreaks = new Set();
|
|
96
96
|
for (const b of md.breaks) {
|
|
97
|
+
if (b.status === "superseded") {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
97
100
|
if (!allPieces.has(norm(b.piece))) {
|
|
98
101
|
gaps.push(`Break "${b.rule}" on ${b.piece}: "${b.piece}" is not a goal.`);
|
|
99
102
|
} else if (!ruleOf(b.rule)) {
|
|
@@ -118,7 +121,8 @@ export async function draftMemo({ cwd = process.cwd(), target } = {}) {
|
|
|
118
121
|
check += `, review ${checked.verdict} by ${checked.reviewer ?? "unknown reviewer"} on ${checked.reviewedAt.slice(0, 10)}`;
|
|
119
122
|
}
|
|
120
123
|
out.push(check);
|
|
121
|
-
|
|
124
|
+
// An options goal is a glob, not a page with records of its own.
|
|
125
|
+
if (goal.target && !isOptionsGoal(goal)) {
|
|
122
126
|
const look = await firstLookOf(root, goal.target);
|
|
123
127
|
out.push(...look.lines);
|
|
124
128
|
if (look.gap) {
|
|
@@ -150,7 +154,7 @@ export async function draftMemo({ cwd = process.cwd(), target } = {}) {
|
|
|
150
154
|
gaps.push(`${goal.piece}: no decision is logged.`);
|
|
151
155
|
}
|
|
152
156
|
}
|
|
153
|
-
if (checked && checked.status !== "met") {
|
|
157
|
+
if (checked && checked.status !== "met" && checked.status !== "options") {
|
|
154
158
|
gaps.push(`${goal.piece}: the effect is ${checked.status}, not met.`);
|
|
155
159
|
}
|
|
156
160
|
}
|
package/src/commands/hooks.mjs
CHANGED
|
@@ -4,7 +4,7 @@ import fs from "node:fs/promises";
|
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
import { fileURLToPath } from "node:url";
|
|
6
6
|
import { toUrl } from "../browser.mjs";
|
|
7
|
-
import { isAssetGoal, readLazuliMd } from "../project/lazuli-md.mjs";
|
|
7
|
+
import { isAssetGoal, isOptionsGoal, readLazuliMd } from "../project/lazuli-md.mjs";
|
|
8
8
|
import { gateStatus as realGateStatus } from "../project/gate.mjs";
|
|
9
9
|
import { identity } from "../project/match.mjs";
|
|
10
10
|
import { readEdits, recordEdit } from "../project/edits.mjs";
|
|
@@ -150,7 +150,9 @@ export function summarizeForAgent(result, file) {
|
|
|
150
150
|
const findings = result?.findings ?? [];
|
|
151
151
|
const fails = findings.filter((f) => f.level === "fail");
|
|
152
152
|
const hints = findings.filter((f) => f.level === "hint");
|
|
153
|
-
|
|
153
|
+
// A declared move is never a fail; it is counted so the agent sees the hint was explained.
|
|
154
|
+
const declared = findings.filter((f) => f.level === "declared");
|
|
155
|
+
const parts = [`Lazuli check-design after editing ${file}: ${result?.target} at ${HOOK_WIDTHS.join(", ")} px, ${fails.length} fail, ${hints.length} hint${declared.length > 0 ? `, ${declared.length} declared` : ""}.`];
|
|
154
156
|
if (fails.length > 0) {
|
|
155
157
|
parts.push(`Fails: ${fails.map((f) => `${f.ruleId} ${f.name}: ${String(f.message ?? "").replace(/\.+$/, "")}`).join("; ")}.`);
|
|
156
158
|
}
|
|
@@ -176,8 +178,8 @@ function pickTargets(file, ext, md, cwd) {
|
|
|
176
178
|
const found = [];
|
|
177
179
|
const bad = [];
|
|
178
180
|
for (const g of md.goals ?? []) {
|
|
179
|
-
// A derived piece or a symbol is not a page: it is checked with --asset, so it never takes a page's place.
|
|
180
|
-
if (!g.target || isAssetGoal(g)) {
|
|
181
|
+
// A derived piece or a symbol is not a page: it is checked with --asset, so it never takes a page's place. Nor is a folder of options.
|
|
182
|
+
if (!g.target || isAssetGoal(g) || isOptionsGoal(g)) {
|
|
181
183
|
continue;
|
|
182
184
|
}
|
|
183
185
|
try {
|
|
@@ -235,7 +237,7 @@ export async function handlePostEdit(input, deps = {}) {
|
|
|
235
237
|
return SILENT;
|
|
236
238
|
}
|
|
237
239
|
const ext = path.extname(file).toLowerCase();
|
|
238
|
-
const watched = HTML.has(ext) || STYLE.has(ext) || (SOURCE.has(ext) && (md.goals ?? []).some((g) => g.target && isUrlTarget(g.target, cwd)));
|
|
240
|
+
const watched = HTML.has(ext) || STYLE.has(ext) || (SOURCE.has(ext) && (md.goals ?? []).some((g) => g.target && !isOptionsGoal(g) && isUrlTarget(g.target, cwd)));
|
|
239
241
|
if (!watched) {
|
|
240
242
|
return SILENT;
|
|
241
243
|
}
|
|
@@ -2,7 +2,8 @@ import { readFile, writeFile, access, rename, rm, mkdir } from "node:fs/promises
|
|
|
2
2
|
import { isDeepStrictEqual } from "node:util";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { KIT_RULES_DIR, loadKit } from "../rules/load.mjs";
|
|
5
|
-
import { parseLazuliMd } from "../project/lazuli-md.mjs";
|
|
5
|
+
import { isOptionsGoal, parseLazuliMd } from "../project/lazuli-md.mjs";
|
|
6
|
+
import { entryTargetForm, matchGoals, sameEntryTarget } from "../project/match.mjs";
|
|
6
7
|
import { writeBreak, writeDecision, LogInputError } from "../project/log.mjs";
|
|
7
8
|
import { RecordError, findCapture, readRecords, withLock, writeFileAtomic } from "../project/records.mjs";
|
|
8
9
|
|
|
@@ -44,14 +45,31 @@ async function readText(file) {
|
|
|
44
45
|
}
|
|
45
46
|
}
|
|
46
47
|
|
|
47
|
-
|
|
48
|
+
// --target names one file: a glob is refused (it would match only its own text and never apply).
|
|
49
|
+
function oneFile(target, cwd) {
|
|
50
|
+
if (target === undefined) {
|
|
51
|
+
return undefined;
|
|
52
|
+
}
|
|
53
|
+
if (String(target).includes("*")) {
|
|
54
|
+
throw new RecordInputError([`--target takes one file, not a glob: ${String(target).trim()}.`]);
|
|
55
|
+
}
|
|
56
|
+
return entryTargetForm(target, cwd);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// asWritten: --target as the person wrote it, for the messages.
|
|
60
|
+
async function prepare({ cwd, piece, rule, target, asWritten = target }) {
|
|
48
61
|
const file = await findFile(cwd);
|
|
49
62
|
const text = await readText(file);
|
|
50
|
-
const
|
|
63
|
+
const md = parseLazuliMd(text);
|
|
64
|
+
const goals = md.goals;
|
|
51
65
|
const goal = goals.find((g) => norm(g.piece) === norm(piece));
|
|
52
66
|
if (!goal) {
|
|
53
67
|
throw new RecordInputError([`Piece "${piece}" is not a goal in LAZULI.md. Goals: ${goals.length > 0 ? goals.map((g) => g.piece).join(", ") : "none"}.`]);
|
|
54
68
|
}
|
|
69
|
+
// A Target names one file of the piece: an exact Target of the goal or a file its glob covers.
|
|
70
|
+
if (target !== undefined && !matchGoals(md, target, path.resolve(cwd)).some((g) => norm(g.piece) === norm(goal.piece))) {
|
|
71
|
+
throw new RecordInputError([`--target ${String(asWritten).trim()} is not covered by the goal "${goal.piece}".`]);
|
|
72
|
+
}
|
|
55
73
|
const kit = await loadKit({
|
|
56
74
|
dirs: [process.env.LAZULI_RULES_DIR ?? KIT_RULES_DIR],
|
|
57
75
|
projectDir: path.join(cwd, ".lazuli", "rules"),
|
|
@@ -132,7 +150,7 @@ function guard(fn) {
|
|
|
132
150
|
// .lazuli/breaks.json: when each break was last set by record-break with a status other than kept.
|
|
133
151
|
// { "breaks": { "<rule>|<piece>": "<ISO time>" } }, keys lower case. A file that cannot be read holds no times.
|
|
134
152
|
const stampsFile = (cwd) => path.join(path.resolve(cwd), ".lazuli", "breaks.json");
|
|
135
|
-
const stampKey = (rule, piece) => `${norm(rule)}|${norm(piece)}`;
|
|
153
|
+
const stampKey = (rule, piece, target) => `${norm(rule)}|${norm(piece)}${target ? `|${norm(target)}` : ""}`;
|
|
136
154
|
|
|
137
155
|
async function readStamps(cwd) {
|
|
138
156
|
try {
|
|
@@ -143,18 +161,18 @@ async function readStamps(cwd) {
|
|
|
143
161
|
}
|
|
144
162
|
}
|
|
145
163
|
|
|
146
|
-
async function stampBreak(cwd, rule, piece) {
|
|
164
|
+
async function stampBreak(cwd, rule, piece, target) {
|
|
147
165
|
const file = stampsFile(cwd);
|
|
148
166
|
await mkdir(path.dirname(file), { recursive: true });
|
|
149
167
|
await withLock(file, async () => {
|
|
150
|
-
const breaks = { ...(await readStamps(cwd)), [stampKey(rule, piece)]: new Date().toISOString() };
|
|
168
|
+
const breaks = { ...(await readStamps(cwd)), [stampKey(rule, piece, target)]: new Date().toISOString() };
|
|
151
169
|
await writeFileAtomic(file, JSON.stringify({ breaks }, null, 2));
|
|
152
170
|
});
|
|
153
171
|
}
|
|
154
172
|
|
|
155
173
|
// A break becomes kept only after the separate reviewer has seen its declared effect: the latest review of a page
|
|
156
174
|
// of the piece judged the piece, on a capture taken after the break was last set. The builder never confirms it alone.
|
|
157
|
-
async function assertReviewed({ cwd, goals, rule, piece, was, given }) {
|
|
175
|
+
async function assertReviewed({ cwd, goals, rule, piece, target, was, given }) {
|
|
158
176
|
const refuse = (why) => {
|
|
159
177
|
throw new RecordError([`Break ${rule} on ${piece} cannot be kept yet: ${why}`]);
|
|
160
178
|
};
|
|
@@ -168,15 +186,23 @@ async function assertReviewed({ cwd, goals, rule, piece, was, given }) {
|
|
|
168
186
|
if (was.status === "kept") {
|
|
169
187
|
return;
|
|
170
188
|
}
|
|
189
|
+
if (was.status === "superseded") {
|
|
190
|
+
refuse("it is superseded. Set it to trying again with record-break --status trying, then review the page with review-design.");
|
|
191
|
+
}
|
|
171
192
|
if (was.status === "reverted") {
|
|
172
193
|
refuse("it is reverted. Set it to trying again with record-break --status trying, then review the page with review-design.");
|
|
173
194
|
}
|
|
174
|
-
const at = Date.parse((await readStamps(cwd))[stampKey(rule, piece)]);
|
|
195
|
+
const at = Date.parse((await readStamps(cwd))[stampKey(rule, piece, target)]);
|
|
175
196
|
if (Number.isNaN(at)) {
|
|
176
197
|
refuse("Lazuli has no record of when this break was last set. Run record-break again with --status trying, then review the page with review-design.");
|
|
177
198
|
}
|
|
178
|
-
|
|
199
|
+
// A break on one file is reviewed on that file; an options goal is never a page that a review counts for.
|
|
200
|
+
const pages = target ? [{ target }] : goals.filter((g) => norm(g.piece) === norm(piece) && g.target && !isOptionsGoal(g));
|
|
179
201
|
if (pages.length === 0) {
|
|
202
|
+
const options = goals.filter((g) => norm(g.piece) === norm(piece) && isOptionsGoal(g)).map((g) => g.target);
|
|
203
|
+
if (options.length > 0) {
|
|
204
|
+
refuse(`"${piece}" covers option files (${options.join(", ")}); a break on it is kept per file: give --target <option file>.`);
|
|
205
|
+
}
|
|
180
206
|
refuse(`"${piece}" has no Target, so no review can check the declared effect. Add a Target with set-goals, or revert the break.`);
|
|
181
207
|
}
|
|
182
208
|
for (const g of pages) {
|
|
@@ -202,25 +228,38 @@ async function assertReviewed({ cwd, goals, rule, piece, was, given }) {
|
|
|
202
228
|
}
|
|
203
229
|
|
|
204
230
|
// What a break on one id must hold before anything is written: a known rule that is not a norm, and for kept a review.
|
|
205
|
-
async function checkBreak({ cwd, rule, piece, status, effect, check }) {
|
|
206
|
-
const base = await prepare({ cwd, piece, rule });
|
|
231
|
+
async function checkBreak({ cwd, rule, piece, target, targetArg, status, effect, check }) {
|
|
232
|
+
const base = await prepare({ cwd, piece, rule, target, asWritten: targetArg });
|
|
207
233
|
const { text, goal, known } = base;
|
|
208
234
|
if (known.origin === "norm") {
|
|
209
235
|
throw new RecordInputError([`${known.id} is a norm and cannot be broken. Fix it instead.`]);
|
|
210
236
|
}
|
|
211
|
-
const given = { rule: known.id, piece: goal.piece, status, ...(effect !== undefined ? { effect } : {}), ...(check !== undefined ? { check } : {}) };
|
|
212
|
-
const next = guard(() => writeBreak(text, given));
|
|
213
|
-
const isTarget = (b) => norm(b.rule) === norm(known.id) && norm(b.piece) === norm(goal.piece);
|
|
237
|
+
const given = { rule: known.id, piece: goal.piece, ...(target !== undefined ? { target } : {}), status, ...(effect !== undefined ? { effect } : {}), ...(check !== undefined ? { check } : {}) };
|
|
238
|
+
const next = guard(() => writeBreak(text, given, { sameTarget: (a, b) => sameEntryTarget(a, b, cwd) }));
|
|
239
|
+
const isTarget = (b) => norm(b.rule) === norm(known.id) && norm(b.piece) === norm(goal.piece) && sameEntryTarget(b.target, target, cwd);
|
|
214
240
|
const keeping = String(status ?? "").trim() === "kept";
|
|
215
241
|
if (keeping) {
|
|
216
242
|
const md = parseLazuliMd(text);
|
|
217
|
-
await assertReviewed({ cwd, goals: md.goals, rule: known.id, piece: goal.piece, was: md.breaks.find(isTarget), given });
|
|
243
|
+
await assertReviewed({ cwd, goals: md.goals, rule: known.id, piece: goal.piece, target, was: md.breaks.find(isTarget), given });
|
|
218
244
|
}
|
|
219
245
|
return { ...base, given, next, isTarget, keeping };
|
|
220
246
|
}
|
|
221
247
|
|
|
248
|
+
// Retiring a break: the entry must already exist for this rule, piece and target. The piece may have no goal any more,
|
|
249
|
+
// so the goal and the rule are not looked up; only the status changes, with no review and no stamp.
|
|
250
|
+
async function supersedeOne({ cwd, rule, piece, target, targetArg }) {
|
|
251
|
+
const file = await findFile(cwd);
|
|
252
|
+
const text = await readText(file);
|
|
253
|
+
const was = parseLazuliMd(text).breaks.find((b) => norm(b.rule) === norm(rule) && norm(b.piece) === norm(piece) && sameEntryTarget(b.target, target, cwd));
|
|
254
|
+
if (!was) {
|
|
255
|
+
throw new RecordInputError([`No break ${rule} on ${piece} to supersede.`]);
|
|
256
|
+
}
|
|
257
|
+
const isTarget = (b) => norm(b.rule) === norm(was.rule) && norm(b.piece) === norm(was.piece) && sameEntryTarget(b.target, target, cwd);
|
|
258
|
+
return { file, isTarget, rule: was.rule, piece: was.piece };
|
|
259
|
+
}
|
|
260
|
+
|
|
222
261
|
async function breakOne(args) {
|
|
223
|
-
const { cwd, status } = args;
|
|
262
|
+
const { cwd, status, target } = args;
|
|
224
263
|
const { file, text, goal, known, given, next, isTarget, keeping } = await checkBreak(args);
|
|
225
264
|
const copies = await commit({
|
|
226
265
|
file,
|
|
@@ -232,7 +271,7 @@ async function breakOne(args) {
|
|
|
232
271
|
["effect", "check", "status"].every((k) => (k in given ? norm(now[k]) === norm(given[k]) : was !== undefined && now[k] === was[k])) &&
|
|
233
272
|
(was === undefined || now.piece === was.piece),
|
|
234
273
|
// Stamped before LAZULI.md is written: a write that fails after it only asks for a newer review.
|
|
235
|
-
beforeWrite: keeping ? undefined : () => stampBreak(cwd, known.id, goal.piece),
|
|
274
|
+
beforeWrite: keeping ? undefined : () => stampBreak(cwd, known.id, goal.piece, target),
|
|
236
275
|
});
|
|
237
276
|
const notes = copies > 1 ? [`Another entry for ${known.id} on ${goal.piece} was left as it was.`] : [];
|
|
238
277
|
return { path: file, rule: known.id, piece: goal.piece, status, notes };
|
|
@@ -240,12 +279,34 @@ async function breakOne(args) {
|
|
|
240
279
|
|
|
241
280
|
// One entry per id of a comma list. Every id is checked before the first is written, so a bad id writes nothing.
|
|
242
281
|
// A rule that shares its measure with kit rules outside the list reports the same finding under them: they are named.
|
|
243
|
-
export async function recordBreak({ cwd = process.cwd(), rule, piece, effect, check, status }) {
|
|
244
|
-
const
|
|
282
|
+
export async function recordBreak({ cwd = process.cwd(), rule, piece, target: targetArg, effect, check, status }) {
|
|
283
|
+
const target = oneFile(targetArg, cwd);
|
|
284
|
+
// One entry per id, however it is written: pa11,PA11 is one id.
|
|
285
|
+
const ids = String(rule ?? "")
|
|
286
|
+
.split(",")
|
|
287
|
+
.map((s) => s.trim())
|
|
288
|
+
.filter((s, i, all) => s !== "" && all.findIndex((x) => norm(x) === norm(s)) === i);
|
|
245
289
|
if (ids.length === 0) {
|
|
246
290
|
throw new RecordInputError(["--rule needs a rule id."]);
|
|
247
291
|
}
|
|
248
|
-
|
|
292
|
+
if (String(status ?? "").trim() === "superseded") {
|
|
293
|
+
if (effect !== undefined || check !== undefined) {
|
|
294
|
+
throw new RecordInputError(["--status superseded changes only the status; give no --effect or --check."]);
|
|
295
|
+
}
|
|
296
|
+
const planned = [];
|
|
297
|
+
for (const id of ids) {
|
|
298
|
+
planned.push(await supersedeOne({ cwd, rule: id, piece, target, targetArg }));
|
|
299
|
+
}
|
|
300
|
+
const entries = [];
|
|
301
|
+
for (const p of planned) {
|
|
302
|
+
const text = await readText(p.file);
|
|
303
|
+
const next = guard(() => writeBreak(text, { rule: p.rule, piece: p.piece, ...(target !== undefined ? { target } : {}), status: "superseded" }, { sameTarget: (a, b) => sameEntryTarget(a, b, cwd) }));
|
|
304
|
+
await commit({ file: p.file, text, next, kind: "breaks", isTarget: p.isTarget, expected: (now, was) => now.status === "superseded" && ["effect", "check", "piece"].every((k) => now[k] === was?.[k]) });
|
|
305
|
+
entries.push({ path: p.file, rule: p.rule, piece: p.piece, status, notes: [] });
|
|
306
|
+
}
|
|
307
|
+
return { path: entries[0].path, rule: entries[0].rule, rules: entries.map((e) => e.rule), piece: entries[0].piece, status, entries, notes: [] };
|
|
308
|
+
}
|
|
309
|
+
const args = (id) => ({ cwd, rule: id, piece, target, targetArg, effect, check, status });
|
|
249
310
|
const checked = [];
|
|
250
311
|
for (const id of ids) {
|
|
251
312
|
checked.push(await checkBreak(args(id)));
|
|
@@ -268,27 +329,28 @@ export async function recordBreak({ cwd = process.cwd(), rule, piece, effect, ch
|
|
|
268
329
|
}
|
|
269
330
|
|
|
270
331
|
// --rule of a decision: "<id> followed|broken|accepted", or "none" for a decision tied to no rule.
|
|
271
|
-
export async function recordDecision({ cwd = process.cwd(), decision, piece, goal: served, rule, measure }) {
|
|
332
|
+
export async function recordDecision({ cwd = process.cwd(), decision, piece, target: targetArg, goal: served, rule, measure }) {
|
|
333
|
+
const target = oneFile(targetArg, cwd);
|
|
272
334
|
const written = String(rule ?? "").trim();
|
|
273
335
|
const none = /^none$/i.test(written);
|
|
274
336
|
const match = /^(\S+)\s+(followed|broken|accepted)$/i.exec(written);
|
|
275
337
|
if (!match && !none) {
|
|
276
338
|
throw new RecordInputError(['--rule needs a rule id and followed, broken or accepted, for example "PA4 followed", or none.']);
|
|
277
339
|
}
|
|
278
|
-
const { file, text, goal, known } = await prepare({ cwd, piece, rule: none ? null : match[1] });
|
|
340
|
+
const { file, text, goal, known } = await prepare({ cwd, piece, target, asWritten: targetArg, rule: none ? null : match[1] });
|
|
279
341
|
const action = none ? "none" : match[2].toLowerCase();
|
|
280
342
|
if (action === "accepted" && known.origin === "norm") {
|
|
281
343
|
throw new RecordInputError([`${known.id} is a norm and cannot be accepted. Fix it instead.`]);
|
|
282
344
|
}
|
|
283
345
|
const ruleId = none ? "none" : known.id;
|
|
284
|
-
const given = { decision, piece: goal.piece, goal: served, rule: none ? "none" : `${known.id} ${action}`, measure };
|
|
285
|
-
const next = guard(() => writeDecision(text, given));
|
|
346
|
+
const given = { decision, piece: goal.piece, ...(target !== undefined ? { target } : {}), goal: served, rule: none ? "none" : `${known.id} ${action}`, measure };
|
|
347
|
+
const next = guard(() => writeDecision(text, given, { sameTarget: (a, b) => sameEntryTarget(a, b, cwd) }));
|
|
286
348
|
const copies = await commit({
|
|
287
349
|
file,
|
|
288
350
|
text,
|
|
289
351
|
next,
|
|
290
352
|
kind: "decisions",
|
|
291
|
-
isTarget: (d) => norm(d.decision) === norm(decision) && norm(d.piece) === norm(goal.piece),
|
|
353
|
+
isTarget: (d) => norm(d.decision) === norm(decision) && norm(d.piece) === norm(goal.piece) && sameEntryTarget(d.target, target, cwd),
|
|
292
354
|
expected: (now) => norm(now.goal) === norm(served) && now.rule === ruleId && now.action === action && norm(now.measure) === norm(measure),
|
|
293
355
|
});
|
|
294
356
|
const notes = copies > 1 ? [`Another entry for decision "${decision}" on ${goal.piece} was left as it was.`] : [];
|