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,271 @@
1
+ // @ts-check
2
+ // Optional Lighthouse runs, an outside check: Chrome loads each page and runs its scripts, analytics included.
3
+ // No findings: its SEO audits repeat the crawler's, its lab metrics aren't the field data PERF-01 asks for, and no rule
4
+ // covers its accessibility or best-practices audits.
5
+ import { execFile } from "node:child_process";
6
+ import { existsSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
7
+ import { homedir, tmpdir } from "node:os";
8
+ import { delimiter, dirname, join } from "node:path";
9
+ import { labLcpParts, labLcpElement } from "./speed.mjs";
10
+ import { CHROME_FLAGS, containerArgs, ownProxyArgs, quietProfile } from "../lib/cdp.mjs";
11
+ import { redact } from "../lib/redact.mjs";
12
+ import { startGuard } from "./render.mjs";
13
+ import { toolsDir } from "../lib/settings-dir.mjs";
14
+
15
+ const CATEGORIES = {
16
+ performance: "performance",
17
+ seo: "seo",
18
+ accessibility: "accessibility",
19
+ bestPractices: "best-practices",
20
+ };
21
+ const METRICS = {
22
+ lcp: "largest-contentful-paint",
23
+ cls: "cumulative-layout-shift",
24
+ tbt: "total-blocking-time",
25
+ fcp: "first-contentful-paint",
26
+ speedIndex: "speed-index",
27
+ };
28
+
29
+ /** LIGHTHOUSE_PATH, then the installer's copy in the settings tools folder, then lighthouse on PATH; null if none. */
30
+ export function findLighthouse(env = process.env, home = homedir(), platform = process.platform) {
31
+ const exe = platform === "win32" ? "lighthouse.cmd" : "lighthouse";
32
+ const path = (env.PATH ?? env.Path ?? "")
33
+ .split(delimiter)
34
+ .filter(Boolean)
35
+ .map(d => join(d, exe));
36
+ const tools = (() => {
37
+ try {
38
+ return join(toolsDir(env, home), "node_modules", ".bin", exe);
39
+ } catch {
40
+ return null;
41
+ }
42
+ })(); // a bad SEO_SUPERVISOR_HOME: no add-on, no crash
43
+ return [env.LIGHTHOUSE_PATH, tools, ...path].find(p => p && existsSync(p)) || null;
44
+ }
45
+
46
+ // Windows can't start a .cmd without a shell, so an npm shim is followed to its script, run with this Node. Other .cmd
47
+ // wrappers fail to start; pointing LIGHTHOUSE_PATH at the script itself gets around that.
48
+ function command(bin) {
49
+ const js = /\.cmd$/i.test(bin) ? readFileSync(bin, "utf8").match(/"%~?dp0%?\\([^"]+\.[cm]?js)"/i)?.[1] : null;
50
+ if (js) return [process.execPath, [join(dirname(bin), ...js.split("\\"))]];
51
+ return /\.[cm]?js$/i.test(bin) ? [process.execPath, [bin]] : [bin, []];
52
+ }
53
+
54
+ // The files or page elements an audit's details.items point at, each once, up to 10. An insight's "list" nests its
55
+ // tables.
56
+ const UNSCORED = new Set(["informative", "notApplicable", "manual", "error"]);
57
+ const rowsOf = d => (Array.isArray(d?.items) ? d.items.flatMap(i => (Array.isArray(i?.items) ? i.items : [i])) : []);
58
+ const filesOf = d =>
59
+ [
60
+ ...new Set(
61
+ rowsOf(d)
62
+ .map(i => [i?.url, i?.source?.url, i?.node?.selector].find(s => typeof s === "string" && s))
63
+ .filter(Boolean),
64
+ ),
65
+ ]
66
+ .slice(0, 10)
67
+ .map(s => s.slice(0, 300));
68
+
69
+ function parse(lhr, url) {
70
+ const cats = lhr.categories || {},
71
+ audits = lhr.audits || {};
72
+ const failed = [],
73
+ detail = new Map();
74
+ for (const c of Object.values(cats)) {
75
+ const total = c.auditRefs.reduce((s, r) => s + r.weight, 0) || 1;
76
+ for (const r of c.auditRefs) {
77
+ const a = audits[r.id];
78
+ if (typeof a?.score !== "number" || a.score >= 0.9) continue;
79
+ const cost = (r.weight * (1 - a.score)) / total;
80
+ if (r.weight > 0) failed.push({ id: r.id, title: a.title, category: c.title, cost });
81
+ // Every failed audit, weighted or not: most opportunities and diagnostics weigh nothing but name the files.
82
+ if (!detail.has(r.id) && !UNSCORED.has(a.scoreDisplayMode))
83
+ detail.set(r.id, {
84
+ id: r.id,
85
+ title: a.title,
86
+ category: c.title,
87
+ cost,
88
+ score: a.score,
89
+ items: filesOf(a.details),
90
+ });
91
+ }
92
+ }
93
+ const map = (o, f) => Object.fromEntries(Object.entries(o).map(([k, id]) => [k, f(id)]));
94
+ return {
95
+ url,
96
+ scores: map(CATEGORIES, id => (cats[id]?.score == null ? null : Math.round(cats[id].score * 100))),
97
+ metrics: map(METRICS, id => audits[id]?.numericValue ?? null),
98
+ lcpParts: labLcpParts(audits),
99
+ lcpElement: labLcpElement(audits),
100
+ // Each audit at 0.9 or more counts once, as Lighthouse's "Passed audits" list counts them.
101
+ passed: new Set(
102
+ Object.values(cats)
103
+ .flatMap(c => c.auditRefs.map(r => r.id))
104
+ .filter(id => audits[id]?.score >= 0.9 && !UNSCORED.has(audits[id].scoreDisplayMode)),
105
+ ).size,
106
+ version: typeof lhr.lighthouseVersion === "string" ? lhr.lighthouseVersion : null,
107
+ // By points lost in the category, so a heavy metric that nearly passes ranks below a light audit that fails.
108
+ failed: failed
109
+ .sort((a, b) => b.cost - a.cost)
110
+ .slice(0, 5)
111
+ .map(({ cost, ...f }) => f),
112
+ // The same order, then the weightless audits, lowest score first.
113
+ detail: [...detail.values()].sort((a, b) => b.cost - a.cost || a.score - b.score).map(({ cost, score, ...d }) => d),
114
+ };
115
+ }
116
+
117
+ // ---------- the Agentic browsing category ----------
118
+ // Lighthouse 13.3 added the experimental agentic-browsing category: it needs Chrome 150 or later and has no 0–100
119
+ // score. Lighthouse refuses a category it doesn't know, so it's asked for only when the package.json above the bin's
120
+ // script says 13.3 or later.
121
+ // https://developer.chrome.com/docs/lighthouse/agentic-browsing
122
+ import { realpathSync } from "node:fs";
123
+ const AGENTIC = "agentic-browsing";
124
+ export function agenticFlag(bin) {
125
+ try {
126
+ for (let dir = dirname(realpathSync(command(bin)[1][0] ?? bin)), i = 0; i < 4; i++, dir = dirname(dir)) {
127
+ const p = join(dir, "package.json");
128
+ const pkg = existsSync(p) && JSON.parse(readFileSync(p, "utf8"));
129
+ if (pkg?.name !== "lighthouse") continue;
130
+ const [major, minor] = String(pkg.version).split(".").map(Number);
131
+ return major > 13 || (major === 13 && minor >= 3) ? "," + AGENTIC : "";
132
+ }
133
+ } catch {}
134
+ return "";
135
+ }
136
+ /** Checks passed out of those that count, and the failed ones, as Lighthouse's report-utils.js counts them: a pass is
137
+ * 0.9 or more, and manual, not-applicable and informative audits don't count. Null without the category. It's removed
138
+ * from lhr so its audits don't join the scored categories' failed audits. */
139
+ export function takeAgentic(lhr) {
140
+ const c = lhr?.categories?.[AGENTIC];
141
+ if (!c) return null;
142
+ delete lhr.categories[AGENTIC];
143
+ const counted = (c.auditRefs || [])
144
+ .filter(r => r.group !== "hidden")
145
+ .map(r => ({ id: r.id, ...lhr.audits?.[r.id] }))
146
+ .filter(a => !["manual", "notApplicable", "informative"].includes(a.scoreDisplayMode));
147
+ const failed = counted.filter(a => a.scoreDisplayMode === "error" || !(Number(a.score) >= 0.9));
148
+ return {
149
+ passed: counted.length - failed.length,
150
+ total: counted.length,
151
+ failed: failed.map(a => ({ id: a.id, title: String(a.title ?? a.id) })),
152
+ };
153
+ }
154
+
155
+ /** One Lighthouse run on its defaults (mobile, simulated throttling) with a throwaway Chrome profile. Chrome gets
156
+ * launchChrome's container flags and the render guard instead of proxy flags, so the page can't steer it to a private
157
+ * or cloud-metadata address; with a configured proxy, that proxy's flags instead. host ({ platform, uid, env, exists })
158
+ * is for tests. Failure messages are redacted.
159
+ * @param {string} bin
160
+ * @param {string} url
161
+ * @param {{ chromePath?: string, timeoutMs?: number, host?: Parameters<typeof containerArgs>[0] }} [options] */
162
+ export async function runLighthouse(bin, url, { chromePath, timeoutMs = 90000, host = {} } = {}) {
163
+ const dir = mkdtempSync(join(tmpdir(), "seo-supervisor-lighthouse-")),
164
+ report = join(dir, "report.json");
165
+ const [file, pre] = command(bin);
166
+ const guard = await startGuard(url, { env: host.env ?? process.env });
167
+ // Lighthouse splits --chrome-flags at spaces, outside quotes: a value with a space (the resolver rule) is quoted.
168
+ const chromeFlags = [
169
+ "--headless=new",
170
+ ...CHROME_FLAGS.map(f => (f.includes(" ") ? f.replace("=", '="') + '"' : f)),
171
+ ...containerArgs(host),
172
+ ...(guard?.args || ownProxyArgs(host.env)),
173
+ `--user-data-dir="${quietProfile(join(dir, "profile"))}"`,
174
+ ].join(" ");
175
+ const args = [
176
+ ...pre,
177
+ url,
178
+ "--output=json",
179
+ `--output-path=${report}`,
180
+ "--quiet",
181
+ `--chrome-flags=${chromeFlags}`,
182
+ `--only-categories=performance,seo,accessibility,best-practices${agenticFlag(bin)}`,
183
+ ];
184
+ const env = chromePath ? { ...process.env, CHROME_PATH: chromePath } : process.env;
185
+ // A timeout kills Lighthouse but can leave its Chrome running on Windows, and the profile then stays in the temp
186
+ // folder. Killing the whole process tree would fix both.
187
+ try {
188
+ return await new Promise((ok, fail) =>
189
+ execFile(file, args, { env, timeout: timeoutMs, maxBuffer: 16 * 1024 * 1024 }, (err, stdout, stderr) => {
190
+ let lhr = null;
191
+ try {
192
+ lhr = JSON.parse(readFileSync(report, "utf8"));
193
+ } catch {}
194
+ try {
195
+ rmSync(dir, { recursive: true, force: true });
196
+ } catch {}
197
+ const why = lhr?.runtimeError?.message || (err && (String(stderr).trim().split("\n").pop() || err.message));
198
+ if (why || !lhr) fail(new Error(redact(String(why || "Lighthouse wrote no report")).slice(0, 200)));
199
+ else {
200
+ const agentic = takeAgentic(lhr);
201
+ ok({ ...parse(lhr, url), ...(agentic ? { agentic } : {}) });
202
+ }
203
+ }),
204
+ );
205
+ } finally {
206
+ await guard?.close();
207
+ }
208
+ }
209
+
210
+ // A run takes about 15–25 s a page on a laptop, longer for heavy pages (the timeout is 90 s). ALL_CAP keeps an
211
+ // all-pages run near an hour.
212
+ export const SECONDS_PER_PAGE = 20,
213
+ ALL_CAP = 200;
214
+
215
+ /** Up to 5 sample pages, or with `all` every page up to max, home first. One at a time, since parallel runs skew each
216
+ * other's timings. log gets the time estimate before the first run.
217
+ * @param {string} bin
218
+ * @param {string[]} urls
219
+ * @param {{ chromePath?: string, all?: boolean, max?: number, log?: (message: string) => void }} [options] */
220
+ export async function checkLighthouse(
221
+ bin,
222
+ urls,
223
+ { chromePath, all = false, max = all ? ALL_CAP : 5, log = () => {} } = {},
224
+ ) {
225
+ const home = u => new URL(u).pathname === "/";
226
+ const sample = [...urls].sort((a, b) => +home(b) - +home(a)).slice(0, max);
227
+ const minutes = Math.max(1, Math.round((sample.length * SECONDS_PER_PAGE) / 60));
228
+ log(
229
+ `Lighthouse: ${sample.length} page${sample.length === 1 ? "" : "s"}, about ${minutes} minute${minutes === 1 ? "" : "s"} (roughly ${SECONDS_PER_PAGE} seconds a page), one at a time.`,
230
+ );
231
+ const results = [],
232
+ failures = [];
233
+ for (const url of sample) {
234
+ try {
235
+ results.push(await runLighthouse(bin, url, { chromePath }));
236
+ } catch (e) {
237
+ failures.push(`${new URL(url).pathname}: ${e.message.split("\n")[0]}`);
238
+ if (!results.length) break; // the first page failing usually means Lighthouse or Chrome can't start
239
+ }
240
+ }
241
+ const tried = results.length + failures.length;
242
+ const failed = failures.length
243
+ ? ` Failed: ${failures.slice(0, 5).join("; ")}${failures.length > 5 ? ` and ${failures.length - 5} more` : ""}`
244
+ : "";
245
+ const notes = [
246
+ `Lighthouse ran on ${results.length} of ${tried} ${all ? "" : "sample "}page(s) (mobile, simulated throttling).${failed}`,
247
+ ];
248
+ if (all && urls.length > max)
249
+ notes.push(
250
+ `Lighthouse stopped at ${max} pages, ${max === ALL_CAP ? "its cap for a run on every page" : "the number asked for"}; ${urls.length - max} more page(s) weren't run.`,
251
+ );
252
+ return { results, notes };
253
+ }
254
+
255
+ /** The median score per category across the runs that have one (the middle two's mean, rounded, for an even count). */
256
+ export function medianScores(results) {
257
+ const mid = xs => {
258
+ const s = [...xs].sort((a, b) => a - b),
259
+ h = s.length >> 1;
260
+ return s.length % 2 ? s[h] : Math.round((s[h - 1] + s[h]) / 2);
261
+ };
262
+ return {
263
+ pages: results.length,
264
+ ...Object.fromEntries(
265
+ Object.keys(CATEGORIES)
266
+ .map(k => [k, results.map(r => r.scores?.[k]).filter(Number.isFinite)])
267
+ .filter(([, xs]) => xs.length)
268
+ .map(([k, xs]) => [k, mid(xs)]),
269
+ ),
270
+ };
271
+ }
@@ -0,0 +1,59 @@
1
+ // @ts-check
2
+ // Internal link strength: how much of a site's own linking reaches each page.
3
+
4
+ /** Each page's share of the site's own links, by the 1998 PageRank paper's formula: base share (1 − d)/n, shares
5
+ * summing to 1. It isn't Google's PageRank, which uses the whole web and has changed a lot since.
6
+ * `out` maps every crawled page to the final URLs it links to; self-links, repeats and targets not in `out` (broken,
7
+ * not HTML, past --max) are ignored, so strength is relative to the crawl. A page with no links to other crawled pages
8
+ * spreads its share over every page. Stops when shares move less than 1e-10 in all, or after 200 rounds, a cap that
9
+ * only guards against a bug since 0.85^200 is far below that.
10
+ * Brin and Page, "The Anatomy of a Large-Scale Hypertextual Web Search Engine" (1998).
11
+ * https://developers.google.com/search/docs/appearance/ranking-systems-guide
12
+ * @param {Map<string, Iterable<string>>} out
13
+ * @param {number} [d] damping, 0.85 as in the paper
14
+ * @returns {{ rank: Map<string, number>, base: number }} `base` is the share of a page no other page links to */
15
+ export function pageRank(out, d = 0.85) {
16
+ const ids = [...out.keys()],
17
+ n = ids.length,
18
+ at = new Map(ids.map((u, i) => [u, i]));
19
+ if (!n) return { rank: new Map(), base: 0 };
20
+ const links = ids.map((u, i) =>
21
+ [...new Set([...(out.get(u) || [])].map(t => at.get(t)))].filter(j => j !== undefined && j !== i),
22
+ );
23
+ let pr = new Float64Array(n).fill(1 / n),
24
+ base = 1 / n;
25
+ for (let round = 0; round < 200; round++) {
26
+ let spread = 0;
27
+ for (let i = 0; i < n; i++) if (!links[i].length) spread += pr[i];
28
+ base = (1 - d + d * spread) / n;
29
+ const next = new Float64Array(n).fill(base);
30
+ for (let i = 0; i < n; i++)
31
+ if (links[i].length) {
32
+ const s = (d * pr[i]) / links[i].length;
33
+ for (const j of links[i]) next[j] += s;
34
+ }
35
+ let moved = 0;
36
+ for (let i = 0; i < n; i++) moved += Math.abs(next[i] - pr[i]);
37
+ pr = next;
38
+ if (moved < 1e-10) break;
39
+ }
40
+ return { rank: new Map(ids.map((u, i) => [u, pr[i]])), base };
41
+ }
42
+
43
+ /** 0–100 for the pages in `keep`: 0 is the base share (no inbound links), 100 the strongest page kept. Logarithmic,
44
+ * since the home and menu pages hold most of the share and a linear scale squeezes the rest into 0–5; here doubling
45
+ * a share adds the same points anywhere. With no links at all, every page is 0.
46
+ * @param {Map<string, number>} rank
47
+ * @param {number} base
48
+ * @param {string[]} [keep]
49
+ * @returns {Map<string, number>} */
50
+ export function scale(rank, base, keep = [...rank.keys()]) {
51
+ const top = keep.reduce((m, u) => Math.max(m, rank.get(u) ?? 0), 0),
52
+ span = Math.log(top / base);
53
+ return new Map(
54
+ keep.map(u => [
55
+ u,
56
+ span > 1e-9 ? Math.min(100, Math.max(0, Math.round((100 * Math.log((rank.get(u) ?? base) / base)) / span))) : 0,
57
+ ]),
58
+ );
59
+ }