@su-sws/synthetic-web-team 0.2.3 → 0.2.4
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 +2 -2
- package/packages/cli/src/checks.mjs +59 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@su-sws/synthetic-web-team",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
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 && node scripts/validate-layouts.mjs && node scripts/validate-divergences.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 && node scripts/validate-frameworks.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
|
},
|
|
@@ -99,6 +99,26 @@ export function projectFiles(root) {
|
|
|
99
99
|
return files.sort((a, b) => depth(a) - depth(b) || a.localeCompare(b));
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
+
// The framework the project is built with: 'next', 'astro', or null for a
|
|
103
|
+
// static site with neither. A check written for one framework never runs on
|
|
104
|
+
// another, because its advice is wrong there: Astro sets response headers in
|
|
105
|
+
// host config, Next in headers(); Astro's canonical URLs come from `site`,
|
|
106
|
+
// Next's from metadataBase. Next wins if a project somehow has both.
|
|
107
|
+
export function framework(root) {
|
|
108
|
+
const d = deps(root);
|
|
109
|
+
if (nextConfig(root) || d.next) return 'next';
|
|
110
|
+
if (['astro.config.mjs', 'astro.config.js', 'astro.config.ts'].some((f) => existsSync(join(root, f))) || d.astro) {
|
|
111
|
+
return 'astro';
|
|
112
|
+
}
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Source without its comments, so a check reading config never counts a
|
|
117
|
+
// commented-out line: `// key: 'Content-Security-Policy'` is not a CSP. Line
|
|
118
|
+
// comments are only taken where `//` cannot be part of a URL in a string.
|
|
119
|
+
const withoutJsComments = (s) => s.replace(/\/\*[\s\S]*?\*\//g, '').replace(/(^|[^:'"`\\])\/\/.*$/gm, '$1');
|
|
120
|
+
const withoutTomlComments = (s) => s.replace(/^\s*#.*$/gm, '');
|
|
121
|
+
|
|
102
122
|
// --------------------------------------------------------------------------
|
|
103
123
|
// footer: reads the contract, never hardcodes the link set
|
|
104
124
|
// --------------------------------------------------------------------------
|
|
@@ -456,16 +476,23 @@ export function seo({ root, html, dist }) {
|
|
|
456
476
|
? bad('seo.meta-description', `${noDesc.length} page(s) without one: ${noDesc.slice(0, 3).join(', ')}`)
|
|
457
477
|
: ok('seo.meta-description', 'all pages have a meta description'));
|
|
458
478
|
|
|
479
|
+
// The fix depends on the framework: Astro derives canonical URLs and the
|
|
480
|
+
// sitemap from `site`; Next from the metadata API and app/sitemap.ts.
|
|
481
|
+
const isNext = framework(root) === 'next';
|
|
459
482
|
out.push(noCanon.length
|
|
460
483
|
? bad('seo.canonical', `${noCanon.length} page(s) without a canonical link`,
|
|
461
|
-
|
|
484
|
+
isNext
|
|
485
|
+
? "Set `alternates.canonical` in each page's metadata, with `metadataBase` in the root layout so it resolves absolutely."
|
|
486
|
+
: 'Requires `site` set in the framework config. Missing `site` also silently breaks the sitemap.')
|
|
462
487
|
: ok('seo.canonical', 'canonical links present'));
|
|
463
488
|
|
|
464
489
|
const sitemap = ['sitemap-index.xml', 'sitemap.xml'].find((f) => existsSync(join(dist, f)));
|
|
465
490
|
out.push(sitemap
|
|
466
491
|
? ok('seo.sitemap', `${sitemap} emitted`)
|
|
467
492
|
: bad('seo.sitemap', 'no sitemap in the build output',
|
|
468
|
-
|
|
493
|
+
isNext
|
|
494
|
+
? 'Add app/sitemap.ts, which Next serves at /sitemap.xml.'
|
|
495
|
+
: 'Add @astrojs/sitemap and set `site` in the config.'));
|
|
469
496
|
|
|
470
497
|
const robotsPath = join(dist, 'robots.txt');
|
|
471
498
|
if (!existsSync(robotsPath)) {
|
|
@@ -1339,14 +1366,34 @@ const DEFAULT_HEADER_SET = [
|
|
|
1339
1366
|
['X-Frame-Options', 'frame options'],
|
|
1340
1367
|
];
|
|
1341
1368
|
|
|
1369
|
+
// Where a CSP comes from, if anywhere: the Next config's headers(), the Netlify
|
|
1370
|
+
// plugin that adds a per-request nonce, or host config. Bodies are read
|
|
1371
|
+
// without comments, so a commented-out policy is not one.
|
|
1372
|
+
function cspSource(root, nextBody, host) {
|
|
1373
|
+
if (nextBody && /Content-Security-Policy/i.test(nextBody)) return 'headers() in the Next config';
|
|
1374
|
+
if (deps(root)['@netlify/plugin-csp-nonce']
|
|
1375
|
+
|| (host?.kind === 'netlify' && /@netlify\/plugin-csp-nonce/.test(host.body))) return '@netlify/plugin-csp-nonce';
|
|
1376
|
+
if (host && /Content-Security-Policy/i.test(host.body)) return host.file;
|
|
1377
|
+
return null;
|
|
1378
|
+
}
|
|
1379
|
+
|
|
1342
1380
|
export function security({ root }) {
|
|
1343
|
-
const
|
|
1344
|
-
const
|
|
1381
|
+
const found = nextConfig(root);
|
|
1382
|
+
const cfg = found && { ...found, body: withoutJsComments(found.body) };
|
|
1383
|
+
const rawHost = hostConfig(root);
|
|
1384
|
+
const host = rawHost && {
|
|
1385
|
+
...rawHost, body: rawHost.kind === 'netlify' ? withoutTomlComments(rawHost.body) : rawHost.body,
|
|
1386
|
+
};
|
|
1345
1387
|
const out = [];
|
|
1346
1388
|
|
|
1347
|
-
//
|
|
1348
|
-
//
|
|
1349
|
-
|
|
1389
|
+
// Headers in host config: how Astro and a static build send them, because
|
|
1390
|
+
// Astro middleware misses prerendered routes. Never on a Next project, which
|
|
1391
|
+
// sets them in headers() for every route, static files included, and
|
|
1392
|
+
// security.headers-set checks that instead.
|
|
1393
|
+
out.push(framework(root) === 'next'
|
|
1394
|
+
? na('astro.headers-in-host-config',
|
|
1395
|
+
'a Next project: response headers come from headers() in the Next config (see security.headers-set)')
|
|
1396
|
+
: host
|
|
1350
1397
|
? (() => {
|
|
1351
1398
|
const missing = DEFAULT_HEADER_SET.filter(([h]) => !new RegExp(h, 'i').test(host.body)).map(([, l]) => l);
|
|
1352
1399
|
return missing.length
|
|
@@ -1377,15 +1424,15 @@ export function security({ root }) {
|
|
|
1377
1424
|
// header that breaks pages at CONTENT-EDIT time rather than at deploy time.
|
|
1378
1425
|
// MinWeb requires no response headers at all. The default header set below
|
|
1379
1426
|
// is what we actually ask for, because none of it can break a page.
|
|
1427
|
+
const csp = cspSource(root, hasHeaders ? b : null, host);
|
|
1428
|
+
out.push(csp
|
|
1429
|
+
? ok('security.csp-present', `CSP set by ${csp}; record it in .sws/manifest.yml`)
|
|
1430
|
+
: ok('security.csp-present', 'no CSP, which is compliant: CSP is optional'));
|
|
1380
1431
|
if (!hasHeaders) {
|
|
1381
|
-
out.push(ok('security.csp-present', 'no CSP, which is compliant: CSP is optional'));
|
|
1382
1432
|
out.push(bad('security.headers-set', 'no headers() function in the Next config',
|
|
1383
1433
|
'Add headers() returning the default set: HSTS, nosniff, Referrer-Policy, ' +
|
|
1384
1434
|
'Permissions-Policy, and X-Frame-Options: SAMEORIGIN. See standards/hosting/capabilities.yml.'));
|
|
1385
1435
|
} else {
|
|
1386
|
-
out.push(/Content-Security-Policy/i.test(b)
|
|
1387
|
-
? ok('security.csp-present', 'CSP configured in headers(); record it in .sws/manifest.yml')
|
|
1388
|
-
: ok('security.csp-present', 'no CSP, which is compliant: CSP is optional'));
|
|
1389
1436
|
|
|
1390
1437
|
const want = [
|
|
1391
1438
|
['Strict-Transport-Security', 'HSTS'],
|
|
@@ -1422,7 +1469,7 @@ export function security({ root }) {
|
|
|
1422
1469
|
|
|
1423
1470
|
export function next({ root, html }) {
|
|
1424
1471
|
const cfg = nextConfig(root);
|
|
1425
|
-
const isNext =
|
|
1472
|
+
const isNext = framework(root) === 'next';
|
|
1426
1473
|
if (!isNext) {
|
|
1427
1474
|
return ['next.postcss-configured', 'next.no-vite-tailwind', 'next.no-tailwind-config', 'next.metadata-base']
|
|
1428
1475
|
.map((id) => na(id, 'not a Next project'));
|