@edjbarron/ux-guard 0.6.0 → 0.7.0
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/README.md +304 -58
- package/docs/cli-reference.md +92 -7
- package/docs/scoring-and-backslide.md +140 -0
- package/docs/test-suite.md +72 -5
- package/docs/use-case-review-design.md +284 -0
- package/docs/use-case-review.md +368 -0
- package/lib/catalog.mjs +46 -7
- package/lib/cli.mjs +368 -84
- package/lib/config.mjs +36 -1
- package/lib/review-app/app.css +697 -0
- package/lib/review-app/app.js +1899 -0
- package/lib/review-app/index.html +44 -0
- package/lib/review-audit.mjs +514 -0
- package/lib/review-command.mjs +409 -0
- package/lib/review-server.mjs +233 -0
- package/lib/review-store.mjs +554 -0
- package/lib/review.mjs +1385 -0
- package/lib/run-contract.mjs +1 -1
- package/package.json +1 -1
- package/skills/ux-guard/SKILL.md +154 -12
package/lib/cli.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { execFileSync } from 'node:child_process';
|
|
2
|
-
import { existsSync, lstatSync,
|
|
3
|
-
import { dirname, join,
|
|
2
|
+
import { existsSync, lstatSync, readFileSync, unlinkSync, writeFileSync } from 'node:fs';
|
|
3
|
+
import { dirname, join, resolve } from 'node:path';
|
|
4
4
|
import {
|
|
5
5
|
AuthoritativeUpgradeError,
|
|
6
6
|
createAuthoritativeAdvisory,
|
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
import { catalogPolicy, loadCatalog, loadSurfaces, renderCatalog, validateCatalog } from './catalog.mjs';
|
|
23
23
|
import {
|
|
24
24
|
CONFIG_FILE,
|
|
25
|
+
ensureLocalDirectory,
|
|
25
26
|
loadConfig,
|
|
26
27
|
loadTypeScript,
|
|
27
28
|
readTrusted,
|
|
@@ -59,6 +60,17 @@ import {
|
|
|
59
60
|
renderVerdictMarkdown,
|
|
60
61
|
serializeVerdictReport,
|
|
61
62
|
} from './verdicts.mjs';
|
|
63
|
+
import {
|
|
64
|
+
createReviewAudit,
|
|
65
|
+
renderReviewAuditMarkdown,
|
|
66
|
+
} from './review-audit.mjs';
|
|
67
|
+
import { previewText } from './review.mjs';
|
|
68
|
+
import {
|
|
69
|
+
DEFAULT_REVIEW_PATHS,
|
|
70
|
+
evaluateReview,
|
|
71
|
+
loadReviewContext,
|
|
72
|
+
readRepositoryFile,
|
|
73
|
+
} from './review-store.mjs';
|
|
62
74
|
import {
|
|
63
75
|
createRunEnvelope,
|
|
64
76
|
policyDigest,
|
|
@@ -84,18 +96,40 @@ import {
|
|
|
84
96
|
VisualContractError,
|
|
85
97
|
} from './visuals.mjs';
|
|
86
98
|
import { ConfigError, parseYamlSubset } from './yaml.mjs';
|
|
99
|
+
import { REVIEW_HELP, reviewCommand, reviewErrorGuidance } from './review-command.mjs';
|
|
87
100
|
|
|
88
101
|
const DEFAULT_SETUP_PROPOSAL = 'ux-guard/setup-proposal.json';
|
|
102
|
+
const SETUP_SIGNAL_LABELS = {
|
|
103
|
+
'inline-style': 'inline styles',
|
|
104
|
+
'hard-coded-color': 'hard-coded colors',
|
|
105
|
+
'px-literal': 'pixel literals',
|
|
106
|
+
'raw-button': 'raw button elements',
|
|
107
|
+
'icon-library': 'icon-library uses',
|
|
108
|
+
};
|
|
109
|
+
const REVIEW_OPTIONS = {
|
|
110
|
+
review: '--review',
|
|
111
|
+
preview: '--preview',
|
|
112
|
+
draft: '--draft',
|
|
113
|
+
catalog: '--catalog',
|
|
114
|
+
replaceCatalogSha256: '--replace-catalog-sha256',
|
|
115
|
+
port: '--port',
|
|
116
|
+
noOpen: '--no-open',
|
|
117
|
+
journeyReport: '--journey-report',
|
|
118
|
+
visualCandidate: '--visual-candidate',
|
|
119
|
+
};
|
|
89
120
|
|
|
90
121
|
const USAGE = `usage: ux-guard <command> [options]
|
|
91
122
|
|
|
92
123
|
commands:
|
|
93
|
-
setup inspect this repo and
|
|
124
|
+
setup inspect this repo and suggest reviewed next steps
|
|
125
|
+
review review proposed use cases in a local app
|
|
126
|
+
review review proposed use cases in a local app
|
|
94
127
|
check compare current UI code with reviewed UX policy
|
|
95
128
|
report explain UX evidence, gaps, and recommendations
|
|
96
129
|
|
|
97
130
|
help:
|
|
98
131
|
ux-guard setup --help
|
|
132
|
+
ux-guard review --help
|
|
99
133
|
ux-guard check --help
|
|
100
134
|
ux-guard report --help
|
|
101
135
|
ux-guard help advanced
|
|
@@ -108,13 +142,15 @@ common options:
|
|
|
108
142
|
|
|
109
143
|
const SETUP_HELP = `usage: ux-guard setup [options]
|
|
110
144
|
|
|
111
|
-
Inspect UI source without approving it,
|
|
112
|
-
|
|
113
|
-
|
|
145
|
+
Inspect UI source without approving it, report good observations, potential
|
|
146
|
+
problems, and unknowns, then suggest tailored next steps. A supporting review
|
|
147
|
+
file records the observed source roots, components, pattern counts, and
|
|
148
|
+
unresolved choices. Setup never creates active policy, a reviewed baseline, a
|
|
149
|
+
waiver, or enforcement.
|
|
114
150
|
|
|
115
151
|
options:
|
|
116
152
|
--root <dir> repository root (default: current directory)
|
|
117
|
-
--proposal <path>
|
|
153
|
+
--proposal <path> repository-local supporting review file
|
|
118
154
|
--format text|json human-readable or machine-readable output
|
|
119
155
|
--typescript <path> advanced: explicit TypeScript package path
|
|
120
156
|
`;
|
|
@@ -135,7 +171,8 @@ const REPORT_HELP = `usage: ux-guard report [options]
|
|
|
135
171
|
|
|
136
172
|
Explain configured journey evidence, UX quality, target attainment, regression,
|
|
137
173
|
and recommendations. Missing evidence stays unknown; it is never reported as
|
|
138
|
-
success.
|
|
174
|
+
success. A successfully rendered report exits 0 even when advisory findings,
|
|
175
|
+
target breaches, or backslide need attention; report does not enforce merges.
|
|
139
176
|
|
|
140
177
|
options:
|
|
141
178
|
--root <dir> repository root (default: current directory)
|
|
@@ -204,7 +241,7 @@ export async function main(argv, io = { out: process.stdout, err: process.stderr
|
|
|
204
241
|
return 2;
|
|
205
242
|
}
|
|
206
243
|
try {
|
|
207
|
-
return run(options, io);
|
|
244
|
+
return await run(options, io);
|
|
208
245
|
} catch (error) {
|
|
209
246
|
if (error instanceof AuthoritativeUpgradeError) {
|
|
210
247
|
io.err.write(`ux-guard: upgrade required: ${error.message}\n`);
|
|
@@ -224,7 +261,7 @@ export async function main(argv, io = { out: process.stdout, err: process.stderr
|
|
|
224
261
|
}
|
|
225
262
|
|
|
226
263
|
function writeCliError(error, argv, io) {
|
|
227
|
-
const command = ['setup', 'check', 'report'].find((name) => argv.includes(name));
|
|
264
|
+
const command = ['setup', 'review', 'check', 'report'].find((name) => argv.includes(name));
|
|
228
265
|
const guidance = errorGuidance(command, error.message);
|
|
229
266
|
if (
|
|
230
267
|
command === 'setup' &&
|
|
@@ -256,19 +293,20 @@ function errorGuidance(command, message) {
|
|
|
256
293
|
return 'Next: run ux-guard check. Setup will not replace the repository’s active policy.';
|
|
257
294
|
}
|
|
258
295
|
if (message.includes('already exists; refusing to overwrite')) {
|
|
259
|
-
return 'Next: review the existing setup
|
|
296
|
+
return 'Next: review the existing supporting setup file, which records observations and unresolved choices, or deliberately choose a different repository-local path.';
|
|
260
297
|
}
|
|
261
|
-
return 'Next: fix the reported input or choose a new
|
|
298
|
+
return 'Next: fix the reported input or choose a new supporting review file path, then run ux-guard setup again. Setup never overwrites files.';
|
|
262
299
|
}
|
|
300
|
+
if (command === 'review') return reviewErrorGuidance(message);
|
|
263
301
|
if (command === 'check') {
|
|
264
302
|
if (message.includes(CONFIG_FILE)) {
|
|
265
|
-
return 'Next:
|
|
303
|
+
return 'Next: run ux-guard setup, review its findings and supporting file, and activate policy only after explicit human approval.';
|
|
266
304
|
}
|
|
267
305
|
return 'Next: run ux-guard check --help, correct the reported input, and retry.';
|
|
268
306
|
}
|
|
269
307
|
if (command === 'report') {
|
|
270
308
|
if (message.includes(CONFIG_FILE)) {
|
|
271
|
-
return 'Next: review
|
|
309
|
+
return 'Next: run ux-guard setup, complete human review of policy and baseline decisions, then configure reviewed journey evidence. Reporting remains unavailable until those reviews are complete.';
|
|
272
310
|
}
|
|
273
311
|
if (message.includes('journey reporting is not configured')) {
|
|
274
312
|
return 'Next: keep using ux-guard check, and configure reviewed journey evidence before asking for a report.';
|
|
@@ -301,6 +339,15 @@ function parseArgs(argv) {
|
|
|
301
339
|
browser: 'chromium',
|
|
302
340
|
profile: 'Desktop Chrome',
|
|
303
341
|
repetitions: 3,
|
|
342
|
+
review: null,
|
|
343
|
+
preview: null,
|
|
344
|
+
draft: null,
|
|
345
|
+
catalog: null,
|
|
346
|
+
replaceCatalogSha256: null,
|
|
347
|
+
port: null,
|
|
348
|
+
noOpen: false,
|
|
349
|
+
journeyReport: null,
|
|
350
|
+
visualCandidate: null,
|
|
304
351
|
help: false,
|
|
305
352
|
};
|
|
306
353
|
for (let index = 0; index < argv.length; index += 1) {
|
|
@@ -336,6 +383,20 @@ function parseArgs(argv) {
|
|
|
336
383
|
}
|
|
337
384
|
options.repetitions = parsed;
|
|
338
385
|
}
|
|
386
|
+
else if (arg === '--review') options.review = value();
|
|
387
|
+
else if (arg === '--preview') options.preview = value();
|
|
388
|
+
else if (arg === '--draft') options.draft = value();
|
|
389
|
+
else if (arg === '--catalog') options.catalog = value();
|
|
390
|
+
else if (arg === '--replace-catalog-sha256') options.replaceCatalogSha256 = value();
|
|
391
|
+
else if (arg === '--port') {
|
|
392
|
+
const text = value();
|
|
393
|
+
const parsed = Number(text);
|
|
394
|
+
if (!/^\d+$/.test(text) || parsed > 65535) throw new Error('--port must be an integer from 0 to 65535');
|
|
395
|
+
options.port = parsed;
|
|
396
|
+
}
|
|
397
|
+
else if (arg === '--no-open') options.noOpen = true;
|
|
398
|
+
else if (arg === '--journey-report') options.journeyReport = value();
|
|
399
|
+
else if (arg === '--visual-candidate') options.visualCandidate = value();
|
|
339
400
|
else if (arg === '--format') options.format = value();
|
|
340
401
|
else if (arg === '--help' || arg === '-h') options.help = true;
|
|
341
402
|
else if (arg === '--strict') options.strict = true;
|
|
@@ -357,6 +418,7 @@ function run(options, io) {
|
|
|
357
418
|
else if (sub === 'setup') io.out.write(SETUP_HELP);
|
|
358
419
|
else if (sub === 'check') io.out.write(CHECK_HELP);
|
|
359
420
|
else if (sub === 'report') io.out.write(REPORT_HELP);
|
|
421
|
+
else if (sub === 'review') io.out.write(REVIEW_HELP);
|
|
360
422
|
else if (sub) throw new ConfigError(`unknown help topic ${sub}`);
|
|
361
423
|
else io.out.write(USAGE);
|
|
362
424
|
return 0;
|
|
@@ -364,15 +426,22 @@ function run(options, io) {
|
|
|
364
426
|
if (options.help) {
|
|
365
427
|
if (!command) io.out.write(USAGE);
|
|
366
428
|
else if (command === 'setup') io.out.write(SETUP_HELP);
|
|
429
|
+
else if (command === 'review') io.out.write(REVIEW_HELP);
|
|
367
430
|
else if (command === 'check') io.out.write(CHECK_HELP);
|
|
368
431
|
else if (command === 'report') io.out.write(REPORT_HELP);
|
|
369
432
|
else io.out.write(ADVANCED_USAGE);
|
|
370
433
|
return 0;
|
|
371
434
|
}
|
|
435
|
+
if (command !== 'review') {
|
|
436
|
+
const option = Object.keys(REVIEW_OPTIONS).find((name) => options[name] !== null && options[name] !== false);
|
|
437
|
+
if (option) throw new ConfigError(`${REVIEW_OPTIONS[option]} is only valid with review`);
|
|
438
|
+
}
|
|
372
439
|
if (command === 'setup') return setupCommand(options, io);
|
|
373
440
|
if (options.proposalExplicit) {
|
|
374
441
|
throw new ConfigError('--proposal is only valid with setup');
|
|
375
442
|
}
|
|
443
|
+
if (command === 'review' && sub === 'audit') return reviewAuditCommand(options, io);
|
|
444
|
+
if (command === 'review') return reviewCommand(options, io);
|
|
376
445
|
if (command === 'discover') return discoverCommand(options, io);
|
|
377
446
|
if (command === 'baseline') return baselineCommand(options, io);
|
|
378
447
|
if (command === 'visual') return visualCommand(options, io);
|
|
@@ -389,6 +458,12 @@ function run(options, io) {
|
|
|
389
458
|
if (options.format === 'markdown' && command !== 'report') {
|
|
390
459
|
throw new ConfigError('--format markdown is only valid with report or baseline inspect/diff');
|
|
391
460
|
}
|
|
461
|
+
if (options.journeyReport) {
|
|
462
|
+
throw new ConfigError('--journey-report is only valid with review audit');
|
|
463
|
+
}
|
|
464
|
+
if (options.visualCandidate) {
|
|
465
|
+
throw new ConfigError('--visual-candidate is only valid with review audit');
|
|
466
|
+
}
|
|
392
467
|
if (options.candidate) throw new ConfigError('--candidate is only valid with discover');
|
|
393
468
|
if (options.baseline) throw new ConfigError('--baseline is only valid with baseline diff');
|
|
394
469
|
if (options.reviewer || options.reviewedAt || options.rationale) {
|
|
@@ -466,6 +541,148 @@ function authoritativeCommand(options, io) {
|
|
|
466
541
|
}
|
|
467
542
|
}
|
|
468
543
|
|
|
544
|
+
function reviewAuditCommand(options, io) {
|
|
545
|
+
const [, sub, extra] = options.positional;
|
|
546
|
+
if (sub !== 'audit' || extra) {
|
|
547
|
+
throw new ConfigError(`unexpected argument ${extra ?? sub ?? '(none)'}`);
|
|
548
|
+
}
|
|
549
|
+
if (!options.base) {
|
|
550
|
+
throw new ConfigError('review audit requires --base with an explicit trusted revision');
|
|
551
|
+
}
|
|
552
|
+
if (!['json', 'markdown'].includes(options.format)) {
|
|
553
|
+
throw new ConfigError('review audit requires --format json or markdown');
|
|
554
|
+
}
|
|
555
|
+
if (
|
|
556
|
+
options.strict ||
|
|
557
|
+
options.acceptGrowth ||
|
|
558
|
+
options.typescript ||
|
|
559
|
+
options.draft ||
|
|
560
|
+
options.catalog ||
|
|
561
|
+
options.replaceCatalogSha256 ||
|
|
562
|
+
options.port !== null ||
|
|
563
|
+
options.noOpen ||
|
|
564
|
+
options.baseline ||
|
|
565
|
+
options.reviewer ||
|
|
566
|
+
options.reviewedAt ||
|
|
567
|
+
options.rationale ||
|
|
568
|
+
options.shards ||
|
|
569
|
+
options.visuals ||
|
|
570
|
+
options.candidateSha ||
|
|
571
|
+
options.project !== 'chromium' ||
|
|
572
|
+
options.browser !== 'chromium' ||
|
|
573
|
+
options.profile !== 'Desktop Chrome' ||
|
|
574
|
+
options.repetitions !== 3
|
|
575
|
+
) {
|
|
576
|
+
throw new ConfigError('review audit accepts only review paths, --base, evidence paths, and output format');
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
const paths = {
|
|
580
|
+
candidatePath: options.candidate ?? DEFAULT_REVIEW_PATHS.candidate,
|
|
581
|
+
reviewPath: options.review ?? DEFAULT_REVIEW_PATHS.review,
|
|
582
|
+
previewPath: options.preview ?? DEFAULT_REVIEW_PATHS.preview,
|
|
583
|
+
explicitCandidate: options.candidate !== null,
|
|
584
|
+
};
|
|
585
|
+
const context = loadReviewContext(options.root, paths);
|
|
586
|
+
if (context.status === 'no-candidate') {
|
|
587
|
+
throw new ConfigError(`candidate ${paths.candidatePath} does not exist`);
|
|
588
|
+
}
|
|
589
|
+
if (context.reviewSha256 === null) {
|
|
590
|
+
throw new ConfigError('review audit requires a saved review; saving remains a user action');
|
|
591
|
+
}
|
|
592
|
+
const state = evaluateReview(context);
|
|
593
|
+
const previewFile = readRepositoryFile(options.root, context.previewPath, 'preview');
|
|
594
|
+
const expectedPreview = previewText(state);
|
|
595
|
+
if (!previewFile || expectedPreview === null || previewFile.text !== expectedPreview) {
|
|
596
|
+
throw new ConfigError(
|
|
597
|
+
`${context.previewPath} does not exactly match the saved review; do not audit or adopt it until the reviewer saves a current preview`,
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const trust = resolveTrustedRevision(options.root, options.base);
|
|
602
|
+
const config = loadConfig(options.root, trust);
|
|
603
|
+
if (state.catalog.path !== config.catalog.path) {
|
|
604
|
+
throw new ConfigError(
|
|
605
|
+
`saved preview targets ${state.catalog.path}, but trusted policy uses ${config.catalog.path}; a candidate configuration cannot redefine the audit judge`,
|
|
606
|
+
);
|
|
607
|
+
}
|
|
608
|
+
const ts = loadTypeScript();
|
|
609
|
+
const surfaces = loadSurfaces(ts, options.root, config);
|
|
610
|
+
const trustedCatalogText = readTrusted(options.root, config.catalog.path, trust);
|
|
611
|
+
if (state.catalog.activeSha256 !== sha256(trustedCatalogText)) {
|
|
612
|
+
throw new ConfigError(
|
|
613
|
+
`${config.catalog.path} differs from trusted base ${trust.ref}; keep the active reviewed catalog unchanged and assess catalog changes through the unapproved preview`,
|
|
614
|
+
);
|
|
615
|
+
}
|
|
616
|
+
const trustedCatalogDocument = parseYamlSubset(trustedCatalogText);
|
|
617
|
+
const trustedPolicy = catalogPolicy(trustedCatalogDocument);
|
|
618
|
+
const activeCatalog = evaluateCatalogReport(
|
|
619
|
+
validateCatalog(trustedCatalogDocument, surfaces),
|
|
620
|
+
trustedPolicy.inventory,
|
|
621
|
+
false,
|
|
622
|
+
);
|
|
623
|
+
const previewReport = validateCatalog(parseYamlSubset(state.catalog.text), surfaces);
|
|
624
|
+
const previewCatalog = evaluateCatalogReport(
|
|
625
|
+
previewReport,
|
|
626
|
+
trustedPolicy.inventory,
|
|
627
|
+
false,
|
|
628
|
+
);
|
|
629
|
+
const patterns = evaluatePatternScan(ts, config, trust, options);
|
|
630
|
+
const journeys = evaluateJourneys(
|
|
631
|
+
config,
|
|
632
|
+
trust,
|
|
633
|
+
{
|
|
634
|
+
...options,
|
|
635
|
+
auditEvidence: true,
|
|
636
|
+
},
|
|
637
|
+
previewReport,
|
|
638
|
+
);
|
|
639
|
+
|
|
640
|
+
let visuals = {
|
|
641
|
+
rollout: 'advisory',
|
|
642
|
+
status: 'not-evaluated',
|
|
643
|
+
reason: 'No explicit current visual candidate was supplied to review audit.',
|
|
644
|
+
};
|
|
645
|
+
if (options.visualCandidate) {
|
|
646
|
+
try {
|
|
647
|
+
visuals = evaluateVisuals(config, trust, options);
|
|
648
|
+
} catch (error) {
|
|
649
|
+
if (!(error instanceof VisualContractError)) throw error;
|
|
650
|
+
visuals = {
|
|
651
|
+
rollout: 'advisory',
|
|
652
|
+
status: 'not-evaluated',
|
|
653
|
+
reason: error.message,
|
|
654
|
+
};
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
const verdict =
|
|
658
|
+
journeys.summary.evidence.status === 'compatible'
|
|
659
|
+
? evaluateVerdicts(
|
|
660
|
+
previewReport,
|
|
661
|
+
journeys,
|
|
662
|
+
patterns.summary,
|
|
663
|
+
visuals.status === 'not-evaluated' ? undefined : visuals,
|
|
664
|
+
)
|
|
665
|
+
: null;
|
|
666
|
+
const audit = createReviewAudit({
|
|
667
|
+
context,
|
|
668
|
+
state,
|
|
669
|
+
trust,
|
|
670
|
+
previewFile,
|
|
671
|
+
activeCatalog,
|
|
672
|
+
previewCatalog,
|
|
673
|
+
patterns,
|
|
674
|
+
journeys,
|
|
675
|
+
visuals,
|
|
676
|
+
verdict,
|
|
677
|
+
});
|
|
678
|
+
if (options.format === 'json') {
|
|
679
|
+
io.out.write(`${JSON.stringify(audit, null, 2)}\n`);
|
|
680
|
+
} else {
|
|
681
|
+
io.out.write(renderReviewAuditMarkdown(audit));
|
|
682
|
+
}
|
|
683
|
+
return 0;
|
|
684
|
+
}
|
|
685
|
+
|
|
469
686
|
function setupCommand(options, io) {
|
|
470
687
|
const [, sub] = options.positional;
|
|
471
688
|
if (sub) throw new ConfigError(`unexpected argument ${sub}`);
|
|
@@ -516,7 +733,7 @@ function setupCommand(options, io) {
|
|
|
516
733
|
}
|
|
517
734
|
|
|
518
735
|
const proposal = setupProposalFromDiscovery(report);
|
|
519
|
-
writeCandidate(options.root, options.proposal, proposal, 'setup
|
|
736
|
+
writeCandidate(options.root, options.proposal, proposal, 'setup review file');
|
|
520
737
|
const result = setupResult(report, options.proposal);
|
|
521
738
|
writeSetupResult(result, options.format, io);
|
|
522
739
|
return 0;
|
|
@@ -555,9 +772,7 @@ function setupResult(report, proposalPath) {
|
|
|
555
772
|
enforcementEnabled: false,
|
|
556
773
|
filesWritten: [proposalPath],
|
|
557
774
|
},
|
|
558
|
-
nextAction:
|
|
559
|
-
`Review ${proposalPath} with the people responsible for product, design, and engineering. ` +
|
|
560
|
-
'Choose the missing policy and catalog decisions, then require explicit human approval before activation.',
|
|
775
|
+
nextAction: setupNextAction(assessment, proposalPath),
|
|
561
776
|
};
|
|
562
777
|
}
|
|
563
778
|
|
|
@@ -598,19 +813,14 @@ function setupEvidenceGap(proposalPath, reason) {
|
|
|
598
813
|
enforcementEnabled: false,
|
|
599
814
|
filesWritten: [],
|
|
600
815
|
},
|
|
601
|
-
nextAction:
|
|
602
|
-
'Add or point ux-guard to a TypeScript UI project with non-test JSX or TSX source, then run ux-guard setup again.',
|
|
816
|
+
nextAction: [
|
|
817
|
+
'1. Add or point ux-guard to a TypeScript UI project with non-test JSX or TSX source, then run ux-guard setup again.',
|
|
818
|
+
'No policy, baseline, waiver, or enforcement was activated.',
|
|
819
|
+
].join('\n'),
|
|
603
820
|
};
|
|
604
821
|
}
|
|
605
822
|
|
|
606
823
|
function assessSetup(report) {
|
|
607
|
-
const labels = {
|
|
608
|
-
'inline-style': 'inline styles',
|
|
609
|
-
'hard-coded-color': 'hard-coded colors',
|
|
610
|
-
'px-literal': 'pixel literals',
|
|
611
|
-
'raw-button': 'raw button elements',
|
|
612
|
-
'icon-library': 'icon-library uses',
|
|
613
|
-
};
|
|
614
824
|
const good = [`Inspected ${report.observed.files} non-test UI source files.`];
|
|
615
825
|
const needsAttention = [];
|
|
616
826
|
for (const rule of DEBT_RULES) {
|
|
@@ -619,11 +829,11 @@ function assessSetup(report) {
|
|
|
619
829
|
.sort((left, right) => left.path.localeCompare(right.path));
|
|
620
830
|
const count = locations.reduce((sum, item) => sum + item.count, 0);
|
|
621
831
|
if (count === 0) {
|
|
622
|
-
good.push(`No ${
|
|
832
|
+
good.push(`No ${SETUP_SIGNAL_LABELS[rule]} were observed in the inspected files.`);
|
|
623
833
|
} else {
|
|
624
834
|
needsAttention.push({
|
|
625
835
|
signal: rule,
|
|
626
|
-
summary: `${count} ${
|
|
836
|
+
summary: `${count} ${SETUP_SIGNAL_LABELS[rule]} observed; review before deciding policy.`,
|
|
627
837
|
count,
|
|
628
838
|
locations,
|
|
629
839
|
});
|
|
@@ -641,6 +851,57 @@ function assessSetup(report) {
|
|
|
641
851
|
return { good, needsAttention, unknown };
|
|
642
852
|
}
|
|
643
853
|
|
|
854
|
+
function setupNextAction(assessment, reviewPath) {
|
|
855
|
+
const steps = [];
|
|
856
|
+
const missingCatalog = assessment.unknown.some((item) =>
|
|
857
|
+
item.startsWith('No use-case catalog was inspected'),
|
|
858
|
+
);
|
|
859
|
+
const missingBaseline = assessment.unknown.some((item) =>
|
|
860
|
+
item.startsWith('No trusted baseline was used'),
|
|
861
|
+
);
|
|
862
|
+
if (missingCatalog) {
|
|
863
|
+
steps.push(
|
|
864
|
+
'Define the important user workflows and use cases. ' +
|
|
865
|
+
'Agent Skill prompt: "Help me define ux-guard use cases for this repo"',
|
|
866
|
+
);
|
|
867
|
+
}
|
|
868
|
+
if (assessment.needsAttention.length > 0) {
|
|
869
|
+
const findings = plainList(
|
|
870
|
+
assessment.needsAttention.map(({ signal }) => SETUP_SIGNAL_LABELS[signal]),
|
|
871
|
+
);
|
|
872
|
+
steps.push(
|
|
873
|
+
`Review the observed styling and pattern issues (${findings}) and decide which are intentional conventions versus UX debt. ` +
|
|
874
|
+
`Agent Skill prompt: "Review ux-guard's observed ${findings} in this repo and help me decide which are intentional conventions versus UX debt; do not change policy or baselines"`,
|
|
875
|
+
);
|
|
876
|
+
}
|
|
877
|
+
const decision = missingBaseline
|
|
878
|
+
? 'Decide what should become reviewed policy and prepare the initial baseline.'
|
|
879
|
+
: 'Decide what should become reviewed policy.';
|
|
880
|
+
const approval = missingBaseline
|
|
881
|
+
? 'Do not activate policy or baseline until a human explicitly approves them.'
|
|
882
|
+
: 'Do not activate policy until a human explicitly approves it.';
|
|
883
|
+
const reviewPrompt = missingBaseline
|
|
884
|
+
? `Help me review ${reviewPath}, decide what should become reviewed ux-guard policy, and prepare the initial baseline; do not activate anything until I explicitly approve it`
|
|
885
|
+
: `Help me review ${reviewPath} and decide what should become reviewed ux-guard policy; do not activate anything until I explicitly approve it`;
|
|
886
|
+
steps.push(
|
|
887
|
+
`${decision} Use ${reviewPath} as a supporting review file; it contains observed source roots, component and icon usage, pattern counts, and unresolved policy choices. ${approval} ` +
|
|
888
|
+
`Agent Skill prompt: "${reviewPrompt}"`,
|
|
889
|
+
);
|
|
890
|
+
steps.push(
|
|
891
|
+
'After human approval and activation, run ux-guard check. Run ux-guard report after reviewed journey policy and a journey report path are configured.',
|
|
892
|
+
);
|
|
893
|
+
return [
|
|
894
|
+
...steps.map((step, index) => `${index + 1}. ${step}`),
|
|
895
|
+
'No policy, baseline, waiver, or enforcement was activated.',
|
|
896
|
+
].join('\n');
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
function plainList(items) {
|
|
900
|
+
if (items.length < 2) return items[0] ?? '';
|
|
901
|
+
if (items.length === 2) return `${items[0]} and ${items[1]}`;
|
|
902
|
+
return `${items.slice(0, -1).join(', ')}, and ${items.at(-1)}`;
|
|
903
|
+
}
|
|
904
|
+
|
|
644
905
|
function writeSetupResult(result, format, io) {
|
|
645
906
|
if (format === 'json') {
|
|
646
907
|
io.out.write(`${JSON.stringify(result, null, 2)}\n`);
|
|
@@ -677,22 +938,10 @@ function writeSetupResult(result, format, io) {
|
|
|
677
938
|
}
|
|
678
939
|
lines.push('', 'Unknown');
|
|
679
940
|
for (const item of result.results.unknown) lines.push(` - ${item}`);
|
|
680
|
-
lines.push('', 'Setup proposal');
|
|
681
|
-
if (result.proposal.written) {
|
|
682
|
-
lines.push(
|
|
683
|
-
` Saved ${result.proposal.path}.`,
|
|
684
|
-
' Status: unapproved. It records observations and decisions still needing human review.',
|
|
685
|
-
);
|
|
686
|
-
} else {
|
|
687
|
-
lines.push(` Not created at ${result.proposal.path}; there was not enough UI evidence.`);
|
|
688
|
-
}
|
|
689
941
|
lines.push(
|
|
690
942
|
'',
|
|
691
|
-
'
|
|
692
|
-
'
|
|
693
|
-
'',
|
|
694
|
-
'Next safe action',
|
|
695
|
-
` ${result.nextAction}`,
|
|
943
|
+
'Next steps',
|
|
944
|
+
...result.nextAction.split('\n').map((line) => ` ${line}`),
|
|
696
945
|
);
|
|
697
946
|
io.out.write(`${lines.join('\n')}\n`);
|
|
698
947
|
}
|
|
@@ -1251,32 +1500,6 @@ function writePromotedPolicy(root, config, baseline) {
|
|
|
1251
1500
|
}
|
|
1252
1501
|
}
|
|
1253
1502
|
|
|
1254
|
-
function ensureLocalDirectory(root, directory, label, create) {
|
|
1255
|
-
const path = relative(root, directory);
|
|
1256
|
-
if (!path) return;
|
|
1257
|
-
let current = root;
|
|
1258
|
-
for (const part of path.split(sep)) {
|
|
1259
|
-
current = join(current, part);
|
|
1260
|
-
if (!existsSync(current)) {
|
|
1261
|
-
if (!create) throw new ConfigError(`${label} parent does not exist`);
|
|
1262
|
-
try {
|
|
1263
|
-
mkdirSync(current);
|
|
1264
|
-
} catch {
|
|
1265
|
-
throw new ConfigError(`${label} parent could not be created safely`);
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
let stats;
|
|
1269
|
-
try {
|
|
1270
|
-
stats = lstatSync(current);
|
|
1271
|
-
} catch {
|
|
1272
|
-
throw new ConfigError(`${label} parent could not be inspected`);
|
|
1273
|
-
}
|
|
1274
|
-
if (stats.isSymbolicLink() || !stats.isDirectory()) {
|
|
1275
|
-
throw new ConfigError(`${label} parent must be a repository directory, not a symbolic link`);
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
1503
|
function catalogCommand(ts, config, trust, options, io) {
|
|
1281
1504
|
const evaluation = evaluateCatalog(ts, config, trust, options);
|
|
1282
1505
|
if (options.format === 'json') {
|
|
@@ -1294,6 +1517,10 @@ function evaluateCatalog(ts, config, trust, options) {
|
|
|
1294
1517
|
if (trust) {
|
|
1295
1518
|
policyInventory = catalogPolicy(parseYamlSubset(readTrusted(options.root, config.catalog.path, trust))).inventory;
|
|
1296
1519
|
}
|
|
1520
|
+
return evaluateCatalogReport(report, policyInventory, options.strict);
|
|
1521
|
+
}
|
|
1522
|
+
|
|
1523
|
+
function evaluateCatalogReport(report, policyInventory, strict) {
|
|
1297
1524
|
const findings = [];
|
|
1298
1525
|
if (policyInventory === 'complete' && report.inventory !== 'complete') {
|
|
1299
1526
|
findings.push({
|
|
@@ -1309,7 +1536,7 @@ function evaluateCatalog(ts, config, trust, options) {
|
|
|
1309
1536
|
message: 'a complete inventory cannot leave a navigation surface unmapped',
|
|
1310
1537
|
});
|
|
1311
1538
|
}
|
|
1312
|
-
if (
|
|
1539
|
+
if (strict && report.unmapped.length > 0) {
|
|
1313
1540
|
findings.push({
|
|
1314
1541
|
rule: 'unmapped-strict',
|
|
1315
1542
|
count: report.unmapped.length,
|
|
@@ -1407,10 +1634,20 @@ function evaluateVerdicts(catalog, journeys, patterns, visuals) {
|
|
|
1407
1634
|
|
|
1408
1635
|
function evaluateJourneys(config, trust, options, catalog) {
|
|
1409
1636
|
if (!config.journeys) {
|
|
1637
|
+
if (options.journeyReport) {
|
|
1638
|
+
throw new ConfigError('--journey-report cannot be used because journey reporting is not configured');
|
|
1639
|
+
}
|
|
1410
1640
|
return {
|
|
1411
1641
|
summary: {
|
|
1412
1642
|
status: 'unconfigured',
|
|
1413
1643
|
rollout: 'measurement-only',
|
|
1644
|
+
evidence: {
|
|
1645
|
+
path: null,
|
|
1646
|
+
sha256: null,
|
|
1647
|
+
present: false,
|
|
1648
|
+
status: 'unconfigured',
|
|
1649
|
+
reason: 'Journey reporting is not configured.',
|
|
1650
|
+
},
|
|
1414
1651
|
},
|
|
1415
1652
|
policy: null,
|
|
1416
1653
|
measurements: null,
|
|
@@ -1423,7 +1660,8 @@ function evaluateJourneys(config, trust, options, catalog) {
|
|
|
1423
1660
|
};
|
|
1424
1661
|
}
|
|
1425
1662
|
|
|
1426
|
-
const
|
|
1663
|
+
const policyPath = config.journeys.policy;
|
|
1664
|
+
const reportPath = options.journeyReport ?? config.journeys.report;
|
|
1427
1665
|
let policy;
|
|
1428
1666
|
try {
|
|
1429
1667
|
policy = parseJourneyPolicy(readTrusted(options.root, policyPath, trust));
|
|
@@ -1432,16 +1670,24 @@ function evaluateJourneys(config, trust, options, catalog) {
|
|
|
1432
1670
|
throw new ConfigError(`${policyPath}: ${error.message}`);
|
|
1433
1671
|
}
|
|
1434
1672
|
|
|
1435
|
-
const reportPresent =
|
|
1673
|
+
const reportPresent = trustedFileExists(options.root, reportPath, null);
|
|
1436
1674
|
let report = null;
|
|
1675
|
+
let reportSha256 = null;
|
|
1676
|
+
let evidenceError = null;
|
|
1437
1677
|
if (reportPresent) {
|
|
1678
|
+
const reportText = readTrusted(options.root, reportPath, null);
|
|
1679
|
+
reportSha256 = sha256(reportText);
|
|
1438
1680
|
try {
|
|
1439
|
-
report = parseJourneyReport(
|
|
1681
|
+
report = parseJourneyReport(reportText);
|
|
1440
1682
|
} catch (error) {
|
|
1441
1683
|
if (error instanceof ConfigError) throw error;
|
|
1442
|
-
|
|
1684
|
+
if (!options.auditEvidence) {
|
|
1685
|
+
throw new ConfigError(`${reportPath}: ${error.message}`);
|
|
1686
|
+
}
|
|
1687
|
+
evidenceError = error;
|
|
1443
1688
|
}
|
|
1444
|
-
}
|
|
1689
|
+
}
|
|
1690
|
+
if (!report) {
|
|
1445
1691
|
const identity = resolveRunIdentity(options.root, {
|
|
1446
1692
|
policy,
|
|
1447
1693
|
baseCommit: trust?.commit,
|
|
@@ -1461,14 +1707,31 @@ function evaluateJourneys(config, trust, options, catalog) {
|
|
|
1461
1707
|
} catch (error) {
|
|
1462
1708
|
throw new ConfigError(`journey measurement: ${error.message}`);
|
|
1463
1709
|
}
|
|
1464
|
-
const
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1710
|
+
const evidenceStatus = evidenceError
|
|
1711
|
+
? evidenceCompatibilityStatus(evidenceError)
|
|
1712
|
+
: reportPresent
|
|
1713
|
+
? 'compatible'
|
|
1714
|
+
: 'missing';
|
|
1715
|
+
const evidenceReason = evidenceError
|
|
1716
|
+
? evidenceError.message
|
|
1717
|
+
: reportPresent
|
|
1718
|
+
? 'The journey report is compatible with this ux-guard version and trusted policy.'
|
|
1719
|
+
: `Journey evidence ${reportPath} is not available.`;
|
|
1720
|
+
const comparisonEvaluation = evidenceError
|
|
1721
|
+
? {
|
|
1722
|
+
comparison: unavailableJourneyComparison(
|
|
1723
|
+
`current journey evidence is ${evidenceStatus}: ${evidenceReason}`,
|
|
1724
|
+
),
|
|
1725
|
+
readinessEvidence: null,
|
|
1726
|
+
}
|
|
1727
|
+
: evaluateJourneyComparison({
|
|
1728
|
+
config,
|
|
1729
|
+
trust,
|
|
1730
|
+
root: options.root,
|
|
1731
|
+
report,
|
|
1732
|
+
reportPresent,
|
|
1733
|
+
policy,
|
|
1734
|
+
});
|
|
1472
1735
|
const targets = evaluateOwnerTargets(
|
|
1473
1736
|
config,
|
|
1474
1737
|
trust,
|
|
@@ -1482,6 +1745,13 @@ function evaluateJourneys(config, trust, options, catalog) {
|
|
|
1482
1745
|
policyPath,
|
|
1483
1746
|
reportPath,
|
|
1484
1747
|
reportPresent,
|
|
1748
|
+
evidence: {
|
|
1749
|
+
path: reportPath,
|
|
1750
|
+
sha256: reportSha256,
|
|
1751
|
+
present: reportPresent,
|
|
1752
|
+
status: evidenceStatus,
|
|
1753
|
+
reason: evidenceReason,
|
|
1754
|
+
},
|
|
1485
1755
|
...artifact,
|
|
1486
1756
|
comparison: comparisonEvaluation.comparison,
|
|
1487
1757
|
targets,
|
|
@@ -1494,6 +1764,19 @@ function evaluateJourneys(config, trust, options, catalog) {
|
|
|
1494
1764
|
};
|
|
1495
1765
|
}
|
|
1496
1766
|
|
|
1767
|
+
function evidenceCompatibilityStatus(error) {
|
|
1768
|
+
const message = error.message.toLowerCase();
|
|
1769
|
+
return [
|
|
1770
|
+
'version',
|
|
1771
|
+
'not this ux-guard version',
|
|
1772
|
+
'policy digest',
|
|
1773
|
+
'profile differs',
|
|
1774
|
+
'adapter',
|
|
1775
|
+
].some((signal) => message.includes(signal))
|
|
1776
|
+
? 'incompatible'
|
|
1777
|
+
: 'invalid';
|
|
1778
|
+
}
|
|
1779
|
+
|
|
1497
1780
|
function evaluateJourneyComparison({
|
|
1498
1781
|
config,
|
|
1499
1782
|
trust,
|
|
@@ -1603,8 +1886,9 @@ function evaluateVisuals(config, trust, options) {
|
|
|
1603
1886
|
comparison: unavailableVisualComparison('visual policy is not configured'),
|
|
1604
1887
|
});
|
|
1605
1888
|
}
|
|
1606
|
-
const { profiles, checkpoints,
|
|
1889
|
+
const { profiles, checkpoints, baseline: baselinePath } =
|
|
1607
1890
|
config.visuals;
|
|
1891
|
+
const candidatePath = options.visualCandidate ?? config.visuals.candidate;
|
|
1608
1892
|
const profileSet = parseVisualProfileSet(
|
|
1609
1893
|
readTrusted(options.root, profiles, trust),
|
|
1610
1894
|
);
|