seo-supervisor 1.2.0 → 2.0.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 (207) hide show
  1. package/.claude-plugin/icon.png +0 -0
  2. package/.claude-plugin/marketplace.json +2 -2
  3. package/.claude-plugin/plugin.json +16 -3
  4. package/CHANGELOG.md +430 -0
  5. package/NOTICE +7 -0
  6. package/README.md +230 -25
  7. package/agents/seo-auditor.md +16 -0
  8. package/agents/seo-reviewer.md +16 -0
  9. package/bin/agents.mjs +194 -29
  10. package/bin/extras.mjs +422 -0
  11. package/bin/prompt.mjs +34 -14
  12. package/bin/seo-supervisor.mjs +386 -53
  13. package/commands/seo-audit.md +29 -3
  14. package/commands/seo-brief.md +28 -0
  15. package/commands/seo-connect.md +27 -0
  16. package/commands/seo-fix.md +24 -3
  17. package/commands/seo-grow.md +26 -0
  18. package/commands/seo-launch.md +17 -3
  19. package/commands/seo-review.md +13 -1
  20. package/commands/seo-rewrite.md +25 -0
  21. package/commands/seo-setup.md +17 -1
  22. package/commands/seo-watch.md +28 -0
  23. package/hooks/hooks.json +117 -0
  24. package/package.json +20 -7
  25. package/skills/seo-supervisor/NOTICE +7 -0
  26. package/skills/seo-supervisor/SKILL.md +302 -21
  27. package/skills/seo-supervisor/audience.md +61 -0
  28. package/skills/seo-supervisor/examples/drafts/security.md +41 -0
  29. package/skills/seo-supervisor/examples/hooks/README.md +28 -0
  30. package/skills/seo-supervisor/examples/hooks/claude-code-settings.json +15 -0
  31. package/skills/seo-supervisor/examples/hooks/codex-hooks.json +17 -0
  32. package/skills/seo-supervisor/examples/hooks/copilot-hooks.json +15 -0
  33. package/skills/seo-supervisor/examples/hooks/cursor-hooks.json +11 -0
  34. package/skills/seo-supervisor/examples/hooks/github-actions.yml +21 -0
  35. package/skills/seo-supervisor/examples/hooks/pre-commit +17 -0
  36. package/skills/seo-supervisor/examples/hooks/reading-ease.yml +24 -0
  37. package/skills/seo-supervisor/examples/sample-audit.json +94 -2
  38. package/skills/seo-supervisor/examples/sample-report.html +111 -61
  39. package/skills/seo-supervisor/examples/sample-report.md +147 -44
  40. package/skills/seo-supervisor/examples/scheduled-runs.md +89 -0
  41. package/skills/seo-supervisor/examples/snippets.md +648 -1
  42. package/skills/seo-supervisor/grow.md +342 -0
  43. package/skills/seo-supervisor/og-images.md +85 -0
  44. package/skills/seo-supervisor/page-types.md +124 -0
  45. package/skills/seo-supervisor/planning.md +19 -7
  46. package/skills/seo-supervisor/profile-template.md +41 -0
  47. package/skills/seo-supervisor/report-format.md +177 -10
  48. package/skills/seo-supervisor/rewrite.md +59 -0
  49. package/skills/seo-supervisor/rules/ai-search.md +65 -12
  50. package/skills/seo-supervisor/rules/content.md +33 -9
  51. package/skills/seo-supervisor/rules/crawl-index.md +33 -6
  52. package/skills/seo-supervisor/rules/internal-linking.md +49 -6
  53. package/skills/seo-supervisor/rules/launch-monitoring.md +17 -8
  54. package/skills/seo-supervisor/rules/media.md +13 -1
  55. package/skills/seo-supervisor/rules/metadata.md +41 -9
  56. package/skills/seo-supervisor/rules/performance.md +50 -5
  57. package/skills/seo-supervisor/rules/rendering.md +39 -2
  58. package/skills/seo-supervisor/rules/search-intent.md +32 -0
  59. package/skills/seo-supervisor/rules/sitemaps-robots.md +24 -12
  60. package/skills/seo-supervisor/rules/structured-data.md +37 -14
  61. package/skills/seo-supervisor/rules/trust-security.md +25 -2
  62. package/skills/seo-supervisor/rules/urls.md +10 -2
  63. package/skills/seo-supervisor/scripts/ai-answers.mjs +314 -0
  64. package/skills/seo-supervisor/scripts/backlinks.mjs +412 -0
  65. package/skills/seo-supervisor/scripts/change-check.mjs +281 -0
  66. package/skills/seo-supervisor/scripts/checks/agents.mjs +488 -0
  67. package/skills/seo-supervisor/scripts/checks/assets.mjs +404 -0
  68. package/skills/seo-supervisor/scripts/checks/bots.mjs +146 -0
  69. package/skills/seo-supervisor/scripts/checks/business-type.mjs +193 -0
  70. package/skills/seo-supervisor/scripts/checks/content.mjs +391 -0
  71. package/skills/seo-supervisor/scripts/checks/coverage.mjs +184 -0
  72. package/skills/seo-supervisor/scripts/checks/crawl.mjs +95 -0
  73. package/skills/seo-supervisor/scripts/checks/hreflang.mjs +396 -0
  74. package/skills/seo-supervisor/scripts/checks/hygiene.mjs +227 -0
  75. package/skills/seo-supervisor/scripts/checks/lighthouse.mjs +271 -0
  76. package/skills/seo-supervisor/scripts/checks/link-strength.mjs +59 -0
  77. package/skills/seo-supervisor/scripts/checks/links.mjs +360 -0
  78. package/skills/seo-supervisor/scripts/checks/local.mjs +101 -0
  79. package/skills/seo-supervisor/scripts/checks/media.mjs +194 -0
  80. package/skills/seo-supervisor/scripts/checks/outbound.mjs +53 -0
  81. package/skills/seo-supervisor/scripts/checks/page.mjs +223 -0
  82. package/skills/seo-supervisor/scripts/checks/probes.mjs +130 -0
  83. package/skills/seo-supervisor/scripts/checks/render.mjs +552 -0
  84. package/skills/seo-supervisor/scripts/checks/robots.mjs +144 -0
  85. package/skills/seo-supervisor/scripts/checks/schema.mjs +206 -0
  86. package/skills/seo-supervisor/scripts/checks/site-agents.mjs +79 -0
  87. package/skills/seo-supervisor/scripts/checks/site-content.mjs +135 -0
  88. package/skills/seo-supervisor/scripts/checks/site-hygiene.mjs +202 -0
  89. package/skills/seo-supervisor/scripts/checks/site-pages.mjs +474 -0
  90. package/skills/seo-supervisor/scripts/checks/site-security.mjs +102 -0
  91. package/skills/seo-supervisor/scripts/checks/sitemap.mjs +473 -0
  92. package/skills/seo-supervisor/scripts/checks/speed.mjs +267 -0
  93. package/skills/seo-supervisor/scripts/checks/technical.mjs +368 -0
  94. package/skills/seo-supervisor/scripts/checks/tls.mjs +297 -0
  95. package/skills/seo-supervisor/scripts/checks/trust.mjs +421 -0
  96. package/skills/seo-supervisor/scripts/checks/visual.mjs +1132 -0
  97. package/skills/seo-supervisor/scripts/checks/writing.mjs +192 -0
  98. package/skills/seo-supervisor/scripts/commoncrawl.mjs +452 -0
  99. package/skills/seo-supervisor/scripts/connect-keys.mjs +422 -0
  100. package/skills/seo-supervisor/scripts/content-scan.mjs +515 -158
  101. package/skills/seo-supervisor/scripts/crawl/catalog.mjs +1248 -0
  102. package/skills/seo-supervisor/scripts/crawl/fetch.mjs +362 -0
  103. package/skills/seo-supervisor/scripts/crawl/page.mjs +741 -0
  104. package/skills/seo-supervisor/scripts/crawl/queue.mjs +190 -0
  105. package/skills/seo-supervisor/scripts/dashboard.mjs +140 -0
  106. package/skills/seo-supervisor/scripts/data/ai-bots.json +38 -0
  107. package/skills/seo-supervisor/scripts/data/build-schema-vocab.mjs +57 -0
  108. package/skills/seo-supervisor/scripts/data/business-types.json +338 -0
  109. package/skills/seo-supervisor/scripts/data/google-rich-results.json +79 -0
  110. package/skills/seo-supervisor/scripts/data/schema-vocab.json +1 -0
  111. package/skills/seo-supervisor/scripts/deploy-check.mjs +462 -0
  112. package/skills/seo-supervisor/scripts/disavow.mjs +176 -0
  113. package/skills/seo-supervisor/scripts/doctor.mjs +174 -0
  114. package/skills/seo-supervisor/scripts/geo-grid.mjs +371 -0
  115. package/skills/seo-supervisor/scripts/google/search-console.mjs +151 -0
  116. package/skills/seo-supervisor/scripts/google/session.mjs +167 -0
  117. package/skills/seo-supervisor/scripts/google-updates.mjs +189 -0
  118. package/skills/seo-supervisor/scripts/google.mjs +1341 -0
  119. package/skills/seo-supervisor/scripts/gsc-import.mjs +298 -0
  120. package/skills/seo-supervisor/scripts/guard/adapters/claude-code.mjs +149 -0
  121. package/skills/seo-supervisor/scripts/guard/adapters/cline.mjs +28 -0
  122. package/skills/seo-supervisor/scripts/guard/adapters/codex.mjs +26 -0
  123. package/skills/seo-supervisor/scripts/guard/adapters/copilot.mjs +36 -0
  124. package/skills/seo-supervisor/scripts/guard/adapters/cursor.mjs +33 -0
  125. package/skills/seo-supervisor/scripts/guard/adapters/devin.mjs +25 -0
  126. package/skills/seo-supervisor/scripts/guard/adapters/edits.mjs +124 -0
  127. package/skills/seo-supervisor/scripts/guard/mode.mjs +37 -0
  128. package/skills/seo-supervisor/scripts/guard/rules.mjs +931 -0
  129. package/skills/seo-supervisor/scripts/guard.mjs +74 -0
  130. package/skills/seo-supervisor/scripts/images.mjs +408 -0
  131. package/skills/seo-supervisor/scripts/indexnow.mjs +300 -0
  132. package/skills/seo-supervisor/scripts/issues.mjs +217 -0
  133. package/skills/seo-supervisor/scripts/keys/authority.mjs +135 -0
  134. package/skills/seo-supervisor/scripts/keys/bing.mjs +239 -0
  135. package/skills/seo-supervisor/scripts/keys/clarity.mjs +137 -0
  136. package/skills/seo-supervisor/scripts/keys/dataforseo.mjs +57 -0
  137. package/skills/seo-supervisor/scripts/keys/googleplaces.mjs +26 -0
  138. package/skills/seo-supervisor/scripts/keys/http.mjs +212 -0
  139. package/skills/seo-supervisor/scripts/keys/matomo.mjs +138 -0
  140. package/skills/seo-supervisor/scripts/keys/openai.mjs +26 -0
  141. package/skills/seo-supervisor/scripts/keys/perplexity.mjs +26 -0
  142. package/skills/seo-supervisor/scripts/keys/posthog.mjs +165 -0
  143. package/skills/seo-supervisor/scripts/keys/semrush.mjs +25 -0
  144. package/skills/seo-supervisor/scripts/keys/services.mjs +41 -0
  145. package/skills/seo-supervisor/scripts/keys/store.mjs +140 -0
  146. package/skills/seo-supervisor/scripts/keys/visits.mjs +58 -0
  147. package/skills/seo-supervisor/scripts/keys/youtube.mjs +84 -0
  148. package/skills/seo-supervisor/scripts/keyword-data.mjs +316 -0
  149. package/skills/seo-supervisor/scripts/keyword-ideas.mjs +503 -0
  150. package/skills/seo-supervisor/scripts/lib/args.mjs +56 -0
  151. package/skills/seo-supervisor/scripts/lib/business.mjs +27 -0
  152. package/skills/seo-supervisor/scripts/lib/cdp.mjs +242 -0
  153. package/skills/seo-supervisor/scripts/lib/cli.mjs +56 -0
  154. package/skills/seo-supervisor/scripts/lib/csv.mjs +38 -0
  155. package/skills/seo-supervisor/scripts/lib/findings.mjs +100 -0
  156. package/skills/seo-supervisor/scripts/lib/google-client.mjs +9 -0
  157. package/skills/seo-supervisor/scripts/lib/html.mjs +146 -0
  158. package/skills/seo-supervisor/scripts/lib/http.mjs +28 -0
  159. package/skills/seo-supervisor/scripts/lib/image-size.mjs +78 -0
  160. package/skills/seo-supervisor/scripts/lib/is-main.mjs +13 -0
  161. package/skills/seo-supervisor/scripts/lib/net.mjs +116 -0
  162. package/skills/seo-supervisor/scripts/lib/proxy.mjs +47 -0
  163. package/skills/seo-supervisor/scripts/lib/recheck.mjs +106 -0
  164. package/skills/seo-supervisor/scripts/lib/redact.mjs +78 -0
  165. package/skills/seo-supervisor/scripts/lib/robots.mjs +73 -0
  166. package/skills/seo-supervisor/scripts/lib/score.mjs +266 -0
  167. package/skills/seo-supervisor/scripts/lib/settings-dir.mjs +81 -0
  168. package/skills/seo-supervisor/scripts/links-import.mjs +603 -0
  169. package/skills/seo-supervisor/scripts/log-scan.mjs +597 -0
  170. package/skills/seo-supervisor/scripts/og-card.mjs +273 -0
  171. package/skills/seo-supervisor/scripts/osm.mjs +359 -0
  172. package/skills/seo-supervisor/scripts/rdap.mjs +164 -0
  173. package/skills/seo-supervisor/scripts/render-report.mjs +324 -690
  174. package/skills/seo-supervisor/scripts/report/client.js +37 -0
  175. package/skills/seo-supervisor/scripts/report/diff.mjs +264 -0
  176. package/skills/seo-supervisor/scripts/report/findings.mjs +165 -0
  177. package/skills/seo-supervisor/scripts/report/format.mjs +111 -0
  178. package/skills/seo-supervisor/scripts/report/markdown.mjs +250 -0
  179. package/skills/seo-supervisor/scripts/report/model.mjs +171 -0
  180. package/skills/seo-supervisor/scripts/report/overview-lines.mjs +158 -0
  181. package/skills/seo-supervisor/scripts/report/overview.mjs +224 -0
  182. package/skills/seo-supervisor/scripts/report/page.mjs +127 -0
  183. package/skills/seo-supervisor/scripts/report/panel.mjs +172 -0
  184. package/skills/seo-supervisor/scripts/report/panels/ai.mjs +211 -0
  185. package/skills/seo-supervisor/scripts/report/panels/connections.mjs +139 -0
  186. package/skills/seo-supervisor/scripts/report/panels/content.mjs +204 -0
  187. package/skills/seo-supervisor/scripts/report/panels/data-search.mjs +379 -0
  188. package/skills/seo-supervisor/scripts/report/panels/data-site.mjs +44 -0
  189. package/skills/seo-supervisor/scripts/report/panels/links.mjs +380 -0
  190. package/skills/seo-supervisor/scripts/report/panels/local.mjs +221 -0
  191. package/skills/seo-supervisor/scripts/report/panels/site.mjs +359 -0
  192. package/skills/seo-supervisor/scripts/report/panels/speed-media.mjs +267 -0
  193. package/skills/seo-supervisor/scripts/report/sources.mjs +163 -0
  194. package/skills/seo-supervisor/scripts/report/styles.css +223 -0
  195. package/skills/seo-supervisor/scripts/report/traffic.mjs +264 -0
  196. package/skills/seo-supervisor/scripts/report-plan.mjs +112 -33
  197. package/skills/seo-supervisor/scripts/schema-check.mjs +717 -0
  198. package/skills/seo-supervisor/scripts/seo-crawl.mjs +1086 -638
  199. package/skills/seo-supervisor/scripts/seo-diff.mjs +584 -0
  200. package/skills/seo-supervisor/scripts/update-check.mjs +82 -0
  201. package/skills/seo-supervisor/site-types/content.md +34 -1
  202. package/skills/seo-supervisor/site-types/ecommerce.md +38 -1
  203. package/skills/seo-supervisor/site-types/local-business.md +96 -6
  204. package/skills/seo-supervisor/site-types/services.md +46 -0
  205. package/skills/seo-supervisor/site-types/tools.md +3 -3
  206. package/skills/seo-supervisor/strategy.md +232 -0
  207. package/skills/seo-supervisor/troubleshooting.md +56 -0
@@ -0,0 +1,266 @@
1
+ // @ts-check
2
+ // The score model (documented in report-format.md), shared by render-report.mjs and dashboard.mjs.
3
+ // Every checked rule is worth 10 points. A passing rule (or one whose findings are all fixed) earns 10;
4
+ // a rule with open findings earns by its worst one: low 8, medium 6, decision 6, high 3, blocker 0.
5
+ // Score = earned / possible. Open blockers cap it: 1 → 59, 2 → 49, 3 → 39 … (never below 9). While any open
6
+ // finding isn't won't-fix, it stops at 99, so 100 always means nothing is left to fix (rounding alone could reach 100).
7
+ import { existsSync, readdirSync, readFileSync } from "node:fs";
8
+ import { basename, join } from "node:path";
9
+ import { CHECKS, currentId, currentIds } from "../crawl/catalog.mjs";
10
+ export const SEV = ["blocker", "high", "needs-decision", "medium", "low"];
11
+ export const EARN = { blocker: 0, high: 3, "needs-decision": 6, medium: 6, low: 8 };
12
+ export const isOpen = f => f.status !== "fixed";
13
+
14
+ // Findings as the report reads them: an ID, a known severity, a status and an area on each.
15
+ export const normalise = list =>
16
+ (Array.isArray(list) ? list : [])
17
+ .filter(f => f && typeof f === "object")
18
+ .map((f, i) => ({
19
+ evidence: [],
20
+ ...f,
21
+ id: f.id || `F-${String(i + 1).padStart(3, "0")}`,
22
+ severity: SEV.includes(f.severity) ? f.severity : "low",
23
+ status: f.status || (f.severity === "needs-decision" ? "needs-decision" : "open"),
24
+ category: f.category || "Other",
25
+ }));
26
+
27
+ // fixedCountsAsOpen: the score before this run's fixes. assume: findings to treat as fixed (for the "once blockers
28
+ // are fixed" score).
29
+ export function buildRules(findings, passed = [], { fixedCountsAsOpen = false, assume = _f => false } = {}) {
30
+ const rules = new Map();
31
+ for (const f of findings) {
32
+ const key = f.rule || f.id;
33
+ const r = rules.get(key) || { key, area: f.category, worst: null, todo: false };
34
+ const counts = !assume(f) && (fixedCountsAsOpen || isOpen(f));
35
+ if (counts && (r.worst === null || SEV.indexOf(f.severity) < SEV.indexOf(r.worst))) r.worst = f.severity;
36
+ if (counts && f.status !== "wont-fix") r.todo = true;
37
+ rules.set(key, r);
38
+ }
39
+ for (const p of Array.isArray(passed) ? passed : [])
40
+ if (typeof p?.rule === "string" && !rules.has(p.rule))
41
+ rules.set(p.rule, { key: p.rule, area: p.category || "Other", worst: null, todo: false });
42
+ return [...rules.values()];
43
+ }
44
+ export function score(rules) {
45
+ if (!rules.length) return null;
46
+ const earned = rules.reduce((s, r) => s + (r.worst ? EARN[r.worst] : 10), 0);
47
+ const rawScore = Math.round((100 * earned) / (rules.length * 10));
48
+ const blockers = rules.filter(r => r.worst === "blocker").length;
49
+ const cap = blockers ? Math.max(9, 69 - 10 * blockers) : 100;
50
+ return {
51
+ value: Math.min(rawScore, cap, rules.some(r => r.todo) ? 99 : 100),
52
+ raw: rawScore,
53
+ cap: blockers ? cap : null,
54
+ blockers,
55
+ rules: rules.length,
56
+ passing: rules.filter(r => !r.worst).length,
57
+ };
58
+ }
59
+ // ---------- the project's own check settings ----------
60
+ // seo-audit/settings.json beside the audit file:
61
+ // "checks": { "off": ["no-hsts"], "severity": { "img-alt-quality": "medium" } }
62
+ // A check is a finding's `check` id; hand-written findings have none and are left alone. findingsOf is the one place
63
+ // these apply, so the report, the score and issues.mjs see the same list. An off check is dropped from the score as if
64
+ // it hadn't run; the report lists it. Blockers are never turned off or lowered: a noindex home page or an expired
65
+ // certificate can appear on any later run, and a setting written once would hide it from every report after. An
66
+ // intended one (noindex before launch) is handled per run, with --ignore-noindex or the audit's review, and noted.
67
+
68
+ // Every check id the scripts can write, read from their own text: catalog entries (`"id": ["RULE-01", "severity", …`,
69
+ // at a line's start or right after `{` or `,`, so `SERVER_CHECK = { "id": [` counts too; `CHECKS["id"] = [`) and findings
70
+ // written directly (`check: "id", rule: …`, `finding("id", …)`). A bare `check: "…"` is left out: the crawler's product
71
+ // problems use one for a code its finding prefixes (image-missing is product-image-missing).
72
+ // A pattern scan, so a check written any other way reads as unknown; add its pattern here if one is.
73
+ export function knownChecks(dir = new URL("..", import.meta.url)) {
74
+ const ids = new Set(),
75
+ files = [];
76
+ for (const d of [dir, new URL("checks/", dir), new URL("crawl/", dir)])
77
+ try {
78
+ files.push(
79
+ ...readdirSync(d)
80
+ .filter(f => f.endsWith(".mjs"))
81
+ .map(f => new URL(f, d)),
82
+ );
83
+ } catch {}
84
+ const re =
85
+ /(?:^|[{,])\s*"?([a-z0-9]+(?:-[a-z0-9]+)*)"?:\s*\[\s*"[A-Z]+-\d+",\s*"(?:blocker|high|medium|low|needs-decision)"|CHECKS\["([a-z0-9-]+)"\] = \[|\bcheck:\s*"([a-z0-9-]+)",\s*rule:\s*"|\bfinding\(\s*"([a-z0-9-]+)"/gm;
86
+ for (const f of files) for (const m of readFileSync(f, "utf8").matchAll(re)) ids.add(m[1] || m[2] || m[3] || m[4]);
87
+ return ids;
88
+ }
89
+ const plainObj = x => x && typeof x === "object" && !Array.isArray(x);
90
+ /** @returns {{ findings: any[], off: { check: string, count: number }[], changed: { check: string, to: string, count: number }[], warnings: string[] }} */
91
+ export function applyChecks(findings, settings, known = null) {
92
+ if (settings == null) return { findings, off: [], changed: [], warnings: [] };
93
+ if (
94
+ !plainObj(settings) ||
95
+ (settings.off != null && !Array.isArray(settings.off)) ||
96
+ (settings.severity != null && !plainObj(settings.severity))
97
+ )
98
+ return {
99
+ findings,
100
+ off: [],
101
+ changed: [],
102
+ warnings: [
103
+ `"checks" in settings.json should be { "off": ["check-id"], "severity": { "check-id": "low" } }, so it was ignored.`,
104
+ ],
105
+ };
106
+ const warnings = new Set(),
107
+ ids = new Set([...(known || knownChecks()), ...findings.map(f => f.check).filter(Boolean)]);
108
+ const valid = id =>
109
+ ids.has(id) ||
110
+ void warnings.add(
111
+ `“${id}” isn't a check SEO Supervisor knows, so its setting was ignored. The check names are the "check" values in seo-crawl.json.`,
112
+ );
113
+ const off = new Map(
114
+ (settings.off || [])
115
+ .flatMap(id => currentIds(id))
116
+ .filter(valid)
117
+ .map(id => [id, 0]),
118
+ ); // an old id applies to the ids it became
119
+ const changed = new Map(
120
+ Object.entries(settings.severity || {})
121
+ .flatMap(([id, s]) => currentIds(id).map(n => [n, s]))
122
+ .filter(
123
+ ([id, s]) =>
124
+ valid(id) &&
125
+ (SEV.includes(s) ||
126
+ void warnings.add(
127
+ `“${s}” isn't a severity, so ${id} keeps its own. Use blocker, high, needs-decision, medium or low.`,
128
+ )),
129
+ )
130
+ .map(([id, to]) => [id, { to, count: 0 }]),
131
+ );
132
+ const kept = [];
133
+ for (const f of findings) {
134
+ const blocker = f.severity === "blocker",
135
+ to = changed.get(f.check);
136
+ if (off.has(f.check)) {
137
+ if (!blocker) {
138
+ off.set(f.check, off.get(f.check) + 1);
139
+ continue;
140
+ }
141
+ warnings.add(
142
+ `${f.check} found a blocker (${f.id}), so it stays on: blockers can't be turned off in settings.json.`,
143
+ );
144
+ }
145
+ if (to && to.to !== f.severity) {
146
+ if (blocker) {
147
+ warnings.add(
148
+ `${f.check} found a blocker (${f.id}), so it stays a blocker: blockers can't be lowered in settings.json.`,
149
+ );
150
+ kept.push(f);
151
+ continue;
152
+ }
153
+ to.count++;
154
+ kept.push({ ...f, severity: to.to });
155
+ continue;
156
+ }
157
+ kept.push(f);
158
+ }
159
+ return {
160
+ findings: kept,
161
+ off: [...off].map(([check, count]) => ({ check, count })),
162
+ changed: [...changed].map(([check, c]) => ({ check, ...c })),
163
+ warnings: [...warnings],
164
+ };
165
+ }
166
+ // An older audit has one h1-count finding for both cases, so each page's detail ("0 H1s", "3 H1s") says which it
167
+ // is. A finding with both becomes two (the second's ID ends in b), each titled and counted by its pages.
168
+ // An old finding lists 100 pages at most, so one over 100 is split and counted by the 100 it lists.
169
+ function oldH1(f) {
170
+ if (f.check !== "h1-count") return [f];
171
+ const ev = Array.isArray(f.evidence) ? f.evidence : [],
172
+ many = e => Number(/^(\d+) H1s\b/.exec(e?.detail ?? "")?.[1]) > 1;
173
+ const parts = [
174
+ ["h1-missing", ev.filter(e => !many(e))],
175
+ ["h1-multiple", ev.filter(many)],
176
+ ].filter(([, x]) => x.length);
177
+ if (parts.length < 2) return [{ ...f, check: parts[0]?.[0] ?? "h1-missing" }];
178
+ return parts.map(([check, evidence], i) => ({
179
+ ...f,
180
+ id: i ? `${f.id}b` : f.id,
181
+ check,
182
+ evidence,
183
+ count: evidence.length,
184
+ title: CHECKS[check][2](evidence.length),
185
+ }));
186
+ }
187
+ // The audit's findings as every reader sees them: normalised, then the settings beside the audit file (dir) applied.
188
+ // A renamed check's old id (crawl/catalog.mjs ID_ALIASES) reads as its new one, in the settings and in an audit made
189
+ // before the rename, so neither stops applying.
190
+ export function findingsOf(raw, dir) {
191
+ const file = join(dir, "settings.json");
192
+ let settings = null,
193
+ bad = null;
194
+ if (existsSync(file))
195
+ try {
196
+ settings = JSON.parse(readFileSync(file, "utf8"));
197
+ } catch {
198
+ bad = `${basename(dir)}/settings.json isn't valid JSON, so its check settings weren't read.`;
199
+ }
200
+ let checks = plainObj(settings) ? settings.checks : undefined;
201
+ // applyChecks maps old ids itself; here they only get a note suggesting the rename.
202
+ const renamed = new Set(),
203
+ note = id => {
204
+ const n = currentIds(id);
205
+ if (n.length > 1)
206
+ renamed.add(
207
+ `“${id}” is now ${n.map(x => `“${x}”`).join(" and ")}, and its setting applies to each. Rename it in settings.json when you can.`,
208
+ );
209
+ else if (n[0] !== id)
210
+ renamed.add(
211
+ `“${id}” is now called “${n[0]}”, and its setting still applies. Rename it in settings.json when you can.`,
212
+ );
213
+ };
214
+ if (plainObj(checks)) {
215
+ if (Array.isArray(checks.off)) checks.off.forEach(note);
216
+ if (plainObj(checks.severity)) Object.keys(checks.severity).forEach(note);
217
+ }
218
+ const r = applyChecks(
219
+ normalise(raw?.findings)
220
+ .flatMap(oldH1)
221
+ .map(f => (typeof f.check === "string" ? { ...f, check: currentId(f.check) } : f)),
222
+ checks,
223
+ );
224
+ return { ...r, warnings: [...(bad ? [bad] : []), ...renamed, ...r.warnings] };
225
+ }
226
+
227
+ // The score summary every reader shows, so the report and the dashboard can't disagree: the findings as the settings
228
+ // leave them (open first, then by severity, then by count), the passed rules, the rules and the score, and the score
229
+ // once the open blockers are fixed (null when no blocker caps it).
230
+ export function scoreSummary(raw, dir) {
231
+ const { findings, ...checkSettings } = findingsOf(raw, dir);
232
+ findings.sort(
233
+ (a, b) =>
234
+ Number(!isOpen(a)) - Number(!isOpen(b)) ||
235
+ SEV.indexOf(a.severity) - SEV.indexOf(b.severity) ||
236
+ (b.count || 0) - (a.count || 0),
237
+ );
238
+ const passed = Array.isArray(raw?.passed) ? raw.passed : [],
239
+ open = findings.filter(isOpen),
240
+ rules = buildRules(findings, passed),
241
+ overall = score(rules);
242
+ const unlock = overall?.cap
243
+ ? score(buildRules(findings, passed, { assume: /** @type {any} */ (f => f.severity === "blocker") }))
244
+ : null;
245
+ return {
246
+ findings,
247
+ checkSettings,
248
+ passed,
249
+ open,
250
+ rules,
251
+ overall,
252
+ unlock,
253
+ countSev: sev => open.filter(f => f.severity === sev).length,
254
+ };
255
+ }
256
+
257
+ export const BANDS = [
258
+ [90, "Excellent", "b5"],
259
+ [75, "Good", "b4"],
260
+ [60, "Fair", "b3"],
261
+ [40, "Poor", "b2"],
262
+ [0, "Critical", "b1"],
263
+ ];
264
+ export const bandOf = v => BANDS.find(([min]) => v >= min);
265
+ // The same words in every report and tool that shows this score.
266
+ export const OWN_SCORE = "SEO Supervisor's own score, not Google's";
@@ -0,0 +1,81 @@
1
+ // @ts-check
2
+ // Where settings, logins, keys and add-ons live: ~/.seo-supervisor or SEO_SUPERVISOR_HOME. SEO_SUPERVISOR_CLIENT=<name>
3
+ // puts logins and keys in clients/<name> so each client's stay apart; add-ons and the update setting stay shared.
4
+ import { spawnSync } from "node:child_process";
5
+ import { chmodSync, existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
6
+ import { homedir } from "node:os";
7
+ import { dirname, isAbsolute, join, normalize } from "node:path";
8
+
9
+ // ~ is expanded here, since GitHub Actions, .env files and PowerShell don't. A relative path is refused: it would put
10
+ // logins and keys inside whatever folder a script runs from, usually the project, where a commit could take them.
11
+ // Errors carry code SEO_SETTINGS so scripts show them as plain messages: the fix is in the environment, not the code.
12
+ const settingsError = msg => Object.assign(new Error(msg), { code: "SEO_SETTINGS" });
13
+ export function settingsDir(env = process.env, home = homedir()) {
14
+ const v = env.SEO_SUPERVISOR_HOME;
15
+ if (!v) return join(home, ".seo-supervisor");
16
+ const p = v === "~" ? home : /^~[\\/]/.test(v) ? join(home, v.slice(2)) : v;
17
+ if (!isAbsolute(p))
18
+ throw settingsError(
19
+ `SEO_SUPERVISOR_HOME must be a full path, like ${join(home, ".seo-supervisor")} (got "${v}"), so logins and keys never land inside a project.`,
20
+ );
21
+ return normalize(p);
22
+ }
23
+ export const toolsDir = (env = process.env, home = homedir()) => join(settingsDir(env, home), "tools");
24
+
25
+ // A client name is one folder name: letters, digits, - and _, so it can never point outside the settings folder.
26
+ export function loginDir(env = process.env, home = homedir()) {
27
+ const c = env.SEO_SUPERVISOR_CLIENT;
28
+ if (!c) return settingsDir(env, home);
29
+ if (!/^[a-z0-9][a-z0-9_-]{0,63}$/i.test(c))
30
+ throw settingsError(`SEO_SUPERVISOR_CLIENT must be a short name made of letters, digits, - and _ (got "${c}").`);
31
+ return join(settingsDir(env, home), "clients", c);
32
+ }
33
+
34
+ // The saved Google sign-in (google.mjs connect writes it; doctor.mjs only looks).
35
+ export const googleFile = (env = process.env, home = homedir()) => join(loginDir(env, home), "google.json");
36
+
37
+ // A login or key file, renamed over the old one so a crash never leaves half of it, and made readable by this user
38
+ // only before it does. Unix: mode 600 in a 700 folder, then checked, since some drives ignore modes. Windows ignores
39
+ // modes, so icacls removes inherited entries and grants this user alone full control. locked says whether that held;
40
+ // when it didn't, the file is only as private as its folder, and privacyOf says so rather than claiming more.
41
+ /** @param {string} file @param {string} text @returns {{ locked: boolean }} */
42
+ export function writePrivate(file, text) {
43
+ mkdirSync(dirname(file), { recursive: true, mode: 0o700 });
44
+ chmodSync(dirname(file), 0o700);
45
+ const t = `${file}.${process.pid}.tmp`;
46
+ writeFileSync(t, text, { mode: 0o600 });
47
+ chmodSync(t, 0o600);
48
+ let locked;
49
+ if (process.platform === "win32") {
50
+ const user =
51
+ process.env.USERDOMAIN && process.env.USERNAME
52
+ ? `${process.env.USERDOMAIN}\\${process.env.USERNAME}`
53
+ : process.env.USERNAME;
54
+ // The full path, never a search: an icacls.exe in the current folder isn't run.
55
+ locked =
56
+ !!user &&
57
+ spawnSync(
58
+ join(process.env.SystemRoot || "C:\\Windows", "System32", "icacls.exe"),
59
+ [t, "/inheritance:r", "/grant:r", `${user}:F`],
60
+ { stdio: "ignore", windowsHide: true },
61
+ ).status === 0;
62
+ } else locked = (statSync(t).mode & 0o077) === 0;
63
+ renameSync(t, file);
64
+ return { locked };
65
+ }
66
+ /** The words for where a writePrivate file stands, for "Saved to <file> (…)". @param {{ locked: boolean }} r */
67
+ export const privacyOf = r =>
68
+ r.locked
69
+ ? "only your user account can read it"
70
+ : "this system didn't let it be limited to your user account, so it's as private as the folder it's in";
71
+
72
+ // The browser `npx seo-supervisor --with-browser` installed, when there is one and it's still there.
73
+ export const browserFile = (env = process.env, home = homedir()) => join(toolsDir(env, home), "chrome-path.txt");
74
+ export function installedBrowser(env = process.env, home = homedir()) {
75
+ try {
76
+ const p = readFileSync(browserFile(env, home), "utf8").trim();
77
+ return p && existsSync(p) ? p : null;
78
+ } catch {
79
+ return null;
80
+ }
81
+ }