@su-sws/synthetic-web-team 0.1.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.
Files changed (82) hide show
  1. package/AGENTS.md +149 -0
  2. package/README.md +321 -0
  3. package/package.json +58 -0
  4. package/packages/cli/bin/sws.mjs +722 -0
  5. package/packages/cli/src/axe.mjs +164 -0
  6. package/packages/cli/src/browser.mjs +192 -0
  7. package/packages/cli/src/checks.mjs +1254 -0
  8. package/packages/cli/src/github.mjs +131 -0
  9. package/packages/cli/src/history.mjs +137 -0
  10. package/packages/cli/src/perf.mjs +245 -0
  11. package/packages/cli/src/preflight.mjs +185 -0
  12. package/packages/cli/src/report.mjs +315 -0
  13. package/packages/cli/src/states.mjs +556 -0
  14. package/packages/wizard/bin/wizard.mjs +767 -0
  15. package/packages/wizard/src/detect.mjs +135 -0
  16. package/packages/wizard/src/emit.mjs +553 -0
  17. package/skills/role-accessibility-lead/SKILL.md +183 -0
  18. package/skills/role-api-architect/SKILL.md +65 -0
  19. package/skills/role-backend-developer/SKILL.md +66 -0
  20. package/skills/role-compliance-officer/SKILL.md +73 -0
  21. package/skills/role-content-designer/SKILL.md +145 -0
  22. package/skills/role-devops/SKILL.md +200 -0
  23. package/skills/role-discoverability/SKILL.md +164 -0
  24. package/skills/role-frontend-developer/SKILL.md +167 -0
  25. package/skills/role-fullstack-developer/SKILL.md +56 -0
  26. package/skills/role-identity-engineer/SKILL.md +77 -0
  27. package/skills/role-information-architect/SKILL.md +136 -0
  28. package/skills/role-infrastructure-architect/SKILL.md +60 -0
  29. package/skills/role-qa-engineer/SKILL.md +81 -0
  30. package/skills/role-security-operations/SKILL.md +56 -0
  31. package/skills/role-software-architect/SKILL.md +75 -0
  32. package/skills/role-staff-technical-architect/SKILL.md +73 -0
  33. package/skills/role-strategist/SKILL.md +122 -0
  34. package/skills/role-user-researcher/SKILL.md +66 -0
  35. package/skills/role-ux-designer/SKILL.md +159 -0
  36. package/skills/sws-compliance-check/SKILL.md +153 -0
  37. package/skills/sws-decanter/SKILL.md +191 -0
  38. package/skills/sws-deploy/SKILL.md +162 -0
  39. package/skills/sws-diverge/SKILL.md +131 -0
  40. package/skills/sws-github/SKILL.md +171 -0
  41. package/skills/sws-install/SKILL.md +97 -0
  42. package/skills/sws-netlify/SKILL.md +110 -0
  43. package/skills/sws-onboard/SKILL.md +85 -0
  44. package/skills/sws-preflight/SKILL.md +87 -0
  45. package/skills/sws-prior-art/SKILL.md +137 -0
  46. package/skills/sws-vercel/SKILL.md +117 -0
  47. package/standards/fragments/global-footer.yml +137 -0
  48. package/standards/fragments/identity-bar.yml +180 -0
  49. package/standards/hosting/capabilities.yml +215 -0
  50. package/standards/hosting/github-pages.yml +306 -0
  51. package/standards/hosting/netlify.yml +234 -0
  52. package/standards/hosting/vercel.yml +284 -0
  53. package/standards/patterns/components.md +162 -0
  54. package/standards/patterns/content.md +130 -0
  55. package/standards/patterns/decanter.md +352 -0
  56. package/standards/patterns/discoverability.md +121 -0
  57. package/standards/patterns/forms.md +116 -0
  58. package/standards/patterns/ia.md +126 -0
  59. package/standards/patterns/motion.md +267 -0
  60. package/standards/patterns/sws-conventions.md +225 -0
  61. package/standards/policy/accessibility.md +241 -0
  62. package/standards/policy/brand.md +213 -0
  63. package/standards/policy/escalation.md +53 -0
  64. package/standards/policy/identity.md +96 -0
  65. package/standards/policy/minsec.md +119 -0
  66. package/standards/policy/minweb.md +87 -0
  67. package/standards/policy/privacy.md +114 -0
  68. package/standards/policy/procurement.md +79 -0
  69. package/standards/prior-art/README.md +205 -0
  70. package/standards/prior-art/catalog.yml +409 -0
  71. package/standards/prior-art/patterns/INDEX.md +53 -0
  72. package/standards/prior-art/repos.yml +734 -0
  73. package/standards/recipes/astro-ssr/RECIPE.md +274 -0
  74. package/standards/recipes/astro-ssr/acceptance.yml +168 -0
  75. package/standards/recipes/astro-static/RECIPE.md +468 -0
  76. package/standards/recipes/astro-static/acceptance.yml +800 -0
  77. package/standards/recipes/next-ssr/RECIPE.md +407 -0
  78. package/standards/recipes/next-ssr/acceptance.yml +187 -0
  79. package/standards/scope.md +111 -0
  80. package/standards/stack/performance-budget.yml +95 -0
  81. package/standards/stack/reference-versions.yml +168 -0
  82. package/standards/stack/requirements.yml +154 -0
@@ -0,0 +1,185 @@
1
+ // System preflight: is the machine equipped to build and deploy this project?
2
+ //
3
+ // Reads standards/stack/requirements.yml and runs each tool's detect command.
4
+ // Deliberately does NOT know how to install anything -- see the header of that
5
+ // file for why. The contract with the agent is: check, install however you
6
+ // like, check again.
7
+ //
8
+ // Design, matching the rest of this CLI:
9
+ // - A tool that cannot be probed is `unknown`, never `pass`.
10
+ // - Exits 0 unless --strict, because nothing here blocks by default.
11
+
12
+ import { execFileSync } from 'node:child_process';
13
+ import { existsSync, readFileSync } from 'node:fs';
14
+ import { join } from 'node:path';
15
+ import YAML from 'yaml';
16
+
17
+ const SEMVER = /(\d+)\.(\d+)(?:\.(\d+))?/;
18
+
19
+ const parse = (s) => {
20
+ const m = SEMVER.exec(s || '');
21
+ return m ? [+m[1], +m[2], +(m[3] ?? 0)] : null;
22
+ };
23
+
24
+ const lt = (a, b) => {
25
+ for (let i = 0; i < 3; i++) {
26
+ if (a[i] !== b[i]) return a[i] < b[i];
27
+ }
28
+ return false;
29
+ };
30
+
31
+ // Run a detect command without a shell, so a manifest entry cannot become
32
+ // shell injection. Splitting on whitespace is enough: every detect command in
33
+ // requirements.yml is a plain `binary --flag`.
34
+ function probe(cmd) {
35
+ const [bin, ...args] = String(cmd).trim().split(/\s+/);
36
+ try {
37
+ const out = execFileSync(bin, args, {
38
+ encoding: 'utf8',
39
+ stdio: ['ignore', 'pipe', 'pipe'],
40
+ timeout: 20000,
41
+ });
42
+ return { ok: true, out: (out || '').trim() };
43
+ } catch (e) {
44
+ // ENOENT means not installed. A non-zero exit means present but unhappy,
45
+ // which is a different problem and worth saying differently.
46
+ const missing = e?.code === 'ENOENT';
47
+ return {
48
+ ok: false,
49
+ missing,
50
+ out: [e?.stdout, e?.stderr].filter(Boolean).join('\n').trim(),
51
+ err: e?.message || String(e),
52
+ };
53
+ }
54
+ }
55
+
56
+ function whichPackageManager(root) {
57
+ if (existsSync(join(root, 'yarn.lock'))) return 'yarn';
58
+ if (existsSync(join(root, 'pnpm-lock.yaml'))) return 'pnpm';
59
+ return 'npm';
60
+ }
61
+
62
+ function applies(tool, ctx) {
63
+ if (tool.required === 'always') return true;
64
+ if (!tool.required_when) return false;
65
+ // The only condition shape in the manifest today.
66
+ const m = /^hosting\.provider\s*==\s*(\S+)$/.exec(tool.required_when.trim());
67
+ if (m) return ctx.provider === m[1];
68
+ return false;
69
+ }
70
+
71
+ export function loadRequirements(standardsDir) {
72
+ const p = join(standardsDir, 'stack', 'requirements.yml');
73
+ if (!existsSync(p)) return null;
74
+ return YAML.parse(readFileSync(p, 'utf8'));
75
+ }
76
+
77
+ export function preflight({ standardsDir, root = process.cwd(), manifest = {} }) {
78
+ const req = loadRequirements(standardsDir);
79
+ if (!req) {
80
+ return {
81
+ results: [],
82
+ error: `No requirements.yml under ${standardsDir}/stack/. Point --standards at the standards directory.`,
83
+ };
84
+ }
85
+
86
+ const provider = manifest?.hosting?.provider ?? null;
87
+ const pm = whichPackageManager(root);
88
+ const ctx = { provider };
89
+ const results = [];
90
+
91
+ for (const tool of req.tools ?? []) {
92
+ // npm vs yarn: report the one the project actually uses, and never nag
93
+ // about converting. A yarn project does not need npm checked.
94
+ if (tool.id === 'npm' && pm !== 'npm') {
95
+ results.push({
96
+ id: tool.id,
97
+ name: `${pm} (this project's package manager)`,
98
+ state: 'skip',
99
+ detail: `${pm}.lock present, so ${pm} is the requirement here, not npm. Never convert a project.`,
100
+ required: true,
101
+ });
102
+ continue;
103
+ }
104
+
105
+ const needed = applies(tool, ctx);
106
+ if (!needed) {
107
+ results.push({
108
+ id: tool.id,
109
+ name: tool.name,
110
+ state: 'not_applicable',
111
+ detail: tool.required_when
112
+ ? `only needed when ${tool.required_when}` +
113
+ (provider ? ` (this project: ${provider})` : ' (no hosting.provider recorded yet)')
114
+ : 'not required for this project',
115
+ required: false,
116
+ });
117
+ continue;
118
+ }
119
+
120
+ const r = probe(tool.detect);
121
+ const entry = {
122
+ id: tool.id,
123
+ name: tool.name,
124
+ required: !tool.optional,
125
+ why: tool.why,
126
+ blocks: tool.blocks,
127
+ detect: tool.detect,
128
+ };
129
+
130
+ if (!r.ok) {
131
+ results.push({
132
+ ...entry,
133
+ state: r.missing ? 'missing' : 'unknown',
134
+ detail: r.missing
135
+ ? `not installed (\`${tool.detect}\` not found)`
136
+ : `installed but \`${tool.detect}\` failed: ${(r.out || r.err).split('\n')[0]}`,
137
+ });
138
+ continue;
139
+ }
140
+
141
+ const found = parse(r.out);
142
+ const floor = tool.version_min ? parse(tool.version_min) : null;
143
+ if (floor && found && lt(found, floor)) {
144
+ results.push({
145
+ ...entry,
146
+ state: 'too_old',
147
+ found: found.join('.'),
148
+ detail: `found ${found.join('.')}, needs >= ${tool.version_min}`,
149
+ });
150
+ continue;
151
+ }
152
+
153
+ results.push({
154
+ ...entry,
155
+ state: 'pass',
156
+ found: found ? found.join('.') : r.out.split('\n')[0],
157
+ detail: found ? found.join('.') : r.out.split('\n')[0],
158
+ });
159
+
160
+ // Secondary probe, e.g. gh installed vs gh authenticated. Reported
161
+ // separately because they are different failures with different fixes.
162
+ if (tool.also_check?.detect) {
163
+ const a = probe(tool.also_check.detect);
164
+ results.push({
165
+ id: `${tool.id}.auth`,
166
+ name: `${tool.name}: ${tool.also_check.what || 'secondary check'}`,
167
+ required: !tool.optional,
168
+ detect: tool.also_check.detect,
169
+ state: a.ok ? 'pass' : 'missing',
170
+ detail: a.ok
171
+ ? 'authenticated'
172
+ : `\`${tool.also_check.detect}\` failed. ${tool.also_check.note ? tool.also_check.note.split('\n')[0] : ''}`.trim(),
173
+ });
174
+ }
175
+ }
176
+
177
+ return { results, notRequired: req.not_required ?? [], packageManager: pm, provider };
178
+ }
179
+
180
+ export function summarise(results) {
181
+ const blocking = results.filter((r) => r.required && ['missing', 'too_old'].includes(r.state));
182
+ const unknown = results.filter((r) => r.state === 'unknown');
183
+ const optional = results.filter((r) => !r.required && ['missing', 'too_old'].includes(r.state));
184
+ return { blocking, unknown, optional, ready: blocking.length === 0 };
185
+ }
@@ -0,0 +1,315 @@
1
+ // Scoring and rendering.
2
+ //
3
+ // Scoring rules, which encode decisions rather than arithmetic:
4
+ //
5
+ // pass earns its weight
6
+ // fail earns nothing
7
+ // unknown COUNTS toward the total and earns nothing. A check that could
8
+ // not run must not flatter the score. If axe never ran, its 10
9
+ // points are withheld rather than excluded.
10
+ // acknowledged earns its weight, and the score is annotated. Earning zero
11
+ // would mean the score never recovers, and people would stop
12
+ // documenting risk acceptance, which is the behaviour we most
13
+ // want.
14
+ // not_applicable excluded from the total entirely.
15
+
16
+ // Grouping is by what the reader can DO, not by policy chapter. Note every
17
+ // test requires a non-passing state: a blocking check that PASSES is not a
18
+ // blocking finding, and an earlier version of this listed `minweb.no-secrets`
19
+ // under "Blocking launch" while it was green.
20
+ const GROUPS = [
21
+ ['Blocking launch', (f) => f.state === 'fail' && (f.blocking || f.weight >= 4)],
22
+ ['Should fix', (f) => f.state === 'fail' && f.weight >= 2],
23
+ ['Consider', (f) => f.state === 'fail'],
24
+ ['Could not check', (f) => f.state === 'unknown'],
25
+ ['Accepted risks', (f) => f.state === 'acknowledged'],
26
+ ];
27
+
28
+ export function score(findings) {
29
+ let earned = 0, possible = 0, ack = 0;
30
+ for (const f of findings) {
31
+ if (f.state === 'not_applicable' || !f.weight) continue;
32
+ possible += f.weight;
33
+ if (f.state === 'pass') earned += f.weight;
34
+ else if (f.state === 'acknowledged') { earned += f.weight; ack++; }
35
+ }
36
+ return {
37
+ value: possible ? Math.round((earned / possible) * 100) : 100,
38
+ earned, possible, acknowledged: ack,
39
+ };
40
+ }
41
+
42
+ export function group(findings) {
43
+ const seen = new Set();
44
+ const out = [];
45
+ for (const [name, test] of GROUPS) {
46
+ const items = findings.filter((f) => !seen.has(f.id) && test(f));
47
+ items.forEach((f) => seen.add(f.id));
48
+ if (items.length) out.push([name, items]);
49
+ }
50
+ return out;
51
+ }
52
+
53
+ const C = {
54
+ reset: '\x1b[0m', dim: '\x1b[2m', bold: '\x1b[1m',
55
+ red: '\x1b[31m', yellow: '\x1b[33m', green: '\x1b[32m', blue: '\x1b[36m',
56
+ };
57
+ const paint = (s, c) => (process.stdout.isTTY ? `${C[c]}${s}${C.reset}` : s);
58
+
59
+ const ICON = { pass: '+', fail: '!', unknown: '?', acknowledged: '~', not_applicable: '.' };
60
+
61
+ export function renderTerminal({ findings, sc, recipe, blocking }) {
62
+ const L = [];
63
+ L.push('');
64
+ L.push(paint(` Stanford compliance report`, 'bold') + paint(` ${recipe}`, 'dim'));
65
+ L.push('');
66
+
67
+ const bar = '#'.repeat(Math.round(sc.value / 5)).padEnd(20, '.');
68
+ const colour = sc.value >= 90 ? 'green' : sc.value >= 70 ? 'yellow' : 'red';
69
+ L.push(` ${paint(bar, colour)} ${paint(String(sc.value), 'bold')}/100` +
70
+ (sc.acknowledged ? paint(` (includes ${sc.acknowledged} accepted risk${sc.acknowledged > 1 ? 's' : ''})`, 'dim') : ''));
71
+ L.push('');
72
+
73
+ for (const [name, items] of group(findings)) {
74
+ const c = name === 'Blocking launch' ? 'red'
75
+ : name === 'Should fix' ? 'yellow'
76
+ : name === 'Could not check' ? 'blue' : 'dim';
77
+ L.push(` ${paint(name, c)}`);
78
+ for (const f of items) {
79
+ L.push(` ${ICON[f.state]} ${paint(f.id, 'bold')} ${f.detail}`);
80
+ if (f.fix) L.push(` ${paint('->', 'dim')} ${f.fix}`);
81
+ }
82
+ L.push('');
83
+ }
84
+
85
+ const passed = findings.filter((f) => f.state === 'pass').length;
86
+ L.push(paint(` ${passed} passing, ${findings.filter((f) => f.state === 'fail').length} to fix, ` +
87
+ `${findings.filter((f) => f.state === 'unknown').length} unchecked`, 'dim'));
88
+
89
+ // "Blocking launch" means fix before go-live. It does NOT mean the build
90
+ // fails, and saying so prevents people concluding the check is broken when
91
+ // CI stays green. Only committed credentials fail a build.
92
+ if (findings.some((f) => f.state === 'fail')) {
93
+ L.push(paint(' "Blocking launch" means fix before go-live, not that CI failed.', 'dim'));
94
+ L.push(paint(' Only a committed credential fails a build.', 'dim'));
95
+ }
96
+
97
+ // The honesty line. Never let a green report imply conformance.
98
+ L.push(paint(' Automated checks cover roughly 30% of accessibility issues (ODA).', 'dim'));
99
+ L.push(paint(' A passing run is a floor, not a conformance claim.', 'dim'));
100
+
101
+ if (blocking.length) {
102
+ L.push('');
103
+ L.push(paint(' BLOCKED: ' + blocking.map((b) => b.id).join(', '), 'red'));
104
+ }
105
+ L.push('');
106
+ return L.join('\n');
107
+ }
108
+
109
+ export function renderMarkdown({ findings, sc, recipe, blocking }) {
110
+ const L = [];
111
+ L.push(`## Stanford compliance report`);
112
+ L.push('');
113
+ L.push(`**Score ${sc.value}/100**` +
114
+ (sc.acknowledged ? ` (includes ${sc.acknowledged} accepted risk${sc.acknowledged > 1 ? 's' : ''})` : '') +
115
+ ` · recipe \`${recipe}\``);
116
+ L.push('');
117
+ if (blocking.length) {
118
+ L.push(`> **Blocked:** ${blocking.map((b) => `\`${b.id}\``).join(', ')}`);
119
+ L.push('');
120
+ }
121
+ for (const [name, items] of group(findings)) {
122
+ L.push(`<details${name === 'Blocking launch' ? ' open' : ''}><summary><strong>${name}</strong> (${items.length})</summary>`);
123
+ L.push('');
124
+ for (const f of items) {
125
+ L.push(`- \`${f.id}\` ${f.detail}`);
126
+ if (f.fix) L.push(` - ${f.fix}`);
127
+ }
128
+ L.push('');
129
+ L.push('</details>');
130
+ L.push('');
131
+ }
132
+ L.push('<sub>Automated checks cover roughly 30% of accessibility issues per ODA guidance. ' +
133
+ 'A passing run is a floor, not a conformance claim. Findings are advisory except committed secrets.</sub>');
134
+ return L.join('\n');
135
+ }
136
+
137
+ export function renderJson({ findings, sc, recipe, blocking }) {
138
+ return JSON.stringify({
139
+ recipe, score: sc, blocking: blocking.map((b) => b.id),
140
+ counts: ['pass', 'fail', 'unknown', 'acknowledged', 'not_applicable']
141
+ .reduce((a, s) => ({ ...a, [s]: findings.filter((f) => f.state === s).length }), {}),
142
+ findings,
143
+ }, null, 2);
144
+ }
145
+
146
+ // ---------------------------------------------------------------------------
147
+ // Destinations. Rendering is separated from publishing (github.mjs) so every
148
+ // body below can be built and inspected without a network or a token.
149
+ // ---------------------------------------------------------------------------
150
+
151
+ const band = (v) => (v >= 90 ? 'brightgreen' : v >= 70 ? 'yellow' : v >= 50 ? 'orange' : 'red');
152
+
153
+ /** Arrow for a delta. Neutral when flat: an unchanged score is not bad news. */
154
+ const arrow = (d) => (d > 0 ? '▲' : d < 0 ? '▼' : '·');
155
+
156
+ function honestyFooter() {
157
+ return '<sub>Automated checks cover roughly 30% of accessibility issues per ODA guidance. ' +
158
+ 'A passing run is a floor, not a conformance claim. Everything is advisory except committed secrets.</sub>';
159
+ }
160
+
161
+ /**
162
+ * The PR comment. One per PR, updated in place.
163
+ *
164
+ * Deliberately short at the top: score, trend, and what changed. The plan's
165
+ * example is "88, down from 94, three new contrast findings in Hero.astro" —
166
+ * the delta and its cause matter more than the full list, which is collapsed.
167
+ */
168
+ export function renderPrComment({ findings, sc, recipe, blocking }, { trend, runUrl } = {}) {
169
+ const L = [];
170
+ const t = trend ? ` ${arrow(trend.delta)} ${trend.text}` : '';
171
+ L.push(`### Stanford compliance report — **${sc.value}/100**${t}`);
172
+ L.push('');
173
+
174
+ const fails = findings.filter((f) => f.state === 'fail');
175
+ const unknowns = findings.filter((f) => f.state === 'unknown');
176
+ L.push(`\`${recipe}\` · ${findings.filter((f) => f.state === 'pass').length} passing · ` +
177
+ `${fails.length} to fix · ${unknowns.length} unchecked` +
178
+ (sc.acknowledged ? ` · ${sc.acknowledged} accepted risk${sc.acknowledged > 1 ? 's' : ''}` : ''));
179
+ L.push('');
180
+
181
+ if (blocking.length) {
182
+ L.push(`> [!CAUTION]`);
183
+ L.push(`> **This is the one thing that fails a build:** ${blocking.map((b) => `\`${b.id}\``).join(', ')}.`);
184
+ L.push(`> Rotate the credential first — blocking the deploy does not un-leak it.`);
185
+ L.push('');
186
+ } else if (!fails.length) {
187
+ L.push(`> [!NOTE]`);
188
+ L.push(`> No automated failures. Nothing here blocks the build in any case.`);
189
+ L.push('');
190
+ }
191
+
192
+ // The biggest available win, named. A list of twelve findings gets skimmed;
193
+ // one specific next action gets done.
194
+ const worst = [...fails].sort((a, b) => b.weight - a.weight)[0];
195
+ if (worst) {
196
+ L.push(`**Biggest win available:** \`${worst.id}\` (${worst.weight} point${worst.weight === 1 ? '' : 's'}) — ${worst.detail}`);
197
+ L.push('');
198
+ }
199
+
200
+ L.push(renderMarkdown({ findings, sc, recipe, blocking: [] }).split('\n').slice(4).join('\n'));
201
+ if (runUrl) L.push(`\n[Full run](${runUrl}) · the HTML report is attached to it as an artifact.`);
202
+ return L.join('\n');
203
+ }
204
+
205
+ /**
206
+ * The persistent "Site health" issue body.
207
+ *
208
+ * Findable by someone who has never opened the Actions tab, notifies watchers,
209
+ * and accumulates history in its own edit trail. The score history is embedded
210
+ * as an HTML comment by history.embedInBody(); the caller appends it.
211
+ */
212
+ export function renderIssueBody({ findings, sc, recipe, blocking }, { trend, spark, runUrl, sha, updatedAt } = {}) {
213
+ const L = [];
214
+ L.push(`# Site health — ${sc.value}/100`);
215
+ L.push('');
216
+ if (trend) L.push(`**${arrow(trend.delta)} ${trend.text}**`);
217
+ if (spark) L.push(`\`${spark}\` <sub>last ${spark.length} runs, 0–100 scale</sub>`);
218
+ L.push('');
219
+ L.push(`Recipe \`${recipe}\` · updated ${updatedAt ?? new Date().toISOString()}` +
220
+ (sha ? ` · \`${String(sha).slice(0, 7)}\`` : ''));
221
+ L.push('');
222
+ L.push('This issue is rewritten in place on every push to the default branch. ' +
223
+ 'It is not a task list and closing it will not stop the checks — reopen or ' +
224
+ 'delete it and the next run recreates it.');
225
+ L.push('');
226
+
227
+ if (blocking.length) {
228
+ L.push(`> [!CAUTION]`);
229
+ L.push(`> **${blocking.map((b) => `\`${b.id}\``).join(', ')}** — the only finding type that fails a build.`);
230
+ L.push('');
231
+ }
232
+
233
+ L.push(renderMarkdown({ findings, sc, recipe, blocking: [] }).split('\n').slice(4).join('\n'));
234
+ if (runUrl) L.push(`\n[Latest run](${runUrl})`);
235
+ L.push('');
236
+ L.push(honestyFooter());
237
+ return L.join('\n');
238
+ }
239
+
240
+ /**
241
+ * shields.io endpoint payload, for a README badge.
242
+ *
243
+ * Written as a file rather than pushed anywhere: deploy it with the site and
244
+ * point shields at the deployed URL, so the badge needs no gist, no secret, and
245
+ * no third-party service beyond shields itself.
246
+ */
247
+ export function renderBadge(sc) {
248
+ return JSON.stringify({
249
+ schemaVersion: 1,
250
+ label: 'Stanford compliance',
251
+ message: `${sc.value}/100`,
252
+ color: band(sc.value),
253
+ });
254
+ }
255
+
256
+ /** Standalone HTML report, for the CI artifact. No assets, no network. */
257
+ export function renderHtml({ findings, sc, recipe, blocking }, { trend, spark, sha, runUrl } = {}) {
258
+ const esc = (s) => String(s ?? '').replace(/[&<>"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c]));
259
+ const rows = group(findings).map(([name, items]) => `
260
+ <section>
261
+ <h2>${esc(name)} <span class="count">${items.length}</span></h2>
262
+ <table>
263
+ <thead><tr><th>Criterion</th><th>Detail</th><th>Wt</th></tr></thead>
264
+ <tbody>${items.map((f) => `
265
+ <tr class="${esc(f.state)}">
266
+ <td><code>${esc(f.id)}</code>${f.policy ? `<div class="policy">${esc(f.policy)}</div>` : ''}</td>
267
+ <td>${esc(f.detail)}${f.fix ? `<div class="fix">${esc(f.fix)}</div>` : ''}</td>
268
+ <td>${f.weight || ''}</td>
269
+ </tr>`).join('')}
270
+ </tbody>
271
+ </table>
272
+ </section>`).join('');
273
+
274
+ return `<!doctype html>
275
+ <html lang="en"><head><meta charset="utf-8">
276
+ <meta name="viewport" content="width=device-width,initial-scale=1">
277
+ <title>Stanford compliance report — ${sc.value}/100</title>
278
+ <style>
279
+ :root { --cardinal:#8C1515; --ink:#2E2D29; --line:#e3e3e1; }
280
+ *{box-sizing:border-box}
281
+ body{font:16px/1.5 -apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,sans-serif;
282
+ color:var(--ink);margin:0;padding:2rem 1.5rem;max-width:60rem;margin-inline:auto}
283
+ h1{font-size:1.5rem;margin:0 0 .25rem}
284
+ .score{font-size:3rem;font-weight:700;line-height:1;color:var(--cardinal)}
285
+ .meta{color:#5f5e5b;font-size:.875rem}
286
+ .spark{font-family:ui-monospace,monospace;font-size:1.25rem;letter-spacing:1px}
287
+ section{margin-top:2rem}
288
+ h2{font-size:1.05rem;border-bottom:2px solid var(--line);padding-bottom:.35rem}
289
+ .count{color:#5f5e5b;font-weight:400;font-size:.875rem}
290
+ table{width:100%;border-collapse:collapse;font-size:.9rem}
291
+ th{text-align:left;color:#5f5e5b;font-weight:600;font-size:.8rem;padding:.4rem .5rem}
292
+ td{padding:.5rem;border-top:1px solid var(--line);vertical-align:top}
293
+ code{font-family:ui-monospace,monospace;font-size:.85em}
294
+ .fix,.policy{color:#5f5e5b;font-size:.85em;margin-top:.25rem}
295
+ tr.fail td:first-child{border-left:3px solid var(--cardinal)}
296
+ tr.unknown td:first-child{border-left:3px solid #b9b6b0}
297
+ tr.acknowledged td:first-child{border-left:3px solid #7a9a01}
298
+ footer{margin-top:2.5rem;padding-top:1rem;border-top:1px solid var(--line);
299
+ color:#5f5e5b;font-size:.85rem}
300
+ </style></head><body>
301
+ <h1>Stanford compliance report</h1>
302
+ <div class="score">${sc.value}<span style="font-size:1rem;color:#5f5e5b">/100</span></div>
303
+ ${trend ? `<p class="meta">${esc(arrow(trend.delta))} ${esc(trend.text)}</p>` : ''}
304
+ ${spark ? `<p class="spark">${esc(spark)}</p>` : ''}
305
+ <p class="meta">Recipe <code>${esc(recipe)}</code>${sha ? ` · <code>${esc(String(sha).slice(0, 7))}</code>` : ''}
306
+ · ${new Date().toISOString()}${runUrl ? ` · <a href="${esc(runUrl)}">run</a>` : ''}</p>
307
+ ${blocking.length ? `<p class="meta"><strong>Blocked:</strong> ${blocking.map((b) => esc(b.id)).join(', ')}</p>` : ''}
308
+ ${rows}
309
+ <footer>
310
+ Automated checks cover roughly <strong>30%</strong> of accessibility issues per ODA guidance.
311
+ A passing run is a floor, not a conformance claim. Everything is advisory except committed secrets.
312
+ </footer>
313
+ </body></html>
314
+ `;
315
+ }