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,462 @@
1
+ #!/usr/bin/env node
2
+ // @ts-check
3
+ // Fast post-deploy check for CI: exits 1 on anything that keeps search engines out, 2 on bad usage.
4
+ import { lookup as dnsLookup } from "node:dns";
5
+ import { isMain } from "./lib/is-main.mjs";
6
+ import { parseArgs } from "./lib/args.mjs";
7
+ import { Fail, runMain, warnProxy } from "./lib/cli.mjs";
8
+ import { isPublic, pinnedGet } from "./lib/net.mjs";
9
+ import { tlsCert } from "./checks/tls.mjs";
10
+ import { allowedBy, groupFor, groupOf, parseRobots } from "./lib/robots.mjs";
11
+ import { VERSION } from "./update-check.mjs";
12
+ import { anomaliesIn, anomalyNote, searchConsole } from "./google/search-console.mjs";
13
+
14
+ const UA = "seo-supervisor-deploy-check/" + VERSION,
15
+ TIMEOUT = 10000,
16
+ DAY = 864e5;
17
+
18
+ // Redirects are followed by hand, 5 at most. Off the site's origin the address must be public, and pinnedGet connects
19
+ // only to the address it checked, so a name can't pass the check and then resolve elsewhere (DNS rebinding).
20
+ async function load(url, origin, { fetchFn, lookup }) {
21
+ let hops = 0;
22
+ try {
23
+ for (; hops <= 5; hops++) {
24
+ if (new URL(url).origin !== origin) {
25
+ if (!isPublic(url))
26
+ return { error: `${new URL(url).host} isn't a public address, so it wasn't visited`, url, hops };
27
+ let asked = 0;
28
+ const got = await pinnedGet(url, {
29
+ headers: { "user-agent": UA },
30
+ dns: lookup,
31
+ timeout: TIMEOUT,
32
+ hops: 5 - hops,
33
+ allow: u => (asked++, isPublic(u)),
34
+ read: (r, u) => ({ res: asResponse(r), url: u }),
35
+ });
36
+ return got.reason
37
+ ? { error: got.reason.replace(/^couldn't connect \((\w+)\)$/, (m, c) => (WHY[c] ? why(c) : m)), url, hops }
38
+ : { ...got, hops: hops + asked - 1 };
39
+ }
40
+ const res = await fetchFn(url, {
41
+ redirect: "manual",
42
+ headers: { "user-agent": UA },
43
+ signal: AbortSignal.timeout(TIMEOUT),
44
+ });
45
+ const loc = res.status >= 300 && res.status < 400 && res.headers.get("location");
46
+ if (!loc) return { res, url, hops };
47
+ await res.body?.cancel();
48
+ url = new URL(loc, url).href;
49
+ }
50
+ return { error: "it redirects more than 5 times", url, hops };
51
+ } catch (e) {
52
+ return {
53
+ error:
54
+ e.name === "TimeoutError"
55
+ ? `no answer within ${TIMEOUT / 1000} seconds`
56
+ : why(e.cause?.code) || e.cause?.message || e.message,
57
+ url,
58
+ hops,
59
+ };
60
+ }
61
+ }
62
+ // pinnedGet's answer, shaped like the parts of a fetch() Response the checks read.
63
+ const asResponse = r => ({
64
+ status: r.statusCode,
65
+ headers: {
66
+ get: k => {
67
+ const v = r.headers[k.toLowerCase()];
68
+ return v == null ? null : [v].flat().join(", ");
69
+ },
70
+ },
71
+ text: async () => {
72
+ let s = "";
73
+ r.setEncoding("utf8");
74
+ for await (const c of r) s += c;
75
+ return s;
76
+ },
77
+ body: {
78
+ cancel: async () => {
79
+ r.destroy();
80
+ },
81
+ },
82
+ });
83
+ const WHY = {
84
+ ECONNREFUSED: "the server refused the connection",
85
+ ECONNRESET: "the connection was dropped",
86
+ ETIMEDOUT: "the connection timed out",
87
+ ENOTFOUND: "the name isn't in DNS",
88
+ EAI_AGAIN: "DNS didn't answer",
89
+ CERT_HAS_EXPIRED: "the certificate has expired",
90
+ };
91
+ const why = code => code && (WHY[code] ? `${WHY[code]} (${code})` : code);
92
+
93
+ const attr = (tag, name) => {
94
+ const m = new RegExp(`\\s${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^\\s>]+))`, "i").exec(tag);
95
+ return m ? (m[1] ?? m[2] ?? m[3]) : null;
96
+ };
97
+ const tags = (html, el) => html.match(new RegExp(`<${el}\\b[^>]*>`, "gi")) || [];
98
+ // noindex, or none (which includes it). Another crawler's directive, and max-image-preview's "none" value, aren't
99
+ // Google's noindex. https://developers.google.com/search/docs/crawling-indexing/robots-meta-tag
100
+ // Known limit: a directive after another crawler's name ("otherbot: nofollow, noindex") reads as everyone's. Carry the
101
+ // crawler name across the list, as backlinks.mjs pageNofollow does, if that matters.
102
+ function noindexOf(html, header) {
103
+ const meta = tags(html, "meta")
104
+ .filter(t => /^(robots|googlebot)$/i.test(attr(t, "name") || ""))
105
+ .find(t => (attr(t, "content") || "").split(",").some(d => /^(noindex|none)$/i.test(d.trim())));
106
+ if (meta) return `a meta tag says ${meta}`;
107
+ const h = (header || "")
108
+ .split(",")
109
+ .map(d => d.trim())
110
+ .find(d => {
111
+ const m = /^(?:([a-z][\w-]*)\s*:\s*)?(noindex|none)$/i.exec(d);
112
+ return m && (!m[1] || /^googlebot$/i.test(m[1]));
113
+ });
114
+ return h ? `the X-Robots-Tag header says ${h}` : null;
115
+ }
116
+
117
+ /** The checks, in order, each { id, state: "ok" | "warning" | "blocker" | "skipped", text }.
118
+ * @param {string} site
119
+ * @param {{ fetchFn?: typeof fetch, connect?: typeof tlsCert, lookup?: any, now?: number }} [options] */
120
+ export async function deployCheck(
121
+ site,
122
+ { fetchFn = fetch, connect = tlsCert, lookup = dnsLookup, now = Date.now() } = {},
123
+ ) {
124
+ const t0 = Date.now(),
125
+ origin = new URL(site).origin,
126
+ o = { fetchFn, lookup },
127
+ checks = [];
128
+ const put = (id, state, text) => checks.push({ id, state, text });
129
+ const https = origin.startsWith("https:"),
130
+ host = new URL(origin).hostname,
131
+ port = Number(new URL(origin).port) || 443;
132
+ const [home, robots, cert] = await Promise.all([
133
+ load(origin + "/", origin, o).then(async r => ({
134
+ ...r,
135
+ body: r.res?.status === 200 ? await r.res.text().catch(() => "") : (await r.res?.body?.cancel(), ""),
136
+ })),
137
+ load(origin + "/robots.txt", origin, o).then(async r => ({
138
+ ...r,
139
+ body: r.res?.status === 200 ? await r.res.text().catch(() => "") : (await r.res?.body?.cancel(), ""),
140
+ })),
141
+ https
142
+ ? connect(host, port, TIMEOUT).then(
143
+ c => ({ c, error: null }),
144
+ e => ({ c: null, error: why(e.code) || e.message }),
145
+ )
146
+ : null,
147
+ ]);
148
+ const via = home.hops ? ` after ${home.hops === 1 ? "a redirect" : `${home.hops} redirects`} to ${home.url}` : "";
149
+ const homeOk = home.res?.status === 200;
150
+ if (home.error) put("home", "blocker", `The home page didn't answer: ${home.error}.`);
151
+ else put("home", homeOk ? "ok" : "blocker", `The home page answers ${home.res.status}${via}.`);
152
+ if (!homeOk) put("noindex", "skipped", "The home page didn't load, so its robots rules weren't read.");
153
+ else {
154
+ const n = noindexOf(home.body, home.res.headers.get("x-robots-tag"));
155
+ put(
156
+ "noindex",
157
+ n ? "blocker" : "ok",
158
+ n
159
+ ? `The home page is noindex: ${n}. Search engines drop it, and often the whole site follows.`
160
+ : "The home page isn't noindex.",
161
+ );
162
+ }
163
+ // Google halts crawling the whole site while robots.txt answers 5xx or 429, and reads a 4xx as no rules. Right after
164
+ // a deploy that halt is immediate, so it's a blocker.
165
+ // https://developers.google.com/search/docs/crawling-indexing/robots/robots_txt
166
+ const rs = robots.res?.status,
167
+ txt = rs === 200 && !/<html/i.test(robots.body) ? robots.body : null;
168
+ // Googlebot obeys only its own group, or `User-agent: *` when it has none.
169
+ const rules = txt != null ? parseRobots(txt) : null,
170
+ ownGoogle = rules && groupFor(rules, "googlebot");
171
+ if (robots.error || rs >= 500 || rs === 429)
172
+ put(
173
+ "robots",
174
+ "blocker",
175
+ `robots.txt ${robots.error ? `didn't answer: ${robots.error}` : `answers ${rs}`}. Google stops crawling the whole site while it fails.`,
176
+ );
177
+ else if (!rules)
178
+ put(
179
+ "robots",
180
+ "warning",
181
+ `robots.txt ${rs === 200 ? "is an HTML page, not a robots.txt file" : `answers ${rs}`}, so Google reads it as no rules: nothing is blocked, and no sitemap is listed there.`,
182
+ );
183
+ else if (!allowedBy(groupOf(rules, "googlebot"), "/"))
184
+ put(
185
+ "robots",
186
+ "blocker",
187
+ ownGoogle
188
+ ? "robots.txt blocks Googlebot from the whole site (its own User-agent: Googlebot group)."
189
+ : "robots.txt blocks every crawler without a group of its own (User-agent: *) from the whole site, Googlebot included.",
190
+ );
191
+ else if (!allowedBy(groupFor(rules, "*"), "/"))
192
+ put(
193
+ "robots",
194
+ "warning",
195
+ "robots.txt blocks every crawler without a group of its own (User-agent: *) from the whole site. Googlebot has its own group that lets it in, but Bing and other search engines without a group are kept out.",
196
+ );
197
+ else put("robots", "ok", "robots.txt doesn't block the home page.");
198
+ if (!rules?.sitemaps.length)
199
+ put(
200
+ "sitemap",
201
+ "warning",
202
+ rules ? "robots.txt lists no sitemap (no Sitemap: line)." : "No sitemap could be read from robots.txt.",
203
+ );
204
+ else {
205
+ const list = rules.sitemaps.slice(0, 5),
206
+ got = await Promise.all(
207
+ list.map(u => {
208
+ try {
209
+ return load(new URL(u).href, origin, o).then(async r => (await r.res?.body?.cancel(), r));
210
+ } catch {
211
+ return { error: "it isn't a valid URL", url: u, hops: [] };
212
+ }
213
+ }),
214
+ );
215
+ const bad = got.map((r, i) => [list[i], r]).filter(([, r]) => r.res?.status !== 200);
216
+ put(
217
+ "sitemap",
218
+ bad.length ? "warning" : "ok",
219
+ bad.length
220
+ ? `The sitemap ${bad.map(([u, r]) => `${u} ${r.error ? `wasn't reached: ${r.error}` : `answers ${r.res.status}`}`).join("; ")}.`
221
+ : `robots.txt lists ${list.length === 1 ? "the sitemap" : `${list.length} sitemaps`}, and ${list.length === 1 ? "it answers" : "each answers"} 200.`,
222
+ );
223
+ }
224
+ if (!homeOk) put("canonical", "skipped", "The home page didn't load, so its canonical wasn't read.");
225
+ else {
226
+ const hrefs = tags(home.body, "link")
227
+ .filter(t => (attr(t, "rel") || "").toLowerCase().split(/\s+/).includes("canonical"))
228
+ .map(t => attr(t, "href") || "");
229
+ const self = new URL(home.url);
230
+ self.hash = "";
231
+ const to =
232
+ hrefs.length === 1
233
+ ? (() => {
234
+ try {
235
+ const x = new URL(hrefs[0], home.url);
236
+ x.hash = "";
237
+ return x.href;
238
+ } catch {
239
+ return hrefs[0];
240
+ }
241
+ })()
242
+ : null;
243
+ if (!hrefs.length) put("canonical", "warning", "The home page has no canonical tag.");
244
+ else if (hrefs.length > 1)
245
+ put(
246
+ "canonical",
247
+ "warning",
248
+ `The home page has ${hrefs.length} canonical tags, so search engines ignore them all.`,
249
+ );
250
+ else
251
+ put(
252
+ "canonical",
253
+ to === self.href ? "ok" : "warning",
254
+ to === self.href
255
+ ? "The home page's canonical points to itself."
256
+ : `The home page's canonical points to ${to}, not to itself (${self.href}).`,
257
+ );
258
+ }
259
+ // Same thresholds as checks/tls.mjs checkLive. Under a third of its lifetime and under 30 days left usually means
260
+ // automatic renewal stopped.
261
+ if (!cert) put("certificate", "skipped", "The site isn't on https://, so there's no certificate to check.");
262
+ else if (!cert.c) put("certificate", "warning", `The certificate couldn't be read: ${cert.error}.`);
263
+ else {
264
+ const c = cert.c,
265
+ to = Date.parse(c.valid_to),
266
+ from = Date.parse(c.valid_from),
267
+ left = to - now,
268
+ days = Math.floor(left / DAY);
269
+ if (!c.authorized && c.authorizationError !== "CERT_HAS_EXPIRED")
270
+ put(
271
+ "certificate",
272
+ "blocker",
273
+ `The certificate isn't trusted (${c.authorizationError || "not trusted"}). Browsers show a full-page warning.`,
274
+ );
275
+ else if (left < 2 * DAY)
276
+ put(
277
+ "certificate",
278
+ "blocker",
279
+ left < 0
280
+ ? `The certificate expired on ${c.valid_to}.`
281
+ : `The certificate expires within 2 days (${c.valid_to}). Renew it now.`,
282
+ );
283
+ else if (left < Math.min(isNaN(from) ? Infinity : (to - from) / 3, 30 * DAY))
284
+ put(
285
+ "certificate",
286
+ "warning",
287
+ `The certificate has ${days} days left (until ${c.valid_to}). Automatic renewal may have stopped.`,
288
+ );
289
+ else put("certificate", "ok", `The certificate has ${days} days left (until ${c.valid_to}).`);
290
+ }
291
+ const count = s => checks.filter(c => c.state === s).length;
292
+ return {
293
+ site: origin,
294
+ checkedAt: new Date(now).toISOString(),
295
+ seconds: Math.round((Date.now() - t0) / 100) / 10,
296
+ blockers: count("blocker"),
297
+ warnings: count("warning"),
298
+ checks,
299
+ };
300
+ }
301
+
302
+ // ---------- --search-console: Google Search clicks hour by hour ----------
303
+ // Local thresholds: warn at a 30% fall in clicks, judged only with 100+ clicks a week before; with fewer, an ordinary
304
+ // slow hour looks like a fall.
305
+ const HOUR = 36e5,
306
+ WEEK = 7 * DAY,
307
+ DROP = 30,
308
+ MIN_CLICKS = 100;
309
+ // Search Analytics takes dates, and returns hours, in Pacific Time.
310
+ // https://developers.google.com/webmaster-tools/v1/searchanalytics/query
311
+ const ptDate = t => new Date(t).toLocaleDateString("en-CA", { timeZone: "America/Los_Angeles" }); // YYYY-MM-DD
312
+ const utc = t => new Date(t).toISOString().slice(0, 16).replace("T", " ") + " UTC";
313
+ const iso = t => new Date(t).toISOString();
314
+ const pct = (a, b) => (b ? Math.round((a / b - 1) * 100) : null);
315
+ const pc = p => (p == null ? "" : ` (${p > 0 ? "+" : ""}${p}%)`),
316
+ vs = (a, b, p) => `${a}, against ${b} in the same hours a week before${pc(p)}`;
317
+ const SINCE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d+)?)?(Z|[+-]\d{2}:\d{2})$/i;
318
+
319
+ /** Clicks in the hours since `since` (an ISO time; default Google's last 24 hours) beside the same hours a week before,
320
+ * as { state: "ok" | "warning" | "too-little-data" | "skipped", text, ... }. Never throws for Google's answers.
321
+ * @param {{ site: string, since?: string | null, now?: number, home?: string, endpoints?: any }} opts */
322
+ export async function searchHourly({ site, since, now = Date.now(), home, endpoints }) {
323
+ const skip = text => ({ state: "skipped", text }),
324
+ t = since ? Date.parse(since) : null;
325
+ if (t != null && t > now) return skip(`--since (${since}) is in the future, so there's nothing to compare yet.`);
326
+ if (t != null && t < now - 2 * DAY)
327
+ return skip(
328
+ `--since (${since}) is more than 2 days ago. Google keeps hourly data for 10 days, and the same hours a week before have to fit in them. For an older deploy, change-check.mjs compares whole days.`,
329
+ );
330
+ let sc, res;
331
+ try {
332
+ sc = await searchConsole({ site, home, endpoints });
333
+ // Hourly data covers up to 10 days and may be partial; Google suggests comparing with the same day a week before.
334
+ // https://developers.google.com/search/blog/2025/04/san-hourly-data
335
+ res = await sc.query({
336
+ startDate: ptDate(now - 9 * DAY),
337
+ endDate: ptDate(now),
338
+ type: "web",
339
+ dimensions: ["hour"],
340
+ dataState: "hourly_all",
341
+ });
342
+ } catch (e) {
343
+ return skip(`Google Search wasn't read: ${sc ? sc.explain(e) : String(e.message).replace(/^google: /, "")}`);
344
+ }
345
+ const little = text => ({ state: "too-little-data", property: sc.prop, text: `${text} This isn't a drop.` });
346
+ const got = new Map();
347
+ for (const r of res.rows || []) {
348
+ const h = Date.parse(r.keys?.[0]);
349
+ if (!isNaN(h)) got.set(h, { clicks: Number(r.clicks) || 0, impressions: Number(r.impressions) || 0 });
350
+ }
351
+ if (!got.size)
352
+ return little("Too little data to tell: Search Console has no hourly data for this site in the last 10 days.");
353
+ // Up to Google's latest hour; the deploy's own hour is left out (Pacific offsets are whole hours, so hours line up).
354
+ const end = Math.max(...got.keys()) + HOUR,
355
+ from = t != null ? Math.ceil(t / HOUR) * HOUR : end - 24 * HOUR;
356
+ if (from >= end)
357
+ return little(
358
+ `Too early to tell: Google's hourly data so far ends at ${utc(end)}, before the first full hour after the deploy. It shows up a few hours late, so run this again later.`,
359
+ );
360
+ const none = { clicks: 0, impressions: 0 },
361
+ hours = []; // an hour with no row had no impressions
362
+ for (let h = from; h < end; h += HOUR)
363
+ hours.push({ hour: iso(h), ...(got.get(h) || none), weekBefore: got.get(h - WEEK) || none });
364
+ const sum = (k, wb) => hours.reduce((s, x) => s + (wb ? x.weekBefore[k] : x[k]), 0);
365
+ const after = { from: iso(from), to: iso(end), clicks: sum("clicks"), impressions: sum("impressions") };
366
+ const before = {
367
+ from: iso(from - WEEK),
368
+ to: iso(end - WEEK),
369
+ clicks: sum("clicks", true),
370
+ impressions: sum("impressions", true),
371
+ };
372
+ const change = { clicks: pct(after.clicks, before.clicks), impressions: pct(after.impressions, before.impressions) };
373
+ const span = `${hours.length} hour${hours.length === 1 ? "" : "s"} from ${utc(from)} to ${utc(end)}`,
374
+ imp = ` Impressions: ${after.impressions} against ${before.impressions}${pc(change.impressions)}.`;
375
+ // firstIncompleteHour is the first hour Google is still collecting; the API's prose spells it first_incomplete_hour.
376
+ const notes = [],
377
+ m = res.metadata || {},
378
+ open = Date.parse(m.firstIncompleteHour ?? m.first_incomplete_hour);
379
+ if (open < end)
380
+ notes.push(
381
+ `Google is still collecting the data for the hours from ${utc(Math.max(open, from))} on, so those numbers may still change.`,
382
+ );
383
+ for (const a of anomaliesIn(ptDate(from - WEEK), ptDate(end))) notes.push(anomalyNote(a, "the hours compared"));
384
+ const base = {
385
+ property: sc.prop,
386
+ after,
387
+ before,
388
+ change,
389
+ hours,
390
+ stillCollectingFrom: isNaN(open) ? null : iso(open),
391
+ notes,
392
+ };
393
+ if (before.clicks < MIN_CLICKS)
394
+ return {
395
+ ...base,
396
+ state: "too-little-data",
397
+ text: `Too little data to tell: ${before.clicks} Google Search clicks in the same hours a week before, and a fair comparison needs at least ${MIN_CLICKS} (our own minimum). This isn't a drop. The ${span} had ${after.clicks} clicks and ${after.impressions} impressions.`,
398
+ };
399
+ if (change.clicks <= -DROP)
400
+ return {
401
+ ...base,
402
+ state: "warning",
403
+ text: `Google Search clicks fell ${-change.clicks}% in the ${span}: ${vs(after.clicks, before.clicks)}.${imp} A fall of ${DROP}% or more is our own line for this warning. Look at what the deploy changed, then check again in a few hours.`,
404
+ };
405
+ return {
406
+ ...base,
407
+ state: "ok",
408
+ text: `Google Search clicks in the ${span}: ${vs(after.clicks, before.clicks, change.clicks)}.${imp}`,
409
+ };
410
+ }
411
+
412
+ const LABEL = { ok: "OK", warning: "WARNING", blocker: "BLOCKER", skipped: "SKIPPED", "too-little-data": "INFO" };
413
+ const NOISY =
414
+ "Hourly data is fresh and noisy: a slow hour, a holiday or a Google update can move it, so take it as a hint, not proof. This part never fails the deploy check.";
415
+ const hourlyOf = h => [
416
+ "",
417
+ "Google Search clicks, hour by hour, from your Search Console:",
418
+ ` ${LABEL[h.state].padEnd(8)} ${h.text}`,
419
+ ...[...(h.notes || []), ...(h.state === "skipped" ? [] : [NOISY])].map(n => ` ${n}`),
420
+ ];
421
+ export const textOf = r =>
422
+ [
423
+ `Deploy check for ${r.site} (${r.seconds} s)`,
424
+ ...r.checks.map(c => ` ${LABEL[c.state].padEnd(8)} ${c.text}`),
425
+ r.blockers
426
+ ? `${r.blockers} blocker${r.blockers === 1 ? "" : "s"}${r.warnings ? ` and ${r.warnings} warning${r.warnings === 1 ? "" : "s"}` : ""}. A blocker can keep the site out of search: fix it now.`
427
+ : r.warnings
428
+ ? `No blockers, ${r.warnings} warning${r.warnings === 1 ? "" : "s"}. Fix ${r.warnings === 1 ? "it" : "them"} soon; a full audit gives the detail.`
429
+ : "Everything checked is fine.",
430
+ ...(r.searchConsole ? hourlyOf(r.searchConsole) : []),
431
+ ].join("\n");
432
+
433
+ const USAGE = `Usage: node deploy-check.mjs --site https://www.example.com [--json] [--search-console [--since 2026-11-21T14:30Z]]
434
+ The site's address must start with http:// or https://.
435
+ --search-console also compares Google Search clicks since the deploy with the same hours a week before, from your own
436
+ Search Console (sign in first with node google.mjs connect). --since is when the deploy went out, with its time zone,
437
+ at most 2 days ago; without it, the last 24 hours. It only warns: it never fails the check.`;
438
+
439
+ if (isMain(import.meta.url)) {
440
+ await runMain(async () => {
441
+ const a = parseArgs(process.argv.slice(2), {
442
+ flags: ["site", "since"],
443
+ booleans: ["json", "search-console"],
444
+ positionals: 0,
445
+ usage: USAGE,
446
+ });
447
+ const site = typeof a.site === "string" ? a.site : null,
448
+ since = a.since === undefined ? null : typeof a.since === "string" ? a.since : "",
449
+ gsc = a["search-console"] === true;
450
+ let ok = false;
451
+ try {
452
+ ok = !!site && /^https?:$/.test(new URL(site).protocol);
453
+ } catch {}
454
+ if (since != null && !(gsc && SINCE.test(since) && !isNaN(Date.parse(since)))) ok = false;
455
+ if (!ok) throw new Fail(USAGE);
456
+ warnProxy();
457
+ const [r, hourly] = await Promise.all([deployCheck(site), gsc ? searchHourly({ site, since }) : null]);
458
+ if (hourly) r.searchConsole = hourly;
459
+ console.log(a.json ? JSON.stringify(r, null, 2) : textOf(r));
460
+ return r.blockers ? 1 : 0; // blockers only: the Search Console part never changes it
461
+ });
462
+ }
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env node
2
+ // @ts-check
3
+ // Writes a disavow file from hand-picked domains and pages. It never chooses entries, and never uploads: Search Console
4
+ // has no API for it.
5
+ import { readFileSync, writeFileSync, mkdirSync } from "node:fs";
6
+ import { dirname, resolve } from "node:path";
7
+ import { isMain } from "./lib/is-main.mjs";
8
+ import { parseArgs } from "./lib/args.mjs";
9
+ import { Fail, runMain } from "./lib/cli.mjs";
10
+
11
+ const USAGE =
12
+ 'usage: node disavow.mjs --site https://www.example.com (--domains "a.com,b.com" and/or --urls links.txt) [--existing <the disavow file already in Search Console>] [--reason "…"] [--out seo-audit/disavow.txt]';
13
+ const fail = msg => {
14
+ throw new Fail("disavow: " + msg);
15
+ };
16
+ // Google's limits: a UTF-8 .txt file of 100,000 lines (blank and comment lines included) and 2 MB, read strictly as
17
+ // 2,000,000 bytes; URLs up to 2,048 characters. https://support.google.com/webmasters/answer/2648487
18
+ const MAX_LINES = 100000,
19
+ MAX_BYTES = 2000000,
20
+ MAX_URL = 2048,
21
+ TOOL = "https://search.google.com/search-console/disavow-links";
22
+ const bare = h => h.toLowerCase().replace(/^www\./, "");
23
+ const LABEL = "(?!-)[a-z0-9-]{1,63}(?<!-)",
24
+ HOST = new RegExp(`^${LABEL}(\\.${LABEL})*\\.(?!\\d+$)${LABEL}$`);
25
+ // A bare host name, lower-cased and in its xn-- form; null for anything with a scheme, path, port or space.
26
+ const hostOf = s => {
27
+ try {
28
+ return /[/\\:@?#\s]/.test(s) ? null : (h => (HOST.test(h) ? h : null))(new URL("http://" + s).hostname);
29
+ } catch {
30
+ return null;
31
+ }
32
+ };
33
+ // http:// or https:// then a host. Node parses "http:spam.com" and "https:/spam.com", but the file keeps lines as
34
+ // written, so those are refused.
35
+ const isUrl = s => {
36
+ try {
37
+ return /^https?:\/\/[^/\\\s]/i.test(s) && !/\s/.test(s) && !!new URL(s).hostname;
38
+ } catch {
39
+ return false;
40
+ }
41
+ };
42
+ // Duplicates: domain lines in any case, URLs as written. Subdomains are never merged, as Google doesn't say whether
43
+ // domain:example.com covers blog.example.com.
44
+ const keyOf = line => (/^domain:/i.test(line) ? line.toLowerCase() : line);
45
+ const lines = f => {
46
+ let t;
47
+ try {
48
+ t = readFileSync(f, "utf8")
49
+ .replace(/^/, "")
50
+ .replace(/\r?\n$/, "");
51
+ } catch (e) {
52
+ fail(`couldn't read ${f} (${e.code === "ENOENT" ? "it isn't there" : e.code}).`);
53
+ }
54
+ return t ? t.split(/\r?\n/) : [];
55
+ };
56
+
57
+ function main(argv) {
58
+ const args = parseArgs(argv, {
59
+ flags: ["site", "domains", "urls", "existing", "reason", "out"],
60
+ positionals: 0,
61
+ usage: USAGE,
62
+ });
63
+ const str = k => (typeof args[k] === "string" ? args[k] : null);
64
+ if (!str("site") || !("domains" in args || "urls" in args)) throw new Fail(USAGE);
65
+ let site;
66
+ try {
67
+ site = new URL(args.site);
68
+ } catch {}
69
+ if (!site || !/^https?:$/.test(site.protocol))
70
+ fail(`--site must be the site's address, like https://www.example.com (got ${args.site})`);
71
+ const own = bare(site.hostname),
72
+ mine = h => {
73
+ const b = bare(h);
74
+ return b === own || b.endsWith("." + own) || own.endsWith("." + b);
75
+ };
76
+ const notMine = (h, what) => {
77
+ if (mine(h)) fail(`${what} is your own site (${site.host}). Never disavow links from your own site.`);
78
+ };
79
+ const out = resolve(str("out") || "seo-audit/disavow.txt");
80
+ if (!/\.txt$/i.test(out)) fail(`--out must end in .txt: Google's disavow tool takes only .txt files (got ${out}).`);
81
+
82
+ const add = [];
83
+ for (const d of (str("domains") || "").split(/[,\s]+/).filter(Boolean)) {
84
+ const h = hostOf(d.replace(/^domain:/i, ""));
85
+ if (!h)
86
+ fail(
87
+ `"${d}" isn't a domain name like spam.example. Give names without http:// or a path; put single pages in a file for --urls.`,
88
+ );
89
+ notMine(h, d);
90
+ add.push(`domain:${h}`);
91
+ }
92
+ if (str("urls"))
93
+ lines(args.urls).forEach((raw, i) => {
94
+ const l = raw.trim();
95
+ if (!l || l.startsWith("#")) return;
96
+ if (!isUrl(l))
97
+ fail(
98
+ `${args.urls} line ${i + 1} isn't a web address: "${l.slice(0, 100)}". Put one full URL per line, like https://spam.example/page; whole sites go in --domains.`,
99
+ );
100
+ if (l.length > MAX_URL)
101
+ fail(
102
+ `${args.urls} line ${i + 1} is ${l.length.toLocaleString("en-US")} characters long; Google takes URLs of up to 2,048.`,
103
+ );
104
+ notMine(new URL(l).hostname, l);
105
+ add.push(l);
106
+ });
107
+ if (!add.length)
108
+ fail("no domains or URLs to disavow were given. Pick them first; the file is never filled in for you.");
109
+
110
+ // An upload replaces the property's whole list, so every existing line is carried over.
111
+ const old = str("existing") ? lines(args.existing) : [];
112
+ old.forEach((raw, i) => {
113
+ const l = raw.trim();
114
+ if (!l || l.startsWith("#")) return;
115
+ const h = isUrl(l) ? new URL(l).hostname : /^domain:/i.test(l) ? hostOf(l.slice(7)) : null;
116
+ if (!h)
117
+ fail(
118
+ `${args.existing} line ${i + 1} isn't a disavow line: "${l.slice(0, 100)}". Pass the disavow file for this property, as it is in Search Console.`,
119
+ );
120
+ // Disavowing the site itself is almost certainly a mistake that's hurting it, so it stops the run.
121
+ if (mine(h))
122
+ fail(
123
+ `${args.existing} line ${i + 1} disavows your own site (${site.host}): "${l.slice(0, 100)}". That's almost certainly a mistake. Remove that line from the file, run this again, and upload the new file.`,
124
+ );
125
+ });
126
+ const seen = new Set(old.map(l => keyOf(l.trim()))),
127
+ fresh = add.filter(l => !seen.has(keyOf(l)) && seen.add(keyOf(l)));
128
+ const known = add.length - fresh.length;
129
+ if (!fresh.length)
130
+ fail(`nothing new: every domain and URL given is already in ${str("existing") ? args.existing : "the list"}.`);
131
+
132
+ const reason = (str("reason") || "").replace(/\s+/g, " ").trim(),
133
+ date = new Date().toLocaleDateString("en-CA"); // local YYYY-MM-DD
134
+ const all = [
135
+ ...old,
136
+ ...(old.length ? [""] : []),
137
+ `# Added ${date}${reason ? `: ${reason}` : " with disavow.mjs"}`,
138
+ ...fresh,
139
+ ];
140
+ const text = all.join("\n") + "\n",
141
+ bytes = Buffer.byteLength(text);
142
+ if (all.length > MAX_LINES)
143
+ fail(
144
+ `the file would have ${all.length.toLocaleString("en-US")} lines; Google takes at most 100,000 lines, blank and comment lines included. Use domain: lines in place of many pages from one site.`,
145
+ );
146
+ if (bytes > MAX_BYTES)
147
+ fail(
148
+ `the file would be ${(bytes / 1e6).toFixed(1)} MB; Google takes at most 2 MB. Use domain: lines in place of many pages from one site.`,
149
+ );
150
+ mkdirSync(dirname(out), { recursive: true });
151
+ writeFileSync(out, text);
152
+
153
+ const n = (k, w) => `${k} ${w}${k === 1 ? "" : "s"}`,
154
+ doms = fresh.filter(l => l.startsWith("domain:")).length;
155
+ console.log(
156
+ [
157
+ `disavow: wrote ${out}: ${[doms && n(doms, "domain"), fresh.length > doms && n(fresh.length - doms, "URL")].filter(Boolean).join(" and ")} added${old.length ? `, ${n(old.length, "line")} kept from ${args.existing}` : ""}${known ? `, ${known} already in the list` : ""}.`,
158
+ "",
159
+ "Before you upload:",
160
+ "- Most sites never need this. Google can usually tell which links to trust on its own. Use it only for a manual action for unnatural links, or for links you know were paid for or made to manipulate rankings, after asking the sites to remove them.",
161
+ `- Uploading replaces the list already in Search Console. ${old.length ? "This file keeps every line of the old list, so nothing is lost." : "If you uploaded a disavow file for this property before, run this again with --existing and that file, or its lines will be lost."}`,
162
+ "- A wrong disavow can hurt the site in Google Search. Read every line first.",
163
+ "",
164
+ "To upload it (only a property owner can):",
165
+ `1. Open ${TOOL}`,
166
+ `2. Pick the URL-prefix property for ${site.origin}/. The tool doesn't work with Domain properties. If you have both http and https properties, upload the file to each.`,
167
+ "3. Upload the file. If Google lists errors, the old list stays; fix the file and upload it again.",
168
+ "It can take a few weeks for Google to use the list. If there's a manual action, then ask for a review in Search Console's Manual actions report.",
169
+ // https://blogs.bing.com/webmaster/september-2023/Bing-Webmaster-Tools-to-Remove-Disavow-Links-Feature-in-October-2023
170
+ "Bing has no disavow tool: it removed it in October 2023.",
171
+ ].join("\n"),
172
+ );
173
+ return 0;
174
+ }
175
+
176
+ if (isMain(import.meta.url)) await runMain(() => main(process.argv.slice(2)));