@edjbarron/ux-guard 0.0.0-stage → 0.6.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/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.0",
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,122 @@
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. Name the setup proposal path and state that it is unapproved.
37
+ 5. Recommend the smallest safe review step needed to complete catalog and
38
+ policy decisions.
39
+
40
+ Setup must not create active policy, approve observed defects, adopt a baseline,
41
+ add a waiver, or enable enforcement. If a proposal already exists, preserve it
42
+ and report the no-overwrite failure.
43
+
44
+ ## Audit and explain
45
+
46
+ Run `check` in JSON mode for reviewed code-policy alignment. Run `report` in
47
+ JSON mode when journey reporting is configured and the user wants UX verdicts
48
+ or recommendations.
49
+
50
+ Report:
51
+
52
+ - every audited source scope, or grouped paths without dropping any;
53
+ - policy findings separately from advisory UX findings;
54
+ - good observations, items needing attention, and unknown evidence;
55
+ - journey completion states, including failed, skipped, unexecutable, and
56
+ infrastructure-error evidence without collapsing them;
57
+ - target attainment, regression, and numerical scores as separate meanings;
58
+ - concrete recommendations tied to evidence.
59
+
60
+ An exit code of `0` can still contain advisory UX findings. Exit `1` means an
61
+ enforceable catalog or pattern finding. Exit `2` means configuration, evidence,
62
+ or execution failed and must never be described as clean.
63
+
64
+ Never describe baseline equality or `unchanged` as good UX. It means only that
65
+ the measured state matches reviewed comparison evidence.
66
+
67
+ ## Compare with a trusted base
68
+
69
+ For regression-from-main requests:
70
+
71
+ 1. Verify that the requested base resolves to a local commit.
72
+ 2. Run `check` and, when configured, `report` with that explicit trusted base.
73
+ 3. State which commit supplied policy and reviewed baselines.
74
+ 4. Keep missing, malformed, incompatible, shallow-clone, or unexecutable
75
+ evidence visible as unknown or unavailable.
76
+
77
+ Do not substitute working-tree policy, targets, or baselines when a trusted
78
+ base was requested. Do not report “no regression” when comparison evidence was
79
+ unavailable.
80
+
81
+ ## Prepare proposals
82
+
83
+ The agent may prepare an unapproved setup, policy, journey-baseline, or visual
84
+ baseline proposal when asked. It may inspect and diff proposals, but it must
85
+ stop before adoption or promotion and request explicit human approval.
86
+
87
+ Approval must name the exact proposal and resulting files. It is one-time and
88
+ does not authorize:
89
+
90
+ - future promotions;
91
+ - waivers or exclusions;
92
+ - baseline growth;
93
+ - lowering severity or completeness;
94
+ - enabling enforcement.
95
+
96
+ Never add a waiver or baseline entry merely to make results green. Never treat
97
+ current defects as acceptable because they appear in a proposed baseline.
98
+
99
+ ## Recommend or repair
100
+
101
+ Prefer recommendations that improve the user's workflow, accessibility,
102
+ consistency, feedback, and recovery. Do not alter production UI merely to pass
103
+ ux-guard. If the user asks for implementation, explain the evidence and the
104
+ intended UX outcome before changing production code, then run relevant product
105
+ tests and rerun the same ux-guard audit.
106
+
107
+ Do not weaken policy, remove evidence, skip journeys, hide findings, or replace
108
+ real workflow evidence with fabricated data.
109
+
110
+ ## Final summary
111
+
112
+ Summarize:
113
+
114
+ - installed local version and audited scope;
115
+ - good, needs-attention, and unknown results;
116
+ - policy findings versus advisory findings;
117
+ - trusted base and whether comparison evidence executed;
118
+ - proposal paths and their unapproved status;
119
+ - recommendations in priority order;
120
+ - exact validations that ran and any missing or unexecutable evidence;
121
+ - approvals still required before policy, promotion, waivers, baselines, or
122
+ enforcement can change.