@su-sws/synthetic-web-team 0.2.1 → 0.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@su-sws/synthetic-web-team",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Stanford Web Services standards and agent team: policy, patterns, recipes, fragments, prior art, 31 skills, the two-part install wizard, and the advisory compliance CLI.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "repository": {
@@ -9,7 +9,7 @@
9
9
  },
10
10
  "scripts": {
11
11
  "sync-skills": "node scripts/sync-skills.mjs",
12
- "validate": "node scripts/validate-skills.mjs && node scripts/validate-emit.mjs && node scripts/validate-install.mjs && node scripts/validate-criteria.mjs && node scripts/validate-state-classifier.mjs && node scripts/validate-hooks.mjs && node scripts/validate-acknowledged.mjs",
12
+ "validate": "node scripts/validate-skills.mjs && node scripts/validate-emit.mjs && node scripts/validate-install.mjs && node scripts/validate-criteria.mjs && node scripts/validate-state-classifier.mjs && node scripts/validate-hooks.mjs && node scripts/validate-acknowledged.mjs && node scripts/validate-layouts.mjs && node scripts/validate-divergences.mjs",
13
13
  "check": "npm run validate && npm run sync-skills -- --check",
14
14
  "pack:all": "mkdir -p .pack && npm pack --pack-destination ./.pack && npm pack -w @su-sws/synthetic-web-team-mcp --pack-destination ./.pack"
15
15
  },
@@ -25,6 +25,7 @@ import * as gh from '../src/github.mjs';
25
25
  import { preflight, summarise } from '../src/preflight.mjs';
26
26
  import { findStandards as locateStandards } from '../src/standards.mjs';
27
27
  import { loadAcknowledged, applyAcknowledgements, sha256 } from '../src/acknowledged.mjs';
28
+ import { loadDivergences, applyDivergences } from '../src/divergences.mjs';
28
29
  // Sibling directory inside the same published package (@su-sws/synthetic-web-team), so this
29
30
  // relative path resolves in the repository and in a tarball alike. One reader
30
31
  // of the install record means the CLI and the wizard cannot disagree about what
@@ -255,10 +256,13 @@ async function run() {
255
256
  // criterion still reports, at weight 0, so a check is never silently dropped.
256
257
  const byId = new Map((acceptance.criteria || []).map((c) => [c.id, c]));
257
258
  const ack = loadAcknowledged(root);
259
+ const divergences = loadDivergences(root);
258
260
  const now = new Date();
259
261
 
260
262
  // An acknowledgement covers what it names, not the whole check: see
261
263
  // src/acknowledged.mjs. Entries a blocking check cannot honour are reported.
264
+ // Then a divergence that names a check still failing explains it, for checks
265
+ // that are preferences rather than requirements: see src/divergences.mjs.
262
266
  const findings = raw.map((f) => {
263
267
  const c = byId.get(f.id) || {};
264
268
  const blocking = Boolean(f.blocking || c.severity === 'block');
@@ -267,13 +271,18 @@ async function run() {
267
271
  if (a?.ignored.length) {
268
272
  console.error(` warning: ${a.ignored.length} acknowledgement(s) for ${f.id} ignored; the report says why.`);
269
273
  }
274
+ const afterAck = { ...f, state: a?.state ?? f.state, detail: a?.detail ?? f.detail };
275
+ const d = applyDivergences(afterAck, divergences, { blocking, policy: c.policy ?? null });
276
+ if (d?.ignored.length) {
277
+ console.error(` warning: ${d.ignored.length} divergence(s) naming ${f.id} ignored; the report says why.`);
278
+ }
270
279
  // The value hashes were for matching entries, just above. Nothing below
271
280
  // this line, no report, comment or artifact, gets to see them.
272
281
  const locations = (a?.locations ?? f.locations)?.map(({ sha256: _hash, ...l }) => l);
273
282
  return {
274
283
  ...f,
275
- state: a?.state ?? f.state,
276
- detail: a?.detail ?? f.detail,
284
+ state: d?.state ?? afterAck.state,
285
+ detail: d?.detail ?? afterAck.detail,
277
286
  ...(locations ? { locations } : {}),
278
287
  weight: c.weight ?? 0,
279
288
  severity: c.severity ?? 'warn',
@@ -61,6 +61,44 @@ function installed(root, name) {
61
61
  return existsSync(p) ? JSON.parse(read(p)) : null;
62
62
  }
63
63
 
64
+ // The project's own source files, relative to root and sorted shallowest first,
65
+ // wherever the project keeps them. Recipes disagree on the layout: Astro puts
66
+ // everything under src/, Next keeps styles/ and app/ at the root or under src/.
67
+ // A check that guesses one folder reports a fail on every project laid out the
68
+ // other way, so source checks search the whole project instead.
69
+ //
70
+ // Through git when it can, tracked files plus untracked ones git would not
71
+ // ignore, so .gitignore decides what is build output and no list of folder
72
+ // names goes stale. node_modules is never source, ignored or not. Outside a
73
+ // repository, walk the tree and skip node_modules, dot-folders and the usual
74
+ // build output.
75
+ const NOT_SOURCE = new Set(['node_modules', 'dist', '_site', 'build', 'out']);
76
+
77
+ export function projectFiles(root) {
78
+ let files;
79
+ try {
80
+ files = execFileSync('git', ['ls-files', '-z', '--cached', '--others', '--exclude-standard'],
81
+ { cwd: root, encoding: 'utf8', maxBuffer: 256 * 1024 * 1024, stdio: ['ignore', 'pipe', 'ignore'] })
82
+ .split('\0').filter(Boolean)
83
+ .filter((f) => !f.split('/').includes('node_modules'))
84
+ // A file deleted but not yet staged is still listed.
85
+ .filter((f) => existsSync(join(root, f)));
86
+ } catch {
87
+ files = [];
88
+ (function walk(d) {
89
+ if (!existsSync(d)) return;
90
+ for (const n of readdirSync(d)) {
91
+ const p = join(d, n);
92
+ if (statSync(p).isDirectory()) {
93
+ if (!n.startsWith('.') && !NOT_SOURCE.has(n)) walk(p);
94
+ } else files.push(relative(root, p));
95
+ }
96
+ })(root);
97
+ }
98
+ const depth = (f) => f.split('/').length;
99
+ return files.sort((a, b) => depth(a) - depth(b) || a.localeCompare(b));
100
+ }
101
+
64
102
  // --------------------------------------------------------------------------
65
103
  // footer: reads the contract, never hardcodes the link set
66
104
  // --------------------------------------------------------------------------
@@ -358,17 +396,10 @@ export function decanter({ root }) {
358
396
  'Dead package: supports neither current Astro nor Tailwind 4. Use @tailwindcss/vite.')
359
397
  : ok('decanter.no-dead-integration', '@astrojs/tailwind absent'));
360
398
 
361
- // Entry CSS: redundant tailwind import, and the @source myth.
362
- const cssFiles = [];
363
- (function walk(d) {
364
- if (!existsSync(d)) return;
365
- for (const n of readdirSync(d)) {
366
- const p = join(d, n);
367
- if (statSync(p).isDirectory()) { if (n !== 'node_modules') walk(p); }
368
- else if (n.endsWith('.css')) cssFiles.push(p);
369
- }
370
- })(join(root, 'src'));
371
-
399
+ // Entry CSS: redundant tailwind import, and the @source myth. Searched across
400
+ // the project, because Astro keeps it in src/styles/ and Next in styles/ or
401
+ // app/, at the root or under src/.
402
+ const cssFiles = projectFiles(root).filter((f) => f.endsWith('.css')).map((f) => join(root, f));
372
403
  const entry = cssFiles.find((f) => /@import\s+['"]decanter['"]/.test(read(f)));
373
404
  if (!entry) {
374
405
  out.push(d ? bad('decanter.entry-css', 'no CSS file imports decanter',
@@ -1418,18 +1449,13 @@ export function next({ root, html }) {
1418
1449
  : ok('next.no-tailwind-config', 'no tailwind JS config'));
1419
1450
 
1420
1451
  // metadataBase is the Next equivalent of Astro's `site`, and the same miss.
1421
- const layouts = [];
1422
- (function walk(d) {
1423
- if (!existsSync(d)) return;
1424
- for (const n of readdirSync(d)) {
1425
- const p = join(d, n);
1426
- if (statSync(p).isDirectory()) { if (n !== 'node_modules') walk(p); }
1427
- else if (/^layout\.(t|j)sx?$/.test(n)) layouts.push(p);
1428
- }
1429
- })(join(root, 'app'));
1452
+ // Next takes the App Router from app/ or, when that is absent, src/app/.
1453
+ const layouts = projectFiles(root)
1454
+ .filter((f) => /^(src\/)?app\/(.+\/)?layout\.(t|j)sx?$/.test(f))
1455
+ .map((f) => join(root, f));
1430
1456
 
1431
1457
  if (!layouts.length) {
1432
- out.push(dunno('next.metadata-base', 'no app/layout file found; App Router expected'));
1458
+ out.push(dunno('next.metadata-base', 'no layout file in app/ or src/app/; App Router expected'));
1433
1459
  } else {
1434
1460
  const hit = layouts.find((f) => /metadataBase/.test(read(f)));
1435
1461
  out.push(hit
@@ -0,0 +1,68 @@
1
+ // Divergences that cover checks.
2
+ //
3
+ // A divergence in .sws/manifest.yml records a deliberate departure from the
4
+ // recipe. Naming the checks it explains, in `checks:`, moves those findings out
5
+ // of the nag and into a "Divergences" section of the report, with the reason
6
+ // beside them. Without that, a choice made on purpose and written down still
7
+ // read as "Should fix" on every run, and the only way to quiet it was an
8
+ // accepted risk with a review date, which says "fix later" about something that
9
+ // will never change.
10
+ //
11
+ // A divergence covers a preference, never a requirement. Checks whose criterion
12
+ // carries a policy (accessibility, brand, MinWeb, MinSec, MinPriv) are what the
13
+ // sws-diverge skill calls "what never bends": a person can still decline one,
14
+ // in .sws/acknowledged.yml, where it stays an accepted risk with a review date.
15
+ // So an entry naming one is ignored, and the report says so.
16
+
17
+ import { existsSync, readFileSync } from 'node:fs';
18
+ import { join } from 'node:path';
19
+ import YAML from 'yaml';
20
+
21
+ /** Policies a divergence may cover: SWS's own conventions, and unclassified criteria. */
22
+ const PREFERENCE = new Set(['patterns', null, undefined]);
23
+
24
+ /** The manifest's divergences that name at least one check, with `checks` as an array. */
25
+ export function loadDivergences(root) {
26
+ const p = join(root, '.sws', 'manifest.yml');
27
+ if (!existsSync(p)) return [];
28
+ let m;
29
+ try { m = YAML.parse(readFileSync(p, 'utf8')) || {}; } catch { return []; }
30
+ const divs = Array.isArray(m.divergences) ? m.divergences : [];
31
+ return divs
32
+ .map((d) => ({ ...d, checks: [].concat(d?.checks ?? []).filter((c) => typeof c === 'string') }))
33
+ .filter((d) => d.checks.length);
34
+ }
35
+
36
+ /**
37
+ * Applies the divergences that name a failing finding.
38
+ *
39
+ * Returns null when none names it or the finding is not a failure. Otherwise
40
+ * `{ state, detail, ignored }`: `diverged` with the reason when an entry covers
41
+ * it, or the finding's own state with a note when every entry naming it was
42
+ * ignored because the check is a requirement.
43
+ */
44
+ export function applyDivergences(finding, divergences, { blocking, policy }) {
45
+ if (finding.state !== 'fail') return null;
46
+ const entries = divergences.filter((d) => d.checks.includes(finding.id));
47
+ if (!entries.length) return null;
48
+
49
+ if (blocking || !PREFERENCE.has(policy)) {
50
+ const why = blocking ? 'it is the blocking check' : `it is a ${policy} requirement`;
51
+ return {
52
+ state: finding.state,
53
+ detail: `${finding.detail} (divergence ignored: ${why}, so a divergence cannot cover it; ` +
54
+ 'accept the risk in .sws/acknowledged.yml instead)',
55
+ ignored: entries,
56
+ };
57
+ }
58
+
59
+ const reasons = [...new Set(entries.map((d) => d.reason).filter(Boolean))];
60
+ const what = [...new Set(entries.map((d) => d.changed).filter(Boolean))];
61
+ const note = reasons.length === 1 ? `: ${String(reasons[0]).trim().replace(/\s+/g, ' ')}` : '';
62
+ const label = what.length === 1 ? String(what[0]).trim().replace(/\s+/g, ' ') : 'recorded in .sws/manifest.yml';
63
+ return {
64
+ state: 'diverged',
65
+ detail: `${finding.detail} (divergence: ${label}${note})`,
66
+ ignored: [],
67
+ };
68
+ }
@@ -132,6 +132,7 @@ export function entryFor({ score, findings, sha, ref, runId }) {
132
132
  fail: findings.filter((f) => f.state === 'fail').length,
133
133
  unknown: findings.filter((f) => f.state === 'unknown').length,
134
134
  acknowledged: findings.filter((f) => f.state === 'acknowledged').length,
135
+ diverged: findings.filter((f) => f.state === 'diverged').length,
135
136
  },
136
137
  };
137
138
  }
@@ -11,6 +11,9 @@
11
11
  // would mean the score never recovers, and people would stop
12
12
  // documenting risk acceptance, which is the behaviour we most
13
13
  // want.
14
+ // diverged earns its weight, and the score is annotated, for the same
15
+ // reason: a deliberate choice written down is the behaviour the
16
+ // contract asks for. Only preferences can be diverged from.
14
17
  // not_applicable excluded from the total entirely.
15
18
 
16
19
  // Grouping is by what the reader can DO, not by policy chapter. Note every
@@ -23,22 +26,34 @@ const GROUPS = [
23
26
  ['Consider', (f) => f.state === 'fail'],
24
27
  ['Could not check', (f) => f.state === 'unknown'],
25
28
  ['Accepted risks', (f) => f.state === 'acknowledged'],
29
+ ['Divergences', (f) => f.state === 'diverged'],
26
30
  ];
27
31
 
28
32
  export function score(findings) {
29
- let earned = 0, possible = 0, ack = 0;
33
+ let earned = 0, possible = 0, ack = 0, div = 0;
30
34
  for (const f of findings) {
31
35
  if (f.state === 'not_applicable' || !f.weight) continue;
32
36
  possible += f.weight;
33
37
  if (f.state === 'pass') earned += f.weight;
34
38
  else if (f.state === 'acknowledged') { earned += f.weight; ack++; }
39
+ else if (f.state === 'diverged') { earned += f.weight; div++; }
35
40
  }
36
41
  return {
37
42
  value: possible ? Math.round((earned / possible) * 100) : 100,
38
- earned, possible, acknowledged: ack,
43
+ earned, possible, acknowledged: ack, diverged: div,
39
44
  };
40
45
  }
41
46
 
47
+ const plural = (n, word) => `${n} ${word}${n > 1 ? 's' : ''}`;
48
+
49
+ /** What the score includes besides passes, e.g. "1 accepted risk, 2 divergences", or ''. */
50
+ export function includes(sc) {
51
+ return [
52
+ sc.acknowledged ? plural(sc.acknowledged, 'accepted risk') : '',
53
+ sc.diverged ? plural(sc.diverged, 'divergence') : '',
54
+ ].filter(Boolean).join(', ');
55
+ }
56
+
42
57
  export function group(findings) {
43
58
  const seen = new Set();
44
59
  const out = [];
@@ -56,7 +71,7 @@ const C = {
56
71
  };
57
72
  const paint = (s, c) => (process.stdout.isTTY ? `${C[c]}${s}${C.reset}` : s);
58
73
 
59
- const ICON = { pass: '+', fail: '!', unknown: '?', acknowledged: '~', not_applicable: '.' };
74
+ const ICON = { pass: '+', fail: '!', unknown: '?', acknowledged: '~', diverged: '=', not_applicable: '.' };
60
75
 
61
76
  export function renderTerminal({ findings, sc, recipe, blocking }) {
62
77
  const L = [];
@@ -67,7 +82,7 @@ export function renderTerminal({ findings, sc, recipe, blocking }) {
67
82
  const bar = '#'.repeat(Math.round(sc.value / 5)).padEnd(20, '.');
68
83
  const colour = sc.value >= 90 ? 'green' : sc.value >= 70 ? 'yellow' : 'red';
69
84
  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') : ''));
85
+ (includes(sc) ? paint(` (includes ${includes(sc)})`, 'dim') : ''));
71
86
  L.push('');
72
87
 
73
88
  for (const [name, items] of group(findings)) {
@@ -111,7 +126,7 @@ export function renderMarkdown({ findings, sc, recipe, blocking }) {
111
126
  L.push(`## Stanford compliance report`);
112
127
  L.push('');
113
128
  L.push(`**Score ${sc.value}/100**` +
114
- (sc.acknowledged ? ` (includes ${sc.acknowledged} accepted risk${sc.acknowledged > 1 ? 's' : ''})` : '') +
129
+ (includes(sc) ? ` (includes ${includes(sc)})` : '') +
115
130
  ` · recipe \`${recipe}\``);
116
131
  L.push('');
117
132
  if (blocking.length) {
@@ -137,7 +152,7 @@ export function renderMarkdown({ findings, sc, recipe, blocking }) {
137
152
  export function renderJson({ findings, sc, recipe, blocking }) {
138
153
  return JSON.stringify({
139
154
  recipe, score: sc, blocking: blocking.map((b) => b.id),
140
- counts: ['pass', 'fail', 'unknown', 'acknowledged', 'not_applicable']
155
+ counts: ['pass', 'fail', 'unknown', 'acknowledged', 'diverged', 'not_applicable']
141
156
  .reduce((a, s) => ({ ...a, [s]: findings.filter((f) => f.state === s).length }), {}),
142
157
  findings,
143
158
  }, null, 2);
@@ -175,7 +190,7 @@ export function renderPrComment({ findings, sc, recipe, blocking }, { trend, run
175
190
  const unknowns = findings.filter((f) => f.state === 'unknown');
176
191
  L.push(`\`${recipe}\` · ${findings.filter((f) => f.state === 'pass').length} passing · ` +
177
192
  `${fails.length} to fix · ${unknowns.length} unchecked` +
178
- (sc.acknowledged ? ` · ${sc.acknowledged} accepted risk${sc.acknowledged > 1 ? 's' : ''}` : ''));
193
+ (includes(sc) ? ` · ${includes(sc).replace(', ', ' · ')}` : ''));
179
194
  L.push('');
180
195
 
181
196
  if (blocking.length) {
@@ -295,6 +310,7 @@ export function renderHtml({ findings, sc, recipe, blocking }, { trend, spark, s
295
310
  tr.fail td:first-child{border-left:3px solid var(--cardinal)}
296
311
  tr.unknown td:first-child{border-left:3px solid #b9b6b0}
297
312
  tr.acknowledged td:first-child{border-left:3px solid #7a9a01}
313
+ tr.diverged td:first-child{border-left:3px solid #006cb8}
298
314
  footer{margin-top:2.5rem;padding-top:1rem;border-top:1px solid var(--line);
299
315
  color:#5f5e5b;font-size:.85rem}
300
316
  </style></head><body>
@@ -357,7 +357,9 @@ content:
357
357
  prior_art: []
358
358
 
359
359
  # Deliberate departures from the recipe. Each needs a reason. Silent divergence
360
- # is the only kind that is a problem. See the sws-diverge skill.
360
+ # is the only kind that is a problem. See the sws-diverge skill. Name the checks a
361
+ # divergence explains in \`checks:\`, and the report lists them as divergences
362
+ # rather than findings to fix. Preferences only: a requirement cannot be diverged.
361
363
  divergences: []
362
364
  `;
363
365
  }
@@ -42,7 +42,13 @@ correct for that project. Read it rather than inventing criteria.
42
42
 
43
43
  ## Result states, and one that matters more than it looks
44
44
 
45
- `pass` · `fail` · `unknown` · `acknowledged` · `not_applicable`
45
+ `pass` · `fail` · `unknown` · `acknowledged` · `diverged` · `not_applicable`
46
+
47
+ `acknowledged` is an accepted risk from `.sws/acknowledged.yml`, with a review
48
+ date. `diverged` is a deliberate choice: a divergence in `.sws/manifest.yml` whose
49
+ `checks:` names the check. Only checks that are SWS preferences (policy
50
+ `patterns`, or none) can be diverged; a requirement stays a failure or an
51
+ accepted risk.
46
52
 
47
53
  **`unknown` is never a pass and never scores.** Any check that can fail to
48
54
  execute must report it: axe needs a real browser, the footer check needs built
@@ -51,8 +51,24 @@ divergences:
51
51
  by: sheamck@stanford.edu
52
52
  ```
53
53
 
54
- The record is what lets the next person understand the project, and it is what
55
- stops `sws doctor` nagging about a choice already made deliberately.
54
+ The record is what lets the next person understand the project. When the choice
55
+ makes a check fail, name the check in `checks:`, and the report moves the finding
56
+ from the nag to a "Divergences" section, with the reason beside it:
57
+
58
+ ```yaml
59
+ - from: next-ssr
60
+ changed: Font Awesome Pro icons, not Heroicons
61
+ reason: Licensed and managed by the web team, with the token in CI (ADR 0013)
62
+ cost_accepted: A licence to renew, and a token every install needs
63
+ checks: [security.no-fontawesome-pro]
64
+ date: 2026-11-09
65
+ by: sheamck@stanford.edu
66
+ ```
67
+
68
+ `checks:` covers preferences only: criteria with `policy: patterns` or no
69
+ policy. A divergence naming a requirement (accessibility, brand, MinWeb, MinSec,
70
+ MinPriv) or the blocking check is ignored, and the report says so. Those are
71
+ below, under what never bends.
56
72
 
57
73
  **5. Say when a swap is genuinely unsupported.** Not everything is a preference.
58
74
  Tailwind 3 with Decanter 8 does not work, because Decanter 8 requires Tailwind 4.
@@ -24,7 +24,7 @@
24
24
  # same way: a harness where axe silently failed to load still printed
25
25
  # "0 violations", which is a report that lies.
26
26
 
27
- # Result states: pass | fail | unknown | acknowledged | not_applicable
27
+ # Result states: pass | fail | unknown | acknowledged | diverged | not_applicable
28
28
 
29
29
  recipe: astro-static
30
30
  version: 1