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,53 @@
1
+ // @ts-check
2
+ // Checks links to other sites. Runs only with the crawler's --outbound-links, since it visits other people's sites.
3
+ import { lookup } from "node:dns";
4
+ import { isPublic, pinnedGet } from "../lib/net.mjs";
5
+
6
+ // Re-exported for callers that import the address guard from here.
7
+ export { privateIp, isPublic, guarded } from "../lib/net.mjs";
8
+
9
+ const UA = "seo-supervisor-links",
10
+ AT_ONCE = 4;
11
+
12
+ export const CHECKS = {
13
+ "outbound-broken": [
14
+ "CRAWL-07",
15
+ "low",
16
+ n => `${n} link(s) to other sites are broken`,
17
+ "These links point at pages on other sites that answer 404 or 410: the page is gone. Visitors who follow them hit a dead end, and a page full of dead links looks neglected.",
18
+ "Update each link to the page's new address, link to another source, or remove it. Links that couldn't be checked (the site turned the visit away or didn't answer) aren't counted here; the notes list them.",
19
+ ],
20
+ };
21
+
22
+ const ok = s => s >= 200 && s < 300;
23
+ // GET only when HEAD gets no 2xx, since some servers refuse HEAD. The body is never read, and a link that couldn't be
24
+ // reached isn't tried again.
25
+ async function probe(url, o) {
26
+ const head = await pinnedGet(url, { method: "HEAD", ...o });
27
+ if (head.reason || ok(head.status)) return head;
28
+ return pinnedGet(url, { method: "GET", ...o });
29
+ }
30
+
31
+ // Private, local and reserved addresses are never visited: allow checks the address each connection uses, on every
32
+ // redirect, and dns (dns.lookup's signature) gives the answer that's checked and used.
33
+ export async function checkOutbound(urls, { limit = 100, timeout = 15000, allow = isPublic, dns = lookup } = {}) {
34
+ const list = [...new Set(urls)].slice(0, limit),
35
+ results = [],
36
+ o = { allow, timeout, dns, headers: { "user-agent": UA, accept: "*/*" } };
37
+ let next = 0;
38
+ await Promise.all(
39
+ Array.from({ length: Math.min(AT_ONCE, list.length) }, async () => {
40
+ while (next < list.length) {
41
+ const i = next++;
42
+ results[i] = { url: list[i], ...(await probe(list[i], o)) };
43
+ }
44
+ }),
45
+ );
46
+ // Only 404 and 410 are broken; a refusal, an error or no answer means the link couldn't be checked.
47
+ return {
48
+ broken: results.filter(r => r.status === 404 || r.status === 410).map(({ url, status }) => ({ url, status })),
49
+ unreachable: results
50
+ .filter(r => r.reason || (!ok(r.status) && r.status !== 404 && r.status !== 410))
51
+ .map(({ url, status, reason }) => ({ url, reason: reason || `the site answered ${status}` })),
52
+ };
53
+ }
@@ -0,0 +1,223 @@
1
+ // @ts-check
2
+ // Per-page checks for seo-crawl.mjs. Thresholds are local, and HTML is read with regexes, as in the crawler.
3
+ import { attrs, headEndOf } from "../lib/html.mjs";
4
+
5
+ const PAID_WORDS = 150; // local threshold for paid text sent in full
6
+ export const CHECKS = {
7
+ // Google suggests rel ugc or nofollow on every link in untrusted content.
8
+ // https://developers.google.com/search/docs/monitor-debug/prevent-abuse
9
+ "ugc-link-followed": [
10
+ "CONTENT-11",
11
+ "low",
12
+ n => `${n} page(s) have links to other sites in comments without rel="ugc" or rel="nofollow"`,
13
+ 'Spammers leave comments to get links to their own sites. Google\'s guidance on user-generated spam says to add `rel="ugc"` or `rel="nofollow"` to all links in content from users you don\'t trust, so those links pass nothing on and the spam isn\'t worth posting. These links sit in a comment section (WordPress-style comment markup, or schema.org Comment markup) and carry neither, nor `rel="sponsored"`. Links your own staff added in a reply, or from users you trust, can stay as they are.',
14
+ 'Add `rel="ugc"` (or `rel="nofollow ugc"`) to links in comments, through the comment template or the comment plugin\'s settings. Google also suggests holding comments for approval and keeping posts from new users out of search (noindex) until they\'ve earned trust.',
15
+ ],
16
+ // Spam since 15 Jun 2026. Google names no code, so the pattern is local.
17
+ // https://developers.google.com/search/blog/2026/04/back-button-hijacking
18
+ "back-button-trap": [
19
+ "CONTENT-11",
20
+ "low",
21
+ n => `${n} page(s) have a script that may stop the Back button working`,
22
+ "Since 15 Jun 2026 Google treats back-button hijacking as spam: a site that changes the browser's history so that Back doesn't return visitors to the page they came from can get a manual action or lose rankings. Google says it can come from a site's ad platform or the libraries it includes. An inline script on these pages adds or changes a history entry as the page loads, with no click (`history.pushState` or `replaceState`), and sends the visitor to another page when they press Back (a `popstate` handler). That's only a possible issue: single-page apps, galleries and filters use the same calls properly. It's fine if pressing Back still takes you to where you came from.",
23
+ 'Open the page from another page, then press Back: you should land where you started. If you don\'t, find the script (often an ad, popup or "before you go" offer) and remove it or turn that feature off. Change the history only when the visitor moves within the page, never on load.',
24
+ ],
25
+ // Hiding sent content with JavaScript isn't a reliable paywall to Google. Applebot skips pages marked
26
+ // isAccessibleForFree false as AI context, judged on the page-level markup only.
27
+ // https://developers.google.com/search/docs/crawling-indexing/javascript/fix-search-javascript
28
+ // https://support.apple.com/en-us/119829
29
+ "paywall-text-sent": [
30
+ "REND-06",
31
+ "low",
32
+ n => `${n} paywalled page(s) send the paid text to every visitor`,
33
+ `The page's structured data marks a section as paid (\`isAccessibleForFree: false\`, with \`hasPart\` naming its CSS class), but the HTML this crawler got without logging in already holds ${PAID_WORDS} or more words in that section (our own cut-off). Google says sending the full text and hiding it with JavaScript "isn't a reliable way to limit access": anyone can read it in the page source or with scripts turned off. Google adds that it makes it hard for Google to tell which content is paid and which isn't. This is fine if the page is free to this visitor on purpose, such as a metered site's free articles. Separately, Apple's Applebot doesn't use pages marked \`isAccessibleForFree: false\` as context for AI answers in Apple products; that follows the page-level markup, whatever the HTML holds.`,
34
+ 'Send the paid section only once the server has confirmed the visitor may read it; Google says the paywall should provide the full content only "once the subscription status is confirmed". Keep the paywall structured data as it is.',
35
+ ],
36
+ // Google reads only the first 2 MB, accepts a canonical only in the head, ends the head at the first element it
37
+ // can't hold, and reads robots meta anywhere. Next.js 15.2+ streams metadata into the body for all but its bot list.
38
+ // https://developers.google.com/search/blog/2026/03/crawler-blog-post
39
+ // https://developers.google.com/search/docs/crawling-indexing/valid-page-metadata
40
+ // https://nextjs.org/blog/next-15-2
41
+ "head-tags-late": [
42
+ "REND-08",
43
+ "low",
44
+ n => `${n} page(s) send their title, description, canonical, robots or hreflang tag after the <head> ends`,
45
+ "These tags came after the page's `<head>` had ended. For Google the head also ends early, at the first element a head can't hold, such as an `<img>`, an `<iframe>` or a tracking pixel: Google then stops reading the head, so the tags after it count as being in the body. Google asks for the title, meta tags and canonical early in the HTML, because it reads only the first 2 MB of a page, and it accepts a canonical only inside the `<head>`, so one sent in the body works only if the page's JavaScript moves it there. Google does read a robots tag anywhere in the page. Next.js 15.2 and later send metadata late on purpose when it loads slowly (\"streamed metadata\"): browsers and Googlebot, which runs JavaScript, get it in the body, while the bots on Next.js's own list, such as Bingbot, Applebot and the link previews of X, Slack and Facebook, get it in the head. This crawler (user agent seo-supervisor-crawler) isn't on that list, so it saw what a browser gets.",
46
+ "Put these tags in the `<head>`, before any element that doesn't belong there (move an `<img>`, `<iframe>` or tracking pixel into the body). In Next.js, make `generateMetadata` fast (cache the data it reads), or list the bots that should get the head version in `htmlLimitedBots` in next.config; `/.*/` turns streaming off. Elsewhere, check the template, component or plugin that writes the tags into the body.",
47
+ ],
48
+ // Google supports relative canonicals but recommends absolute ones, in the HTML and the HTTP header.
49
+ // https://developers.google.com/search/docs/crawling-indexing/consolidate-duplicate-urls
50
+ "canonical-relative": [
51
+ "URL-04",
52
+ "low",
53
+ n => `${n} page(s) give their canonical as a relative URL`,
54
+ "The canonical is written without the site's address (`/page/` or `//host/page/`). Google supports relative canonicals but recommends full URLs: a relative one points at whatever host serves the page, so a staging or test copy that gets crawled names itself as the canonical.",
55
+ "Write the canonical as a full URL on the production origin (`https://www.example.com/page/`), built from one setting such as Next.js `metadataBase`, in the HTML and in any `Link` header.",
56
+ ],
57
+ // One Organization and one WebSite node, with stable @ids, on every page.
58
+ "site-identity-differs": [
59
+ "SCHEMA-02",
60
+ "low",
61
+ n => `${n} page(s) describe the site's organization or website with a different @id or name`,
62
+ "Organization and WebSite structured data say who runs the site and what it's called. Each should be one node with the same `@id` and name on every page, so that every page points at the same organization and site. On these pages the node uses a different `@id` from the one most pages use, or the same `@id` with a different name, so the pages disagree about who runs the site. A relative `@id` such as `#organization` is read against the page it's on, so on `/about/` it names `/about/#organization`, another node from the home page's.",
63
+ "Output the Organization and WebSite nodes from one place, such as the root layout, with fixed `@id`s (`https://your-site/#organization`, `https://your-site/#website`), and take their names from one setting.",
64
+ ],
65
+ };
66
+
67
+ // Takes a whole tag or just the attribute text after its name.
68
+ const attr = (tag, name) => attrs(tag)[name] ?? null;
69
+ const strip = h => h.replace(/<(script|style|noscript|template|svg|textarea)\b[\s\S]*?<\/\1>|<!--[\s\S]*?-->/gi, " ");
70
+ const SEG = new Intl.Segmenter(undefined, { granularity: "word" });
71
+ const wordCount = h => [...SEG.segment(h.replace(/<[^>]+>/g, " "))].filter(s => s.isWordLike).length;
72
+
73
+ // Index just past the matching end tag, or -1. Optional end tags aren't inferred, so an element left open is skipped;
74
+ // a real parser would fix that.
75
+ function elementEnd(html, i, tag) {
76
+ const re = new RegExp(`<(/?)${tag}\\b[^>]*>`, "gi");
77
+ re.lastIndex = i;
78
+ let depth = 0;
79
+ for (let m; (m = re.exec(html));)
80
+ if (!m[1]) depth++;
81
+ else if (--depth === 0) return re.lastIndex;
82
+ return -1;
83
+ }
84
+ // [start, end] of each element whose start tag passes test, outermost only.
85
+ function regions(html, test) {
86
+ const out = [];
87
+ for (const m of html.matchAll(/<([a-z][\w-]*)\b[^>]*>/gi)) {
88
+ if ((out.length && m.index < out[out.length - 1][1]) || !test(m[0])) continue;
89
+ const end = elementEnd(html, m.index, m[1]);
90
+ if (end > 0) out.push([m.index, end]);
91
+ }
92
+ return out;
93
+ }
94
+
95
+ // ---------- links in user content (CONTENT-11) ----------
96
+ // Only documented comment markup counts: WordPress's comment template and schema.org Comment in Microdata or RDFa.
97
+ // A bare "comment" class doesn't (code highlighters use it), nor do forums or reviews a site may write itself.
98
+ const UGC_CLASS = /^(comments-area|comment-list|commentlist|comment-body|comment-content)$/;
99
+ const ugcArea = tag =>
100
+ /comment/i.test(tag) &&
101
+ (/^(comments|comment-\d+)$/.test(attr(tag, "id") || "") ||
102
+ (attr(tag, "class") || "").split(/\s+/).some(c => UGC_CLASS.test(c)) ||
103
+ `${attr(tag, "itemtype") || ""} ${attr(tag, "typeof") || ""}`
104
+ .split(/\s+/)
105
+ .some(t => /(^|[\/#:])(Comment|UserComments)$/.test(t)));
106
+ // Links there without rel ugc, nofollow or sponsored. body is the page body without scripts.
107
+ export const ugcLinks = body =>
108
+ regions(body, ugcArea)
109
+ .flatMap(([s, e]) => [...body.slice(s, e).matchAll(/<a\b[^>]*>/gi)].map(m => m[0]))
110
+ .filter(a => !/\b(ugc|nofollow|sponsored)\b/i.test(attr(a, "rel") || ""))
111
+ .map(a => attr(a, "href")?.trim())
112
+ .filter(Boolean);
113
+
114
+ // ---------- back-button hijacking (CONTENT-11) ----------
115
+ // One inline script that changes history with no user event in it (so on load or a timer) and whose popstate handler
116
+ // navigates within its first 400 characters, a local window.
117
+ const PUSH = /\bhistory\s*\.\s*(pushState|replaceState)\s*\(/,
118
+ POP = /\baddEventListener\s*\(\s*["'`]popstate["'`]|\bonpopstate\s*=/;
119
+ const AWAY = /\blocation\s*(?:\.\s*href\s*)?=(?!=)|\blocation\s*\.\s*(?:replace|assign)\s*\(/;
120
+ const USER =
121
+ /\baddEventListener\s*\(\s*["'`](?:click|submit|change|input|keydown|keyup|keypress|mousedown|mouseup|pointerdown|pointerup|touchstart|touchend)["'`]|\bon(?:click|submit|change|input|keydown|keyup|mousedown|pointerdown|touchstart)\s*=|\.on\(\s*["'](?:click|submit|change)|\.(?:click|submit|change)\(\s*function/;
122
+ export function backTrap(html) {
123
+ for (const [, a, js] of html.matchAll(/<script\b([^>]*)>([\s\S]*?)<\/script>/gi)) {
124
+ if (
125
+ /\ssrc\s*=/i.test(a) ||
126
+ !/^((text|application)\/(x-)?(java|ecma)script|module)?$/i.test((attr(a, "type") || "").trim())
127
+ )
128
+ continue;
129
+ const push = PUSH.exec(js),
130
+ pop = POP.exec(js);
131
+ if (push && pop && !USER.test(js) && AWAY.test(js.slice(pop.index, pop.index + 400)))
132
+ return `an inline script calls history.${push[1]} with no click, and sends the visitor to another page on Back (popstate)`;
133
+ }
134
+ return null;
135
+ }
136
+
137
+ // ---------- paid text sent in full (REND-06) ----------
138
+ // Google's paywall markup: isAccessibleForFree false, with hasPart elements marked the same and a .class cssSelector.
139
+ // https://developers.google.com/search/docs/appearance/structured-data/paywalled-content
140
+ const paid = v => v === false || /^false$/i.test(String(v ?? ""));
141
+ export function paywallLeak(body, nodes) {
142
+ const classes = new Set(),
143
+ walk = (o, d) => {
144
+ if (!o || typeof o !== "object" || d > 12) return;
145
+ if (paid(o.isAccessibleForFree))
146
+ for (const part of [].concat(o.hasPart ?? []))
147
+ if (part && paid(part.isAccessibleForFree))
148
+ for (const s of [].concat(part.cssSelector ?? []))
149
+ if (typeof s === "string" && /^\.[\w-]+$/.test(s.trim())) classes.add(s.trim().slice(1));
150
+ Object.values(o).forEach(x => walk(x, d + 1));
151
+ };
152
+ nodes.forEach(n => walk(n, 0));
153
+ if (!classes.size) return null;
154
+ const has = tag => (attr(tag, "class") || "").split(/\s+/).some(c => classes.has(c));
155
+ const words = regions(body, tag => /class/i.test(tag) && has(tag)).reduce(
156
+ (n, [s, e]) => n + wordCount(body.slice(s, e)),
157
+ 0,
158
+ );
159
+ return words >= PAID_WORDS ? { selector: [...classes].map(c => "." + c).join(", "), words } : null;
160
+ }
161
+
162
+ // ---------- head tags after the head ends (REND-08) ----------
163
+ // The head ends where Google ends it (headEndOf): at </head>, <body> or the first element a head can't hold.
164
+ // When nothing ends it (at < 0), no tag can be called late.
165
+ export function lateHead(html, at = headEndOf(html).at) {
166
+ if (at < 0) return [];
167
+ const found = new Set();
168
+ for (const [tag, name] of strip(html.slice(at)).matchAll(/<(title|meta|link)\b[^>]*>/gi)) {
169
+ const t = name.toLowerCase(),
170
+ n = (attr(tag, "name") || "").toLowerCase(),
171
+ rel = (attr(tag, "rel") || "").toLowerCase().split(/\s+/);
172
+ if (t === "title") found.add("title");
173
+ else if (t === "meta" && n === "description") found.add("description");
174
+ else if (t === "meta" && (n === "robots" || n === "googlebot")) found.add("robots");
175
+ else if (t === "link" && rel.includes("canonical")) found.add("canonical");
176
+ else if (t === "link" && rel.includes("alternate") && attr(tag, "hreflang")) found.add("hreflang");
177
+ }
178
+ return ["title", "description", "canonical", "robots", "hreflang"].filter(x => found.has(x));
179
+ }
180
+
181
+ // ---------- the site's identity (SCHEMA-02) ----------
182
+ // The most common value and its count, or [] when there's none or a tie.
183
+ const tally = list => {
184
+ const m = new Map();
185
+ for (const k of list) m.set(k, (m.get(k) || 0) + 1);
186
+ const [[top, n] = [], [, next] = []] = [...m].sort((a, b) => b[1] - a[1]);
187
+ return n > (next ?? 0) ? [top, n] : [];
188
+ };
189
+ // A relative @id ("#organization") resolves against the page it's on, so it names a different node on each page.
190
+ // https://www.w3.org/TR/json-ld11/#iris
191
+ const idOf = (id, page) => {
192
+ if (typeof id !== "string" || !id.trim()) return null;
193
+ for (const base of [undefined, page])
194
+ try {
195
+ return new URL(id.trim(), base).href;
196
+ } catch {}
197
+ return id.trim();
198
+ };
199
+ const nameOf = s => (typeof s === "string" && s.trim() ? s.replace(/\s+/g, " ").trim() : null);
200
+ // pages: [{ url, org: [{ id, name }], site: [{ id, name }] }]. The site's @id is the one most pages use, and its name
201
+ // the one most of those give. A node with neither is another organization (a partner, a client), and without @ids one
202
+ // organization can't be told from two, so neither is flagged. Returns url -> detail.
203
+ export function identityDrift(pages) {
204
+ const out = new Map(),
205
+ note = (url, s) => out.set(url, out.has(url) ? `${out.get(url)}; ${s}` : s);
206
+ for (const [kind, label] of [
207
+ ["org", "Organization"],
208
+ ["site", "WebSite"],
209
+ ]) {
210
+ const nodes = pages.map(p => p[kind].map(x => ({ id: idOf(x.id, p.url), name: nameOf(x.name) })));
211
+ const [id, onPages] = tally(nodes.flatMap(ns => [...new Set(ns.map(x => x.id).filter(Boolean))]));
212
+ if (!id || onPages < 2) continue;
213
+ const [name] = tally(nodes.flatMap(ns => [...new Set(ns.filter(x => x.id === id && x.name).map(x => x.name))]));
214
+ nodes.forEach((ns, i) => {
215
+ if (ns.some(x => x.id === id && (!name || !x.name || x.name === name))) return;
216
+ const renamed = ns.find(x => x.id === id),
217
+ moved = name && ns.find(x => x.id && x.name === name);
218
+ if (renamed) note(pages[i].url, `${label} name “${renamed.name}” for ${id}, where other pages say “${name}”`);
219
+ else if (moved) note(pages[i].url, `${label} @id ${moved.id}, where other pages use ${id}`);
220
+ });
221
+ }
222
+ return out;
223
+ }
@@ -0,0 +1,130 @@
1
+ // @ts-check
2
+ // Probes run after the crawl: soft 404, llms.txt, Markdown negotiation, security.txt and security headers.
3
+ import { isLocal } from "../crawl/fetch.mjs";
4
+ import { pool } from "../crawl/queue.mjs";
5
+ import { tagsOf } from "../lib/html.mjs";
6
+
7
+ const noindexed = r =>
8
+ /\b(noindex|none)\b/i.test(r.headers?.get?.("x-robots-tag") || "") ||
9
+ tagsOf(r.body || "", "meta").some(
10
+ m => /^(robots|googlebot)$/i.test(m.name || "") && /\b(noindex|none)\b/i.test(m.content || ""),
11
+ );
12
+
13
+ // Returns the start page's Markdown, or null, for site-hygiene.mjs markdownCheck. checkLive is --check-live, which
14
+ // reads HSTS on the live origin itself; pages (the crawl's records) give the top sections to probe.
15
+ export async function probeSite({
16
+ start: START,
17
+ startOrigin: START_ORIGIN,
18
+ expectOrigin: EXPECT_ORIGIN,
19
+ checkLive: CHECK_LIVE,
20
+ conc: CONC = 1,
21
+ home,
22
+ add,
23
+ evalRules,
24
+ notes,
25
+ follow,
26
+ get,
27
+ pages = new Map(),
28
+ }) {
29
+ evalRules("CRAWL-05", "URL-02", "TRUST-01", "TRUST-02");
30
+ // A made-up URL at the root and in up to 10 top sections (local cap), largest first, since a dynamic route
31
+ // (/blog/[slug]) can answer 200 for any slug. Once the root answers 200 the sections would only repeat it. A 200 with
32
+ // noindex is low: Google accepts noindex on error pages where a real status is impractical.
33
+ // https://developers.google.com/search/docs/crawling-indexing/javascript/javascript-seo-basics
34
+ const id = Date.now().toString(36),
35
+ sections = new Map();
36
+ for (const p of pages.values()) {
37
+ const s = p.html && p.finalUrl && new URL(p.finalUrl).pathname.split("/").filter(Boolean);
38
+ if (s?.length > 1) sections.set(s[0], (sections.get(s[0]) || 0) + 1);
39
+ }
40
+ for (const path of [
41
+ "",
42
+ ...[...sections]
43
+ .sort((a, b) => b[1] - a[1])
44
+ .slice(0, 10)
45
+ .map(([s]) => `/${s}`),
46
+ ]) {
47
+ const probe = await follow(`${START_ORIGIN}${path}/seo-supervisor-404-probe-${id}`);
48
+ if (probe.status !== 200) continue;
49
+ add(
50
+ noindexed(probe) ? "soft-404-noindex" : "soft-404",
51
+ probe.chain[0].url,
52
+ probe.chain.length > 1 ? `redirected to ${probe.finalUrl} (200)` : "returned 200",
53
+ );
54
+ if (!path) break;
55
+ }
56
+ // The Markdown request isn't followed, so only the crawled URL's own answer counts.
57
+ const [llms, md, sectxt] = await pool(
58
+ [
59
+ () => get(START_ORIGIN + "/llms.txt", { manual: false }),
60
+ () => get(START.href, { accept: "text/markdown", text: /^text\/markdown/i }),
61
+ () => get(START_ORIGIN + "/.well-known/security.txt", { manual: false }),
62
+ ],
63
+ CONC,
64
+ f => f(),
65
+ );
66
+ // A missing llms.txt is only low and never a ranking fix: Google says it neither harms nor helps rankings. An HTML
67
+ // page there counts as missing.
68
+ evalRules("MAP-07");
69
+ if (llms.status !== 200 || /<html/i.test(llms.body || ""))
70
+ add(
71
+ "llms-txt-missing",
72
+ START_ORIGIN + "/llms.txt",
73
+ llms.status === 200 ? "returns an HTML page instead" : `status ${llms.status}`,
74
+ );
75
+ else {
76
+ const problems = [
77
+ !/^# \S/.test(llms.body.replace(/^\uFEFF/, "").trimStart()) && "no # heading first",
78
+ !/\[[^\]]+\]\([^)\s]+\)/.test(llms.body) && "no Markdown links",
79
+ ].filter(Boolean);
80
+ if (problems.length) add("llms-structure", START_ORIGIN + "/llms.txt", problems.join(", "));
81
+ }
82
+ // A Markdown response must vary on Accept so caches keep it apart from the HTML. AI-05 counts as checked only when
83
+ // the site serves Markdown; otherwise the code-level check decides it. mdHome saves markdownCheck a second fetch.
84
+ /** @type {string | null} */
85
+ let mdHome = null;
86
+ const isMd = /^text\/markdown/i.test(md.ct);
87
+ if (isMd) evalRules("AI-05");
88
+ const vary = (md.headers?.get("vary") || "")
89
+ .toLowerCase()
90
+ .split(",")
91
+ .map(v => v.trim()); // Accept-Encoding isn't Accept
92
+ if (isMd && !vary.includes("accept") && !vary.includes("*"))
93
+ add("markdown-no-vary", START.href, `Vary: ${md.headers?.get("vary") || "(none)"}`);
94
+ if (md.status === 200 && isMd && !md.over) mdHome = md.body;
95
+ if (sectxt.status !== 200 || /<html/i.test(sectxt.body || ""))
96
+ add(
97
+ "security-txt",
98
+ START_ORIGIN + "/.well-known/security.txt",
99
+ sectxt.status === 200 ? "returns an HTML page instead (soft 404)" : `status ${sectxt.status}`,
100
+ );
101
+ if (home && home.headers) {
102
+ const h = home.headers,
103
+ missing = [];
104
+ if (
105
+ !CHECK_LIVE &&
106
+ EXPECT_ORIGIN.startsWith("https") &&
107
+ START_ORIGIN.startsWith("https") &&
108
+ !h.get("strict-transport-security")
109
+ )
110
+ add("no-hsts", home.finalUrl); // one id with or without --check-live (checks/tls.mjs)
111
+ if (!h.get("x-content-type-options")) missing.push("X-Content-Type-Options");
112
+ if (!h.get("referrer-policy")) missing.push("Referrer-Policy");
113
+ // A Report-Only policy monitors without enforcing, so it doesn't count as a CSP.
114
+ // https://www.w3.org/TR/CSP3/#cspro-header
115
+ if (!h.get("content-security-policy"))
116
+ missing.push(
117
+ h.get("content-security-policy-report-only")
118
+ ? "Content-Security-Policy (only a Report-Only policy, which blocks nothing)"
119
+ : "Content-Security-Policy",
120
+ );
121
+ if (!h.get("x-frame-options") && !/frame-ancestors/i.test(h.get("content-security-policy") || ""))
122
+ missing.push("X-Frame-Options or CSP frame-ancestors");
123
+ for (const m of missing) add("sec-headers", home.finalUrl, m);
124
+ if (isLocal(START_ORIGIN))
125
+ notes.push(
126
+ "Security headers were read from a local server; production headers set by a CDN or proxy may differ.",
127
+ );
128
+ }
129
+ return mdHome;
130
+ }