@edjbarron/ux-guard 0.0.0-stage → 0.6.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/yaml.mjs ADDED
@@ -0,0 +1,140 @@
1
+ // A strict parser for the YAML subset ux-guard catalogs use: two-space
2
+ // indentation, mappings, lists, quoted or plain scalars, and comments. Anything
3
+ // outside that subset is an error rather than a guess.
4
+
5
+ export class ConfigError extends Error {}
6
+
7
+ export function parseYamlSubset(text) {
8
+ const lines = [];
9
+ text.split(/\r?\n/).forEach((raw, offset) => {
10
+ const lineNo = offset + 1;
11
+ const code = stripComment(raw);
12
+ if (!code.trim()) return;
13
+ if (code.includes('\t')) throw new ConfigError(`line ${lineNo}: tabs are not allowed`);
14
+ const indent = code.length - code.trimStart().length;
15
+ if (indent % 2) throw new ConfigError(`line ${lineNo}: indent must be a multiple of 2`);
16
+ lines.push({ level: indent / 2, text: code.trim(), lineNo });
17
+ });
18
+ if (lines.length === 0) throw new ConfigError('document is empty');
19
+ const [value, index] = parseNode(lines, 0, 0);
20
+ if (index !== lines.length) {
21
+ throw new ConfigError(`line ${lines[index].lineNo}: unexpected content`);
22
+ }
23
+ return value;
24
+ }
25
+
26
+ function stripComment(raw) {
27
+ let quote = '';
28
+ let out = '';
29
+ for (const char of raw) {
30
+ if (quote) {
31
+ out += char;
32
+ if (char === quote) quote = '';
33
+ } else if (char === '"' || char === "'") {
34
+ quote = char;
35
+ out += char;
36
+ } else if (char === '#') {
37
+ break;
38
+ } else {
39
+ out += char;
40
+ }
41
+ }
42
+ return out;
43
+ }
44
+
45
+ function parseNode(lines, index, level) {
46
+ if (index >= lines.length || lines[index].level !== level) {
47
+ throw new ConfigError(where(lines, index, `expected content at indent ${level * 2}`));
48
+ }
49
+ return isListItem(lines[index].text)
50
+ ? parseList(lines, index, level)
51
+ : parseMap(lines, index, level);
52
+ }
53
+
54
+ function isListItem(text) {
55
+ return text === '-' || text.startsWith('- ');
56
+ }
57
+
58
+ function parseList(lines, index, level) {
59
+ const items = [];
60
+ while (index < lines.length && lines[index].level === level && isListItem(lines[index].text)) {
61
+ const { text, lineNo } = lines[index];
62
+ const rest = text.slice(1).trim();
63
+ index += 1;
64
+ if (!rest) {
65
+ const [value, next] = parseNode(lines, index, level + 1);
66
+ items.push(value);
67
+ index = next;
68
+ continue;
69
+ }
70
+ if (rest[0] === '"' || rest[0] === "'" || !hasField(rest)) {
71
+ items.push(scalar(rest, lineNo));
72
+ continue;
73
+ }
74
+ const item = {};
75
+ let [key, value] = splitField(rest, lineNo);
76
+ if (value === undefined) {
77
+ [value, index] = parseNode(lines, index, level + 2);
78
+ }
79
+ item[key] = value;
80
+ while (index < lines.length && lines[index].level === level + 1 && !isListItem(lines[index].text)) {
81
+ const field = lines[index];
82
+ let [nestedKey, nestedValue] = splitField(field.text, field.lineNo);
83
+ index += 1;
84
+ if (Object.hasOwn(item, nestedKey)) {
85
+ throw new ConfigError(`line ${field.lineNo}: duplicate key ${nestedKey}`);
86
+ }
87
+ if (nestedValue === undefined) {
88
+ [nestedValue, index] = parseNode(lines, index, level + 2);
89
+ }
90
+ item[nestedKey] = nestedValue;
91
+ }
92
+ items.push(item);
93
+ }
94
+ return [items, index];
95
+ }
96
+
97
+ function parseMap(lines, index, level) {
98
+ const mapping = {};
99
+ while (index < lines.length && lines[index].level === level && !isListItem(lines[index].text)) {
100
+ const { text, lineNo } = lines[index];
101
+ let [key, value] = splitField(text, lineNo);
102
+ index += 1;
103
+ if (Object.hasOwn(mapping, key)) throw new ConfigError(`line ${lineNo}: duplicate key ${key}`);
104
+ if (value === undefined) {
105
+ [value, index] = parseNode(lines, index, level + 1);
106
+ }
107
+ mapping[key] = value;
108
+ }
109
+ return [mapping, index];
110
+ }
111
+
112
+ function hasField(text) {
113
+ return /^[^\s:"']+:(\s|$)/.test(text);
114
+ }
115
+
116
+ function splitField(text, lineNo) {
117
+ const match = /^([^\s:"']+):(?:\s+(.*))?$/.exec(text);
118
+ if (!match) throw new ConfigError(`line ${lineNo}: expected key: value`);
119
+ const [, key, raw] = match;
120
+ return [key, raw === undefined || raw === '' ? undefined : scalar(raw.trim(), lineNo)];
121
+ }
122
+
123
+ function scalar(text, lineNo) {
124
+ if (text.length >= 2 && (text[0] === '"' || text[0] === "'")) {
125
+ if (text.at(-1) !== text[0]) throw new ConfigError(`line ${lineNo}: unterminated quote`);
126
+ return text.slice(1, -1);
127
+ }
128
+ if (text === 'true') return true;
129
+ if (text === 'false') return false;
130
+ if (/^\d+$/.test(text)) return Number(text);
131
+ if (text.includes(': ') || text.endsWith(':')) {
132
+ throw new ConfigError(`line ${lineNo}: quote text that contains a colon`);
133
+ }
134
+ return text;
135
+ }
136
+
137
+ function where(lines, index, message) {
138
+ const lineNo = index < lines.length ? lines[index].lineNo : 'end';
139
+ return `line ${lineNo}: ${message}`;
140
+ }
package/package.json CHANGED
@@ -1,6 +1,58 @@
1
1
  {
2
2
  "name": "@edjbarron/ux-guard",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.6.1",
4
+ "type": "module",
5
+ "description": "Deterministic UX checks and advisory evidence, verdict, and recommendation reports.",
6
+ "license": "Apache-2.0",
7
+ "author": "Ed Barron",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/ebarron/ux-guard.git"
11
+ },
12
+ "bugs": {
13
+ "url": "https://github.com/ebarron/ux-guard/issues"
14
+ },
15
+ "homepage": "https://github.com/ebarron/ux-guard#readme",
16
+ "publishConfig": {
17
+ "access": "public",
18
+ "provenance": true
19
+ },
20
+ "files": [
21
+ "bin",
22
+ "docs",
23
+ "lib",
24
+ "skills",
25
+ "README.md",
26
+ "LICENSE",
27
+ "NOTICE"
28
+ ],
29
+ "bin": {
30
+ "ux-guard": "bin/ux-guard.mjs"
31
+ },
32
+ "exports": {
33
+ "./authoritative": "./lib/authoritative.mjs",
34
+ "./baselines": "./lib/baselines.mjs",
35
+ "./journey-policy": "./lib/journey-policy.mjs",
36
+ "./journeys": "./lib/journeys.mjs",
37
+ "./observations": "./lib/observations.mjs",
38
+ "./playwright": "./lib/playwright.mjs",
39
+ "./run-contract": "./lib/run-contract.mjs",
40
+ "./shards": "./lib/shards.mjs",
41
+ "./targets": "./lib/targets.mjs",
42
+ "./visuals": "./lib/visuals.mjs",
43
+ "./verdicts": "./lib/verdicts.mjs"
44
+ },
45
+ "engines": {
46
+ "node": ">=22"
47
+ },
48
+ "dependencies": {
49
+ "typescript": "5.9.3"
50
+ },
51
+ "scripts": {
52
+ "check:hygiene": "node scripts/check-product-hygiene.mjs",
53
+ "check:test-catalog": "node scripts/check-test-catalog.mjs",
54
+ "check:package": "node scripts/check-package.mjs",
55
+ "test": "node --test \"test/*.test.mjs\"",
56
+ "test:install": "node scripts/install-smoke.mjs"
57
+ }
58
+ }
@@ -0,0 +1,134 @@
1
+ ---
2
+ name: ux-guard
3
+ description: Uses ux-guard when users ask to set up ux-guard, audit UX, explain ux-guard results, detect UX regression from main, recommend UX improvements, or prepare a reviewed policy or baseline.
4
+ ---
5
+
6
+ # ux-guard
7
+
8
+ Use the repository's installed `ux-guard` CLI as the source of truth. The skill
9
+ interprets deterministic evidence and proposes reviewable next steps; it does
10
+ not turn observations into approval.
11
+
12
+ ## Find or install the local package
13
+
14
+ 1. Inspect the repository's package manifest and local dependencies for
15
+ `@edjbarron/ux-guard`.
16
+ 2. Resolve and invoke the repository-local `ux-guard` executable directly.
17
+ Keep package-runner mechanics out of the user-facing explanation.
18
+ 3. When the user asks to set up ux-guard and it is absent, install
19
+ `@edjbarron/ux-guard` as a development dependency with the repository's
20
+ package manager.
21
+ 4. For an audit-only request, do not silently install or fetch a missing
22
+ package. Report that executable evidence is unavailable and ask before
23
+ changing dependencies.
24
+
25
+ Never use a global installation when a local version is declared. Never claim
26
+ that ux-guard ran when the local executable could not be found or executed.
27
+
28
+ ## Set up a repository
29
+
30
+ 1. Run the local `setup` command in JSON mode from the repository root.
31
+ 2. Explain what source and signals were inspected.
32
+ 3. Group the output as:
33
+ - good observations;
34
+ - items needing attention;
35
+ - unknown or missing evidence.
36
+ 4. Present ordered, plain-English next steps generated from those findings:
37
+ - include use-case catalog work only when catalog evidence is missing;
38
+ - include pattern review only when pattern findings exist;
39
+ - include initial-baseline work only when baseline evidence is missing;
40
+ - include directly usable Agent Skill prompts for use-case and pattern work.
41
+ 5. Mention the setup supporting file only in the policy-and-baseline review
42
+ step. Explain that it records observed source roots, component and icon
43
+ usage, pattern counts, and unresolved policy choices and is not approval.
44
+ 6. End by stating that no policy, baseline, waiver, or enforcement was
45
+ activated.
46
+
47
+ Setup must not create active policy, approve observed defects, adopt a baseline,
48
+ add a waiver, or enable enforcement. If supporting review work already exists,
49
+ preserve it and report the no-overwrite failure.
50
+
51
+ ## Audit and explain
52
+
53
+ Run `check` in JSON mode for reviewed code-policy alignment. Run `report` in
54
+ JSON mode when journey reporting is configured and the user wants UX verdicts
55
+ or recommendations.
56
+
57
+ Report:
58
+
59
+ - every audited source scope, or grouped paths without dropping any;
60
+ - policy findings separately from advisory UX findings;
61
+ - good observations, items needing attention, and unknown evidence;
62
+ - journey completion states, including failed, skipped, unexecutable, and
63
+ infrastructure-error evidence without collapsing them;
64
+ - target attainment, regression, and numerical scores as separate meanings;
65
+ - concrete recommendations tied to evidence.
66
+
67
+ An exit code of `0` can still contain advisory UX findings. Exit `1` means an
68
+ enforceable catalog or pattern finding. Exit `2` means configuration, evidence,
69
+ or execution failed and must never be described as clean.
70
+
71
+ Never describe baseline equality or `unchanged` as good UX. It means only that
72
+ the measured state matches reviewed comparison evidence.
73
+
74
+ Offer these directly usable prompts when users want to explore those results:
75
+
76
+ - `Show me where ux-guard scoring comes from and explain every score`
77
+ - `Compare this branch with origin/main and explain every backslide signal; do not change policy or baselines`
78
+
79
+ ## Compare with a trusted base
80
+
81
+ For regression-from-main requests:
82
+
83
+ 1. Verify that the requested base resolves to a local commit.
84
+ 2. Run `check` and, when configured, `report` with that explicit trusted base.
85
+ 3. State which commit supplied policy and reviewed baselines.
86
+ 4. Keep missing, malformed, incompatible, shallow-clone, or unexecutable
87
+ evidence visible as unknown or unavailable.
88
+
89
+ Do not substitute working-tree policy, targets, or baselines when a trusted
90
+ base was requested. Do not report “no regression” when comparison evidence was
91
+ unavailable.
92
+
93
+ ## Prepare review work
94
+
95
+ The agent may prepare unapproved setup support, policy, journey-baseline, or
96
+ visual-baseline review work when asked. It may inspect and diff that work, but
97
+ it must stop before adoption or promotion and request explicit human approval.
98
+
99
+ Approval must name the exact review artifact and resulting files. It is one-time and
100
+ does not authorize:
101
+
102
+ - future promotions;
103
+ - waivers or exclusions;
104
+ - baseline growth;
105
+ - lowering severity or completeness;
106
+ - enabling enforcement.
107
+
108
+ Never add a waiver or baseline entry merely to make results green. Never treat
109
+ current defects as acceptable because they appear in a proposed baseline.
110
+
111
+ ## Recommend or repair
112
+
113
+ Prefer recommendations that improve the user's workflow, accessibility,
114
+ consistency, feedback, and recovery. Do not alter production UI merely to pass
115
+ ux-guard. If the user asks for implementation, explain the evidence and the
116
+ intended UX outcome before changing production code, then run relevant product
117
+ tests and rerun the same ux-guard audit.
118
+
119
+ Do not weaken policy, remove evidence, skip journeys, hide findings, or replace
120
+ real workflow evidence with fabricated data.
121
+
122
+ ## Final summary
123
+
124
+ Summarize:
125
+
126
+ - installed local version and audited scope;
127
+ - good, needs-attention, and unknown results;
128
+ - policy findings versus advisory findings;
129
+ - trusted base and whether comparison evidence executed;
130
+ - supporting review paths and their unapproved status;
131
+ - recommendations in priority order;
132
+ - exact validations that ran and any missing or unexecutable evidence;
133
+ - approvals still required before policy, promotion, waivers, baselines, or
134
+ enforcement can change.