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,298 @@
1
+ #!/usr/bin/env node
2
+ // @ts-check
3
+ // Reads an unzipped Search Console Performance export, and the AI report exports, into traffic per page and findings.
4
+ // google.mjs builds the same output from the API and reuses addTraffic() and gscFindings().
5
+ import { readFileSync, writeFileSync, mkdirSync, existsSync, readdirSync, statSync } from "node:fs";
6
+ import { dirname, join, resolve } from "node:path";
7
+ import { isMain } from "./lib/is-main.mjs";
8
+ import { parseCsv } from "./lib/csv.mjs";
9
+ import { parseArgs } from "./lib/args.mjs";
10
+ import { Fail, runMain } from "./lib/cli.mjs";
11
+ import { foundOn } from "./lib/findings.mjs";
12
+
13
+ // http/https and www variants of a page add up; position is weighted by impressions.
14
+ export function addTraffic(traffic, path, m) {
15
+ const t = traffic[path];
16
+ if (!t) {
17
+ traffic[path] = m;
18
+ return;
19
+ }
20
+ const clicks = t.clicks + m.clicks,
21
+ impressions = t.impressions + m.impressions;
22
+ traffic[path] = {
23
+ clicks,
24
+ impressions,
25
+ ctr: impressions ? Math.round((clicks / impressions) * 10000) / 10000 : 0,
26
+ position: impressions
27
+ ? Math.round(((t.position * t.impressions + m.position * m.impressions) / impressions) * 10) / 10
28
+ : m.position,
29
+ };
30
+ }
31
+
32
+ // traffic and pageQueries are keyed by path; urls gives each path's full URL for the evidence.
33
+ export function gscFindings(traffic, pageQueries, urls) {
34
+ const findings = [];
35
+ const fmtN = n => n.toLocaleString("en-US"),
36
+ pct = x => `${Math.round(x * 1000) / 10}%`;
37
+ const finding = (check, rule, severity, title, why, fix, evidence) => {
38
+ if (!evidence.length) return;
39
+ const ex = evidence[0];
40
+ findings.push({
41
+ check,
42
+ rule,
43
+ severity,
44
+ category: "Search intent",
45
+ title,
46
+ what: foundOn(evidence.length, ex),
47
+ why,
48
+ fix,
49
+ count: evidence.length,
50
+ evidence,
51
+ source: "search-console",
52
+ status: "open",
53
+ });
54
+ };
55
+ // Low CTR: under half the median CTR of pages at a similar position (needs 3+ such pages to compare against).
56
+ const bucket = p => (p < 4 ? "1-3" : p < 8 ? "4-7" : p <= 10 ? "8-10" : p <= 20 ? "11-20" : "21+");
57
+ const groups = {};
58
+ for (const [path, t] of Object.entries(traffic))
59
+ if (t.impressions >= 100) (groups[bucket(t.position)] ||= []).push([path, t]);
60
+ const median = xs => {
61
+ const s = [...xs].sort((a, b) => a - b),
62
+ m = s.length >> 1;
63
+ return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2;
64
+ };
65
+ const lowCtr = [];
66
+ for (const list of Object.values(groups)) {
67
+ if (list.length < 3) continue;
68
+ const med = median(list.map(([, t]) => t.ctr));
69
+ for (const [path, t] of list)
70
+ if (t.ctr < med / 2)
71
+ lowCtr.push({
72
+ url: urls[path],
73
+ detail: `CTR ${pct(t.ctr)} at position ${t.position}, similar pages ${pct(med)}, ${fmtN(t.impressions)} impressions`,
74
+ });
75
+ }
76
+ finding(
77
+ "low-ctr",
78
+ "INTENT-03",
79
+ "low",
80
+ `${lowCtr.length} page(s) get far fewer clicks than similar pages at the same position`,
81
+ "Search Console shows these pages appearing often but rarely clicked: half the click rate or less of the site's other pages at a similar position. The title and description usually decide that click.",
82
+ "Rewrite the title and meta description to match what people searching want, using the page's top queries. Keep them accurate.",
83
+ lowCtr,
84
+ );
85
+ const nearTop = Object.entries(traffic)
86
+ .filter(([, t]) => t.position >= 8 && t.position <= 20 && t.impressions >= 50)
87
+ .sort((a, b) => b[1].impressions - a[1].impressions)
88
+ .map(([path, t]) => ({ url: urls[path], detail: `position ${t.position}, ${fmtN(t.impressions)} impressions` }));
89
+ finding(
90
+ "almost-page-one",
91
+ "INTENT-04",
92
+ "low",
93
+ `${nearTop.length} page(s) rank just below the top results (position 8–20)`,
94
+ "These pages already get impressions and sit at the bottom of page one or on page two, where a small improvement brings them into view.",
95
+ "Work on these first: match the main query's intent, strengthen the content and add internal links from related pages.",
96
+ nearTop,
97
+ );
98
+ // Competing pages (per-page exports only): two or more pages each with a real share of one query's impressions.
99
+ // The home page is left out (it shows for brand queries by design), and so is the long tail (under 10 impressions).
100
+ const byQuery = {};
101
+ for (const [path, list] of Object.entries(pageQueries))
102
+ for (const q of list)
103
+ if (q.impressions >= 10 && path !== "/") (byQuery[q.query.toLowerCase()] ||= []).push([path, q]);
104
+ const competing = Object.values(byQuery)
105
+ .map(l => l.sort((a, b) => b[1].impressions - a[1].impressions))
106
+ .filter(l => l.length > 1 && l[1][1].impressions >= 0.2 * l.reduce((n, [, q]) => n + q.impressions, 0))
107
+ .map(l => ({
108
+ url: urls[l[0][0]],
109
+ detail: `“${l[0][1].query}”: ${l.map(([p, q]) => `${p} (${fmtN(q.impressions)} impressions, position ${q.position})`).join(" · ")}`,
110
+ }));
111
+ finding(
112
+ "query-competition",
113
+ "INTENT-02",
114
+ "medium",
115
+ `${competing.length} quer${competing.length === 1 ? "y has" : "ies have"} two or more of the site's pages competing`,
116
+ "Search Console shows several of the site's pages getting impressions for the same query, so they split clicks and links and none ranks as well as one page would.",
117
+ "Pick one page per query and make it the clear answer. Link the others to it, and merge or refocus pages that cover the same thing.",
118
+ competing,
119
+ );
120
+ findings.forEach((f, i) => {
121
+ f.id = "G-" + String(i + 1).padStart(3, "0");
122
+ });
123
+ return findings;
124
+ }
125
+
126
+ // Search Console's AI export has the page column, then Impressions, with "~" and "-" downloaded as zeros. Bing doesn't
127
+ // document its columns, so the number is the column named like `metric`, else the first number column after the pages.
128
+ // https://support.google.com/webmasters/answer/16984139
129
+ const toCount = s => {
130
+ const d = String(s ?? "").replace(/\D/g, "");
131
+ return d ? Number(d) : NaN;
132
+ };
133
+ function aiReport(rows, metric, host) {
134
+ const cols = Object.keys(rows[0] || {}),
135
+ isUrl = v => /^https?:\/\//i.test(v || "");
136
+ const page = cols.find(c => rows.some(r => isUrl(r[c])));
137
+ const value =
138
+ cols.find(c => c !== page && new RegExp(metric, "i").test(c)) ||
139
+ cols.slice(cols.indexOf(page) + 1).find(c => rows.every(r => !r[c] || !isNaN(toCount(r[c]))));
140
+ if (!page || !value) return null;
141
+ const pages = {};
142
+ for (const r of rows) {
143
+ let u;
144
+ try {
145
+ u = new URL(r[page]);
146
+ } catch {
147
+ continue;
148
+ }
149
+ const n = toCount(r[value]);
150
+ if (n > 0 && (!host || u.hostname.replace(/^www\./, "") === host))
151
+ pages[u.pathname + u.search] = { [metric]: (pages[u.pathname + u.search]?.[metric] || 0) + n };
152
+ }
153
+ const sorted = Object.entries(pages).sort((a, b) => b[1][metric] - a[1][metric]);
154
+ return { [metric]: sorted.reduce((s, [, v]) => s + v[metric], 0), pages: Object.fromEntries(sorted) };
155
+ }
156
+
157
+ // --site is the other scripts' name for --site-origin.
158
+ const USAGE =
159
+ "usage: node gsc-import.mjs --pages Pages.csv [--queries Queries.csv] [--page-queries dir/] [--site-origin https://x] [--out seo-audit/gsc.json]\n node gsc-import.mjs --ai-google Pages.csv [--ai-bing ai-pages.csv] [--site-origin https://x] [--out seo-audit/ai-reports.json]";
160
+ function main(argv) {
161
+ const args = parseArgs(argv, {
162
+ flags: ["pages", "queries", "page-queries", "site-origin", "out", "ai-google", "ai-bing"],
163
+ aliases: { site: "site-origin" },
164
+ positionals: 0,
165
+ usage: USAGE,
166
+ });
167
+ const AI = [
168
+ ["ai-google", "google", "impressions", "Search Console Generative AI performance", "then Impressions"],
169
+ ["ai-bing", "bing", "citations", "Bing Webmaster Tools AI Performance", "and a Citations column"],
170
+ ].filter(([flag]) => typeof args[flag] === "string");
171
+ if (typeof args.pages !== "string" && !AI.length) throw new Fail(USAGE);
172
+ const OUT = resolve(
173
+ typeof args.out === "string"
174
+ ? args.out
175
+ : typeof args.pages === "string"
176
+ ? "seo-audit/gsc.json"
177
+ : "seo-audit/ai-reports.json",
178
+ );
179
+ let host = null;
180
+ if (typeof args["site-origin"] === "string")
181
+ try {
182
+ host = new URL(args["site-origin"]).hostname.replace(/^www\./, "");
183
+ } catch {
184
+ throw new Fail(
185
+ `gsc-import: --site-origin must be the site's address, like https://www.example.com (got ${args["site-origin"]}).`,
186
+ );
187
+ }
188
+ const aiReports = AI.length
189
+ ? Object.fromEntries(
190
+ AI.map(([flag, id, metric, what, cols]) => {
191
+ const r = aiReport(parseCsv(readFileSync(args[flag], "utf8")), metric, host);
192
+ if (!r)
193
+ throw new Fail(
194
+ `gsc-import: ${args[flag]} isn't a ${what} export of pages. Expected a column of page addresses ${cols}, as the report's download writes them.`,
195
+ );
196
+ return [id, r];
197
+ }),
198
+ )
199
+ : null;
200
+ if (typeof args.pages !== "string") {
201
+ mkdirSync(dirname(OUT), { recursive: true });
202
+ writeFileSync(OUT, JSON.stringify({ source: "ai-reports", aiReports }, null, 2));
203
+ console.log(
204
+ `gsc-import: AI reports for ${Object.values(aiReports)
205
+ .map(r => Object.keys(r.pages).length)
206
+ .join(" and ")} pages · wrote ${OUT}`,
207
+ );
208
+ return 0;
209
+ }
210
+
211
+ // Search Console writes the dimension, Clicks, Impressions, CTR and Position in that order in every UI language,
212
+ // so columns are read by position. Counts drop every separator ("10.000", "1 234"); CTR and position take
213
+ // "," or "." as the decimal mark ("5,1 %" -> 5.1).
214
+ const count = s => {
215
+ const d = String(s ?? "").replace(/\D/g, "");
216
+ return d ? Number(d) : NaN;
217
+ };
218
+ const decimal = s => {
219
+ s = String(s ?? "").replace(/[\s %]/g, "");
220
+ const i = Math.max(s.lastIndexOf("."), s.lastIndexOf(","));
221
+ return Number(i < 0 ? s : s.slice(0, i).replace(/[.,]/g, "") + "." + s.slice(i + 1));
222
+ };
223
+ const metrics = v => ({
224
+ clicks: count(v[1]),
225
+ impressions: count(v[2]),
226
+ ctr: Math.round(decimal(v[3]) * 100) / 10000,
227
+ position: decimal(v[4]),
228
+ });
229
+ const rowsOf = file => parseCsv(readFileSync(file, "utf8")).map(r => Object.values(r));
230
+ const notExport = (file, what) => {
231
+ throw new Fail(
232
+ `gsc-import: ${file} isn't a Search Console ${what} export. Expected ${what === "Pages" ? "a URL" : "a query"}, then Clicks, Impressions, CTR and Position, comma-separated, as Search Console's "Export → Download CSV" writes them.`,
233
+ );
234
+ };
235
+ const pathOf = u => {
236
+ try {
237
+ const x = new URL(u);
238
+ return host && x.hostname.replace(/^www\./, "") !== host ? null : x.pathname + x.search;
239
+ } catch {
240
+ return null;
241
+ }
242
+ };
243
+ // Filters.csv: rows of (filter, value) in the UI's language; the page filter's value is a URL.
244
+ const filters = file => (existsSync(file) ? rowsOf(file) : []);
245
+ const periodOf = rows => rows.find(v => /dat|fecha|p[ée]riod/i.test(v[0] || ""))?.[1] ?? null;
246
+
247
+ const traffic = {},
248
+ urls = {};
249
+ const pageRows = rowsOf(args.pages);
250
+ if (
251
+ !pageRows.length ||
252
+ pageRows.some(v => v.length < 5 || !/^https?:\/\//i.test(v[0]) || isNaN(count(v[1])) || isNaN(count(v[2])))
253
+ )
254
+ notExport(args.pages, "Pages");
255
+ for (const v of pageRows) {
256
+ const path = pathOf(v[0]);
257
+ if (!path) continue;
258
+ urls[path] ||= v[0];
259
+ addTraffic(traffic, path, metrics(v));
260
+ }
261
+ const queryRows = typeof args.queries === "string" ? rowsOf(args.queries) : [];
262
+ if (queryRows.some(v => v.length < 5 || isNaN(count(v[2])))) notExport(args.queries, "Queries");
263
+ const queries = queryRows.map(v => ({ query: v[0], ...metrics(v) }));
264
+ const period = periodOf(filters(join(dirname(resolve(args.pages)), "Filters.csv")));
265
+
266
+ // Per-page exports: each folder's Filters.csv names the page its Queries.csv belongs to.
267
+ const pageQueries = {};
268
+ if (typeof args["page-queries"] === "string") {
269
+ for (const d of readdirSync(args["page-queries"])) {
270
+ const dir = join(args["page-queries"], d);
271
+ if (!statSync(dir).isDirectory() || !existsSync(join(dir, "Queries.csv"))) continue;
272
+ const page = filters(join(dir, "Filters.csv")).find(v => /^https?:\/\//i.test(v[1] || ""))?.[1] || "",
273
+ path = pathOf(page);
274
+ if (path) urls[path] ||= page;
275
+ if (path)
276
+ pageQueries[path] = rowsOf(join(dir, "Queries.csv"))
277
+ .filter(v => v.length >= 5)
278
+ .map(v => ({ query: v[0], ...metrics(v) }));
279
+ }
280
+ }
281
+
282
+ const findings = gscFindings(traffic, pageQueries, urls);
283
+ mkdirSync(dirname(OUT), { recursive: true });
284
+ writeFileSync(
285
+ OUT,
286
+ JSON.stringify(
287
+ { source: "search-console", period, traffic, queries, pageQueries, findings, ...(aiReports && { aiReports }) },
288
+ null,
289
+ 2,
290
+ ),
291
+ );
292
+ console.log(
293
+ `gsc-import: ${Object.keys(traffic).length} pages, ${queries.length} queries, ${Object.keys(pageQueries).length} per-page exports, ${findings.length} findings · wrote ${OUT}`,
294
+ );
295
+ return 0;
296
+ }
297
+
298
+ if (isMain(import.meta.url)) await runMain(() => main(process.argv.slice(2)));
@@ -0,0 +1,149 @@
1
+ // @ts-check
2
+ // https://code.claude.com/docs/en/hooks
3
+ import { mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { dirname, isAbsolute, join, relative, resolve } from "node:path";
6
+ import { seoSensitive } from "../rules.mjs";
7
+
8
+ const QUIET = Object.freeze({ stdout: "", stderr: "", exitCode: 0 });
9
+ const out = o => ({ stdout: JSON.stringify(o), stderr: "", exitCode: 0 });
10
+ const str = v => (typeof v === "string" ? v : "");
11
+
12
+ /** The hook payload as guard actions. A Write's before is the file on disk; an Edit's after is that file, edited. */
13
+ export function toActions(input, event, cwd) {
14
+ if (event === "UserPromptSubmit") return [{ kind: "prompt", text: str(input?.prompt) }];
15
+ if (event !== "PreToolUse") return [];
16
+ const tool = input?.tool_name,
17
+ ti = input?.tool_input || {};
18
+ if (tool === "Bash" || tool === "PowerShell") return [{ kind: "bash", command: str(ti.command) }];
19
+ // MultiEdit is legacy but the permissions page still names it, so its edits list is read when present.
20
+ if (!["Write", "Edit", "MultiEdit"].includes(tool) || !str(ti.file_path)) return [];
21
+ const file = resolve(cwd, ti.file_path);
22
+ let disk = null;
23
+ try {
24
+ disk = readFileSync(file, "utf8").replace(/\r\n/g, "\n");
25
+ } catch {}
26
+ if (tool === "Write") return [{ kind: "edit", file, before: disk ?? "", after: str(ti.content) }];
27
+ const edits = (tool === "Edit" ? [ti] : Array.isArray(ti.edits) ? ti.edits : []).map(e => ({
28
+ o: str(e?.old_string).replace(/\r\n/g, "\n"),
29
+ n: str(e?.new_string).replace(/\r\n/g, "\n"),
30
+ all: e?.replace_all === true,
31
+ }));
32
+ let after = disk;
33
+ if (disk != null)
34
+ for (const { o, n, all } of edits) if (o) after = all ? after.split(o).join(n) : after.replace(o, () => n);
35
+ // An unreadable file, or an old_string that isn't in it: judge the edited snippets on their own.
36
+ if (disk == null || (after === disk && edits.some(e => e.o !== e.n)))
37
+ return edits.map(e => ({ kind: "edit", file, before: e.o, after: e.n }));
38
+ return [{ kind: "edit", file, before: disk, after }];
39
+ }
40
+
41
+ /** @param {{ decision: string, reason?: string, rule?: string }} r */
42
+ export function respond(r, event) {
43
+ // No output leaves the normal permission flow.
44
+ if (!r || r.decision === "allow") return QUIET;
45
+ // The block reason is shown to the user; suppressOriginalPrompt keeps the prompt, and so a pasted key, out of it.
46
+ if (event === "UserPromptSubmit")
47
+ return out({
48
+ decision: "block",
49
+ reason: r.reason,
50
+ hookSpecificOutput: { hookEventName: "UserPromptSubmit", suppressOriginalPrompt: true },
51
+ });
52
+ if (event !== "PreToolUse") return QUIET;
53
+ const why =
54
+ r.decision === "deny" && r.rule !== "key"
55
+ ? `${r.reason} The guard is in block mode, so it stopped this. Ask the owner in chat: they can run it themselves, or set the guard to ask.`
56
+ : r.reason;
57
+ // "ask" shows the reason to the user in the permission prompt; "deny" shows it to Claude.
58
+ return out({
59
+ hookSpecificOutput: {
60
+ hookEventName: "PreToolUse",
61
+ permissionDecision: r.decision,
62
+ permissionDecisionReason: `SEO Supervisor: ${why}`,
63
+ },
64
+ });
65
+ }
66
+
67
+ // ---------- the review reminder (Stop) ----------
68
+ // One small notes file per session, in the plugin's data folder.
69
+ const stateFile = (input, env) =>
70
+ join(
71
+ env.CLAUDE_PLUGIN_DATA || join(tmpdir(), "seo-supervisor"),
72
+ "guard-sessions",
73
+ `${String(input.session_id)
74
+ .replace(/[^\w-]/g, "_")
75
+ .slice(0, 100)}.json`,
76
+ );
77
+ const load = f => {
78
+ try {
79
+ const s = JSON.parse(readFileSync(f, "utf8"));
80
+ return {
81
+ changed: [].concat(s.changed || []),
82
+ noted: [].concat(s.noted || []),
83
+ pending: s.pending && typeof s.pending === "object" && !Array.isArray(s.pending) ? s.pending : {},
84
+ };
85
+ } catch {
86
+ return { changed: [], noted: [], pending: {} };
87
+ }
88
+ };
89
+ // A note that can't be saved is skipped: the reminder must never stop the guard's own checks.
90
+ const save = (f, s) => {
91
+ try {
92
+ mkdirSync(dirname(f), { recursive: true });
93
+ writeFileSync(f, JSON.stringify(s));
94
+ } catch {}
95
+ };
96
+ const shown = (f, cwd) => {
97
+ const p = relative(cwd, f);
98
+ return (p.startsWith("..") || isAbsolute(p) ? f : p).replace(/\\/g, "/");
99
+ };
100
+ const list = a => (a.length > 3 ? `${a.slice(0, 3).join(", ")} and ${a.length - 3} more` : a.join(", "));
101
+
102
+ /** Notes the SEO files an edit touches, clears them when a review runs, and on Stop reminds the user once. Returns the
103
+ * hook's answer for the events only this handles (PostToolUse, Stop), else null. */
104
+ export function session(input, event, cwd, actions, env = process.env) {
105
+ if (!input?.session_id) return event === "Stop" || event === "PostToolUse" ? QUIET : null;
106
+ const f = stateFile(input, env),
107
+ reviewed = () => save(f, { changed: [], noted: [], pending: {} });
108
+ // An edit's files stay pending until its PostToolUse, which never fires after a denial, so an edit the user, the
109
+ // guard or a permission rule refused never counts. The tool_use_id pairs the two; without one, the file does.
110
+ const ti = input.tool_input || {},
111
+ key = str(input.tool_use_id) || (str(ti.file_path) && shown(resolve(cwd, ti.file_path), cwd));
112
+ if (event === "PreToolUse") {
113
+ const files = actions.filter(a => a.kind === "edit" && seoSensitive(a, cwd)).map(a => shown(a.file, cwd));
114
+ if (files.length && key) {
115
+ const s = load(f);
116
+ s.pending[key] = files;
117
+ save(f, s);
118
+ }
119
+ return null;
120
+ }
121
+ // /seo-review typed by the user, or the review skill or seo-reviewer subagent started by Claude.
122
+ if (event === "UserPromptSubmit") {
123
+ if (/^\s*\/(seo-supervisor:)?seo-review\b/.test(str(input.prompt))) reviewed();
124
+ return null;
125
+ }
126
+ if (event === "PostToolUse") {
127
+ if (/seo-review/.test(`${str(ti.subagent_type)} ${str(ti.skill)}`)) reviewed();
128
+ // A failed call's tool_response is the error text, a string, so only an object counts as done.
129
+ else if (key && input.tool_response && typeof input.tool_response === "object") {
130
+ const s = load(f),
131
+ files = [].concat(s.pending[key] || []);
132
+ if (files.length) {
133
+ delete s.pending[key];
134
+ s.changed = [...new Set([...s.changed, ...files])];
135
+ save(f, s);
136
+ }
137
+ }
138
+ return QUIET;
139
+ }
140
+ if (event !== "Stop" || input.stop_hook_active) return event === "Stop" ? QUIET : null;
141
+ const s = load(f),
142
+ fresh = s.changed.filter(x => !s.noted.includes(x));
143
+ if (!fresh.length) return QUIET;
144
+ save(f, { changed: s.changed, noted: s.changed });
145
+ // systemMessage is shown to the user and doesn't keep Claude going.
146
+ return out({
147
+ systemMessage: `SEO Supervisor: this session changed what search engines read (${list(fresh)}), and no SEO review has run since. Run /seo-review to check those changes before they go live.`,
148
+ });
149
+ }
@@ -0,0 +1,28 @@
1
+ // @ts-check
2
+ // Cline's hooks are plugin functions: the installed .cline/plugins/seo-supervisor-guard.js runs this guard with
3
+ // { tool, input, cwd } on stdin and returns what it prints. Plugins run only in Cline's SDK, CLI and Kanban, so the
4
+ // guard doesn't reach the VS Code and JetBrains extensions.
5
+ // https://docs.cline.bot/sdk/plugins
6
+ // Known gap: no Cline hook sees the prompt before the model does, so a key pasted in chat isn't caught.
7
+ import { bashActions, editActions, json, obj, patchActions, say, SILENT } from "./edits.mjs";
8
+
9
+ // The built-in tools' argument names aren't documented, so edits.mjs tries the usual spellings.
10
+ // https://docs.cline.bot/tools-reference/all-cline-tools
11
+ export function toActions(input, event, cwd) {
12
+ const here = typeof input?.cwd === "string" ? input.cwd : cwd,
13
+ args = obj(input?.input);
14
+ if (input?.tool === "run_commands") return bashActions(args);
15
+ if (input?.tool === "apply_patch") {
16
+ const p = Object.values(args).find(v => typeof v === "string" && v.includes("*** Begin Patch"));
17
+ return p ? patchActions(p, here) : [];
18
+ }
19
+ if (input?.tool === "editor") return editActions(args, here);
20
+ return [];
21
+ }
22
+
23
+ // skip blocks the call and gives the model the reason; autoApprove: false makes Cline ask the user.
24
+ export function respond(result) {
25
+ if (!result || result.decision === "allow") return SILENT;
26
+ if (result.decision === "ask") return json({ policy: { autoApprove: false }, appendContext: say(result, true) });
27
+ return json({ skip: true, reason: say(result) });
28
+ }
@@ -0,0 +1,26 @@
1
+ // @ts-check
2
+ // https://learn.chatgpt.com/docs/hooks
3
+ import { bashActions, json, patchActions, say, SILENT } from "./edits.mjs";
4
+
5
+ export function toActions(input, event, cwd) {
6
+ if (event === "UserPromptSubmit")
7
+ return typeof input?.prompt === "string" ? [{ kind: "prompt", text: input.prompt }] : [];
8
+ const args = input?.tool_input ?? {};
9
+ if (input?.tool_name === "Bash") return bashActions(args);
10
+ if (input?.tool_name === "apply_patch" && typeof args.command === "string") return patchActions(args.command, cwd);
11
+ return [];
12
+ }
13
+
14
+ export function respond(result, event) {
15
+ if (!result || result.decision === "allow") return SILENT;
16
+ if (event === "UserPromptSubmit") return json({ decision: "block", reason: say(result) });
17
+ // Codex parses "ask" but doesn't support it yet: the hook is marked failed and the tool runs. So an ask is a deny
18
+ // with the reason, and the agent asks in chat.
19
+ return json({
20
+ hookSpecificOutput: {
21
+ hookEventName: "PreToolUse",
22
+ permissionDecision: "deny",
23
+ permissionDecisionReason: say(result),
24
+ },
25
+ });
26
+ }
@@ -0,0 +1,36 @@
1
+ // @ts-check
2
+ // GitHub Copilot CLI and cloud agent hooks.
3
+ // https://docs.github.com/en/copilot/reference/copilot-cli-reference/cli-hooks-reference
4
+ import { bashActions, editActions, json, obj, patchActions, say, SILENT } from "./edits.mjs";
5
+
6
+ export function toActions(input, event, cwd) {
7
+ const here = typeof input?.cwd === "string" ? input.cwd : cwd;
8
+ if (event === "userPromptTransformed")
9
+ return typeof input?.prompt === "string" ? [{ kind: "prompt", text: input.prompt }] : [];
10
+ // toolArgs may be a JSON string and is typed unknown, so a patch is whichever value holds "*** Begin Patch".
11
+ const args = obj(input?.toolArgs);
12
+ if (input?.toolName === "bash" || input?.toolName === "powershell") return bashActions(args);
13
+ if (input?.toolName === "apply_patch") {
14
+ const p = [...Object.values(args), input.toolArgs].find(
15
+ v => typeof v === "string" && v.includes("*** Begin Patch"),
16
+ );
17
+ return p ? patchActions(p, here) : [];
18
+ }
19
+ if (["edit", "create", "str_replace_editor"].includes(input?.toolName)) return editActions(args, here);
20
+ return [];
21
+ }
22
+
23
+ export function respond(result, event) {
24
+ if (!result || result.decision === "allow") return SILENT;
25
+ // userPromptSubmitted can't block, so userPromptTransformed swaps a prompt holding a key for the guard's note and the
26
+ // model never sees the key.
27
+ if (event === "userPromptTransformed")
28
+ return json({
29
+ modifiedTransformedPrompt: `${say(result)} The owner's message was held back, so you didn't see it. Tell the owner why, in those words.`,
30
+ });
31
+ // The CLI shows an ask; the cloud agent and autopilot treat it as deny.
32
+ return json({
33
+ permissionDecision: result.decision === "ask" ? "ask" : "deny",
34
+ permissionDecisionReason: say(result, result.decision === "ask"),
35
+ });
36
+ }
@@ -0,0 +1,33 @@
1
+ // @ts-check
2
+ // https://cursor.com/docs/hooks
3
+ import { resolve } from "node:path";
4
+ import { bashActions, editActions, json, obj, say } from "./edits.mjs";
5
+
6
+ export function toActions(input, event, cwd) {
7
+ const here = typeof input?.cwd === "string" ? input.cwd : cwd;
8
+ if (event === "beforeSubmitPrompt")
9
+ return typeof input?.prompt === "string" ? [{ kind: "prompt", text: input.prompt }] : [];
10
+ if (event === "beforeShellExecution") return bashActions(input ?? {});
11
+ const args = obj(input?.tool_input);
12
+ if (input?.tool_name === "Shell") return bashActions(args);
13
+ if (input?.tool_name === "Delete") {
14
+ const p = ["path", "file_path", "target_file"].map(k => args[k]).find(v => typeof v === "string");
15
+ return p ? [{ kind: "delete", file: resolve(here, p) }] : [];
16
+ }
17
+ if (input?.tool_name === "Write") return editActions(args, here);
18
+ return [];
19
+ }
20
+
21
+ export function respond(result, event) {
22
+ const decision = result?.decision || "allow";
23
+ if (event === "beforeSubmitPrompt")
24
+ return json(decision === "allow" ? { continue: true } : { continue: false, user_message: say(result) });
25
+ // Output that isn't valid JSON blocks a permission hook and there's no "no opinion" answer, so allow is stated
26
+ // outright, as Cursor's sample hooks do. Cursor merges hooks so deny beats ask beats allow, making allow neutral;
27
+ // whether it also skips Cursor's own approval prompt isn't documented.
28
+ if (decision === "allow") return json({ permission: "allow" });
29
+ // preToolUse accepts "ask" but doesn't enforce it, so an ask on an edit is a deny with the reason.
30
+ const ask = decision === "ask" && event === "beforeShellExecution",
31
+ text = say(result, ask);
32
+ return json({ permission: ask ? "ask" : "deny", user_message: text, agent_message: text });
33
+ }
@@ -0,0 +1,25 @@
1
+ // @ts-check
2
+ // Devin hooks, for Devin Local, Devin Desktop and the Devin CLI.
3
+ // https://docs.devin.ai/cli/extensibility/hooks/overview
4
+ import { bashActions, editActions, json, obj, patchActions, say, SILENT } from "./edits.mjs";
5
+
6
+ export function toActions(input, event, cwd) {
7
+ const here = typeof input?.cwd === "string" ? input.cwd : cwd;
8
+ if (event === "UserPromptSubmit")
9
+ return typeof input?.prompt === "string" ? [{ kind: "prompt", text: input.prompt }] : [];
10
+ const args = obj(input?.tool_input);
11
+ if (input?.tool_name === "exec") return bashActions(args);
12
+ if (input?.tool_name === "apply_patch") {
13
+ const p = Object.values(args).find(v => typeof v === "string" && v.includes("*** Begin Patch"));
14
+ return p ? patchActions(p, here) : [];
15
+ }
16
+ if (input?.tool_name === "edit" || input?.tool_name === "write") return editActions(args, here);
17
+ return [];
18
+ }
19
+
20
+ export function respond(result) {
21
+ if (!result || result.decision === "allow") return SILENT;
22
+ // Exit 2 would also block, but PowerShell's -Command turns a native exit 2 into 1, which Devin only logs, so the
23
+ // block is JSON with exit 0. There's no ask, so an ask blocks and the agent asks in chat.
24
+ return json({ decision: "block", reason: say(result) });
25
+ }