seo 0.13.2 → 0.13.3

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.
package/dist/mcp.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { createRequire as __seoCreateRequire } from 'node:module'; const require = __seoCreateRequire(import.meta.url);
2
- import { i as __toESM, n as version, r as __commonJSMin, t as load } from "./esm-Dmtr8qrP.js";
2
+ import { i as __toESM, n as version, r as __commonJSMin, t as load } from "./esm-hHlvm1W0.js";
3
3
  import { createHash, randomUUID, sign } from "node:crypto";
4
4
  import { ZodOptional, z } from "zod";
5
5
  import { arch, homedir, platform, tmpdir, totalmem } from "node:os";
@@ -13874,6 +13874,13 @@ async function failure(response, label, subject, options) {
13874
13874
  const detail = (await response.text().catch(() => "")).slice(0, 300);
13875
13875
  const status = response.status;
13876
13876
  const what = subject ? `${label} for ${subject}` : label;
13877
+ if (status === 400) {
13878
+ let reason = detail;
13879
+ try {
13880
+ reason = JSON.parse(detail).error?.message ?? detail;
13881
+ } catch {}
13882
+ return new GoogleApiError("INVALID_INPUT", `${label} rejected the request: ${reason}`.trim(), status);
13883
+ }
13877
13884
  if (status === 401) return new GoogleApiError("AUTH_EXPIRED", `Google rejected the sign-in. ${options.signIn}`, status);
13878
13885
  if (status === 403) return new GoogleApiError("ACCESS_DENIED", `Google denied access to ${what}. Check the Google account, its access to this property, and the granted scopes. ${detail}`.trim(), status);
13879
13886
  if (status === 404) return new GoogleApiError("PROPERTY_NOT_FOUND", `Google could not find ${what}. Check the property and account access.`, status);
@@ -40543,7 +40550,7 @@ async function analyticsBeside(access, site, range, before, pages) {
40543
40550
  //#endregion
40544
40551
  //#region packages/core/dist/commands/audit.js
40545
40552
  const AUDIT_SECTION = "weekly-audit";
40546
- const AUDIT_SECTION_TEXT = "What the weekly crawl of the site found (broken and redirected internal links, missing or duplicate titles, descriptions and H1s, noindex, canonicals to another page, sitemap URLs that do not return 200, thin pages), with what is new, back or resolved since the crawl before. Only for sites added to the weekly site audit beta.";
40553
+ const AUDIT_SECTION_TEXT = "What the weekly crawl of the site found (broken and redirected internal links, missing or duplicate titles, descriptions and H1s, noindex, canonicals to another page, sitemap URLs that do not return 200, thin pages, tags that JavaScript changes), with what is new, back or resolved since the crawl before. Only for sites added to the weekly site audit beta.";
40547
40554
  const AUDIT_RULES = {
40548
40555
  link_to_error: "Internal links to a page that returns an error",
40549
40556
  link_to_redirect: "Internal links to a redirect",
@@ -40556,7 +40563,8 @@ const AUDIT_RULES = {
40556
40563
  canonical_elsewhere: "Pages whose canonical is another URL",
40557
40564
  sitemap_url_not_ok: "Sitemap URLs that do not return 200",
40558
40565
  sitemap_page_unlinked: "Sitemap pages no crawled page links to (heuristic: the crawl may not reach every page)",
40559
- thin_page: "Pages under 100 words (heuristic)"
40566
+ thin_page: "Pages under 100 words (heuristic)",
40567
+ js_changed_tags: "Pages whose raw HTML has another title, canonical or robots tag than the page after JavaScript runs"
40560
40568
  };
40561
40569
  const PAGE_SIZE$2 = 50;
40562
40570
  const SUMMARY_ROWS$1 = 20;
@@ -40571,6 +40579,17 @@ function evidence(finding, origin) {
40571
40579
  if (typeof details.location === "string") parts.push(`to ${relative$2(details.location, origin)}`);
40572
40580
  if (typeof details.canonical === "string") parts.push(`canonical ${relative$2(details.canonical, origin)}`);
40573
40581
  if (typeof details.words === "number") parts.push(`${details.words} words`);
40582
+ if (details.raw && typeof details.raw === "object") {
40583
+ const raw = details.raw;
40584
+ for (const key of [
40585
+ "title",
40586
+ "canonical",
40587
+ "robots"
40588
+ ]) if (key in raw) {
40589
+ const value = raw[key];
40590
+ parts.push(`raw ${key} ${typeof value === "string" ? key === "canonical" ? relative$2(value, origin) : value : "none"}`);
40591
+ }
40592
+ }
40574
40593
  const linking = typeof details.linking_pages === "number";
40575
40594
  const count = linking ? details.linking_pages : details.pages;
40576
40595
  if (typeof count === "number") {
@@ -40601,6 +40620,14 @@ function ordered(findings, since) {
40601
40620
  };
40602
40621
  return [...findings].sort((a, b) => rank(a) - rank(b) || a.rule.localeCompare(b.rule) || (a.subject < b.subject ? -1 : a.subject > b.subject ? 1 : 0));
40603
40622
  }
40623
+ function renderingText(rendering) {
40624
+ if (!rendering) return null;
40625
+ const pages = (n) => n === 1 ? "1 page" : `${n} pages`;
40626
+ if (rendering.mode === "on") return `JavaScript changed what some pages show, so the crawl rendered the parts of the site that need it (${pages(rendering.rendered)} rendered${rendering.failed ? `; ${pages(rendering.failed)} could not be rendered, so ${rendering.failed === 1 ? "it is" : "they are"} left out of the tag and text checks` : ""}).`;
40627
+ if (rendering.mode === "off") return "JavaScript did not change the pages checked, so the crawl read raw HTML.";
40628
+ if (rendering.mode === "unavailable") return "JavaScript rendering failed on the pages checked, so the crawl read raw HTML. If the site builds its pages with JavaScript, titles, canonicals and links may be missing here.";
40629
+ return rendering.failed && !rendering.rendered ? "JavaScript rendering failed, so the crawl read raw HTML." : null;
40630
+ }
40604
40631
  function runAuditReport(input, snapshot, call) {
40605
40632
  const site = input.site;
40606
40633
  const detail = input.detail ?? "summary";
@@ -40649,7 +40676,8 @@ function runAuditReport(input, snapshot, call) {
40649
40676
  const head = [
40650
40677
  `Weekly site audit of ${site}, crawled ${day$1(snapshot.finished_at)}: ${coverage}.${pages.blocked ? ` ${pages.blocked === 1 ? "1 URL" : `${pages.blocked} URLs`} blocked by robots.txt ${pages.blocked === 1 ? "was" : "were"} not fetched.` : ""}`,
40651
40678
  previous ? `Since the crawl of ${day$1(previous.finished_at)}: ${summary.findings.new} new, ${summary.findings.reopened} back, ${summary.findings.resolved} resolved. ${summary.findings.open} open now.` : `This is the first crawl, so every finding is new: ${summary.findings.open} open.`,
40652
- summary.findings.resolution === "crawled-pages-only" ? "Because the crawl is partial, a finding counts as resolved only when this crawl fetched its page again; a finding not seen here is not an all-clear." : null,
40679
+ renderingText(summary.rendering),
40680
+ summary.findings.resolution === "crawled-pages-only" ? summary.complete ? "Because some pages could not be rendered, a finding counts as resolved only when this crawl rendered its page; a finding not seen here is not an all-clear." : "Because the crawl is partial, a finding counts as resolved only when this crawl fetched its page again; a finding not seen here is not an all-clear." : null,
40653
40681
  summary.findings.capped_rules.length ? `Capped at 1,000 findings each, so these counts are lower bounds: ${summary.findings.capped_rules.join(", ")}.` : null,
40654
40682
  running
40655
40683
  ].filter(Boolean).join("\n");
@@ -43068,6 +43096,7 @@ const siteName = (property) => property.replace(/^sc-domain:|^https?:\/\//, "").
43068
43096
  const count = (n) => n.toLocaleString("en-US");
43069
43097
  const plural = (n, one, many = `${one}s`) => `${count(n)} ${n === 1 ? one : many}`;
43070
43098
  const list = (items) => items.length <= 1 ? items[0] ?? "" : `${items.slice(0, -1).join(", ")} and ${items.at(-1)}`;
43099
+ const sentence = (text) => /[.!?]$/.test(text) ? text : `${text}.`;
43071
43100
  function path(url) {
43072
43101
  try {
43073
43102
  const parsed = new URL(url);
@@ -43090,60 +43119,58 @@ const percent = (site) => {
43090
43119
  return Math.round(Math.abs(clicks.clicks - clicks.previous) / clicks.previous * 100);
43091
43120
  };
43092
43121
  function issues(site, startMs, endMs) {
43093
- const name = siteName(site.property);
43094
43122
  const found = [];
43123
+ if (site.index?.dropped) found.push({
43124
+ rank: 0,
43125
+ heading: `${plural(site.index.dropped, "page")} dropped`
43126
+ });
43127
+ const crawl = site.crawl;
43128
+ const crawled = crawl !== null && crawl.finished_at >= startMs && crawl.finished_at < endMs;
43129
+ if (crawled && crawl.status === "failed") found.push({
43130
+ rank: 1,
43131
+ heading: "crawl stopped early"
43132
+ });
43133
+ else if (!crawled && site.added_at < startMs) found.push({
43134
+ rank: 1,
43135
+ heading: "no crawl this week"
43136
+ });
43137
+ if (clicksChange(site) === "fell") found.push({
43138
+ rank: 2,
43139
+ heading: `clicks down ${percent(site)}%`
43140
+ });
43141
+ if (crawled && crawl.new_issues > 0) found.push({
43142
+ rank: 3,
43143
+ heading: plural(crawl.new_issues, "new issue")
43144
+ });
43145
+ return found;
43146
+ }
43147
+ function siteLines(site, startMs, endMs) {
43148
+ const lines = [];
43095
43149
  const index = site.index;
43096
- if (index?.dropped) {
43150
+ if (!index) lines.push("Google index: no checks ran this week yet.");
43151
+ else if (index.dropped) {
43097
43152
  const paths = index.dropped_pages.map((page) => path(page.url));
43098
43153
  const more = index.dropped - paths.length;
43099
43154
  const shown = more > 0 ? `${paths.join(", ")} and ${plural(more, "more")}` : list(paths);
43100
43155
  const reasons = new Set(index.dropped_pages.map((page) => page.coverage));
43101
43156
  const reason = reasons.size === 1 ? [...reasons][0] : null;
43102
- found.push({
43103
- rank: 0,
43104
- heading: `${plural(index.dropped, "page")} dropped`,
43105
- line: `${shown} dropped out of Google’s index.${reason ? ` Google says: ${reason}.` : ""}`,
43106
- next: `check ${index.dropped === 1 ? "it" : "they"} still return${index.dropped === 1 ? "s" : ""} 200 and ${index.dropped === 1 ? "is" : "are"} not noindexed.`,
43107
- prompt: `Why did ${paths[0] ?? "a page"} on ${name} drop out of Google’s index this week, and how do I fix it?`
43108
- });
43109
- }
43157
+ lines.push(`Google index: ${plural(index.dropped, "page")} dropped out (${shown}).${reason ? ` Google says: ${reason}.` : ""}${index.returned ? ` ${plural(index.returned, "page")} came back.` : ""} ${plural(index.checked, "page")} checked.`);
43158
+ } else lines.push(`Google index: ${plural(index.checked, "page")} checked, none dropped${index.returned ? `, ${plural(index.returned, "page")} came back` : ""}.`);
43110
43159
  const crawl = site.crawl;
43111
43160
  const crawled = crawl !== null && crawl.finished_at >= startMs && crawl.finished_at < endMs;
43112
- if (crawled && crawl.status === "failed") found.push({
43113
- rank: 1,
43114
- heading: "crawl stopped early",
43115
- line: `The weekly crawl stopped after ${plural(crawl.pages, "page")}${crawl.error ? `: ${crawl.error}` : "."}`,
43116
- next: "check the site is up. The next weekly crawl tries again.",
43117
- prompt: `Why did the weekly crawl of ${name} stop early, and what should I check?`
43118
- });
43119
- else if (!crawled && site.added_at < startMs) found.push({
43120
- rank: 1,
43121
- heading: "no crawl this week",
43122
- line: `No weekly crawl finished this week${site.start_error ? `: ${site.start_error}` : "."}`,
43123
- next: "check the site is up. The crawl tries again each hour.",
43124
- prompt: `Why has the weekly crawl of ${name} not finished, and what should I check?`
43125
- });
43126
- if (clicksChange(site) === "fell") {
43127
- const clicks = site.clicks;
43128
- found.push({
43129
- rank: 2,
43130
- heading: `clicks down ${percent(site)}%`,
43131
- line: `Search clicks fell ${percent(site)}%, from ${count(clicks.previous)} to ${count(clicks.clicks)} (${weekLabel(clicks.start, clicks.end)}, against the 7 days before).`,
43132
- next: "ask your agent which pages and queries lost them.",
43133
- prompt: `Which pages and queries lost search clicks on ${name} in the last week, and why?`
43134
- });
43135
- }
43136
- if (crawled && crawl.new_issues > 0) {
43161
+ if (crawled && crawl.status === "failed") lines.push(`Weekly crawl: stopped after ${plural(crawl.pages, "page")}${crawl.error ? `: ${sentence(crawl.error)}` : "."} It tries again next week.`);
43162
+ else if (crawled) {
43137
43163
  const rule = crawl.top_rule ? AUDIT_RULES[crawl.top_rule] : void 0;
43138
- found.push({
43139
- rank: 3,
43140
- heading: plural(crawl.new_issues, "new issue"),
43141
- line: `The weekly crawl found ${plural(crawl.new_issues, "new issue")}${rule ? `, most of them ${rule.charAt(0).toLowerCase()}${rule.slice(1)}` : ""}.`,
43142
- next: "ask your agent for the weekly audit of this site.",
43143
- prompt: `What did the weekly crawl of ${name} find this week, and what should I fix first?`
43144
- });
43145
- }
43146
- return found;
43164
+ lines.push(crawl.new_issues ? `Weekly crawl: ${plural(crawl.pages, "page")}, ${plural(crawl.new_issues, "new issue")}${rule ? `, most of them ${rule.charAt(0).toLowerCase()}${rule.slice(1)}` : ""}.` : `Weekly crawl: ${plural(crawl.pages, "page")}, no new issues.`);
43165
+ } else if (site.added_at < startMs) lines.push(`Weekly crawl: none finished this week${site.start_error ? `: ${sentence(site.start_error)}` : "."} It tries again each hour.`);
43166
+ else lines.push("Weekly crawl: the first crawl is still running.");
43167
+ const clicks = site.clicks;
43168
+ if (clicks) {
43169
+ const change = clicks.previous > 0 ? Math.round((clicks.clicks - clicks.previous) / clicks.previous * 100) : null;
43170
+ const trend = change === null ? `from ${count(clicks.previous)}` : change === 0 ? "level with" : `${change > 0 ? "up" : "down"} ${Math.abs(change)}% on`;
43171
+ lines.push(`Search clicks: ${count(clicks.clicks)} (${weekLabel(clicks.start, clicks.end)}), ${trend}${change === null ? "" : ` ${count(clicks.previous)}`} the 7 days before.`);
43172
+ } else lines.push("Search clicks: not available this week.");
43173
+ return lines;
43147
43174
  }
43148
43175
  function weekMarkdown(data) {
43149
43176
  const startMs = Date.parse(`${data.start}T00:00:00Z`);
@@ -43151,43 +43178,21 @@ function weekMarkdown(data) {
43151
43178
  const title = `# ${weekTitle(data)}`;
43152
43179
  if (!data.sites.length) return `${title}\n\nNo site is in your weekly audit yet. Add one on the Sites tab: ${data.account}#sites`;
43153
43180
  const byName = (a, b) => siteName(a.property).localeCompare(siteName(b.property)) || a.property.localeCompare(b.property);
43154
- const sites = [...data.sites].sort(byName);
43155
- const attention = [];
43156
- const quiet = [];
43157
- const waiting = [];
43158
- for (const site of sites) {
43159
- const found = issues(site, startMs, endMs);
43160
- if (found.length) attention.push({
43161
- site,
43162
- found
43163
- });
43164
- else if (!site.crawl || !site.index) waiting.push(site);
43165
- else quiet.push(site);
43166
- }
43167
- attention.sort((a, b) => a.found[0].rank - b.found[0].rank || byName(a.site, b.site));
43168
- const total = sites.length;
43181
+ const rows = data.sites.map((site) => ({
43182
+ site,
43183
+ found: issues(site, startMs, endMs),
43184
+ waiting: !site.crawl || !site.index
43185
+ }));
43186
+ const attention = rows.filter((row) => row.found.length);
43187
+ const quiet = rows.filter((row) => !row.found.length && !row.waiting);
43188
+ rows.sort((a, b) => (a.found[0]?.rank ?? Number.POSITIVE_INFINITY) - (b.found[0]?.rank ?? Number.POSITIVE_INFINITY) || byName(a.site, b.site));
43189
+ const total = rows.length;
43169
43190
  const out = [
43170
43191
  title,
43171
43192
  "",
43172
- attention.length ? total === 1 ? "Your site needs a look this week." : `${attention.length} of your ${total} sites ${attention.length === 1 ? "needs" : "need"} a look this week.` : quiet.length ? total === 1 ? "Your site had a quiet week." : quiet.length === total ? `All ${total} of your sites had a quiet week.` : `${quiet.length} of your ${total} sites had a quiet week.` : "Your sites are still on their first checks."
43193
+ attention.length ? total === 1 ? "Your site had changes worth a look this week." : `${attention.length} of your ${total} sites had changes worth a look this week.` : quiet.length ? total === 1 ? "Your site had a quiet week." : quiet.length === total ? `All ${total} of your sites had a quiet week.` : `${quiet.length} of your ${total} sites had a quiet week.` : "Your sites are still on their first checks."
43173
43194
  ];
43174
- if (attention.length) {
43175
- out.push("", "## Needs attention");
43176
- for (const { site, found } of attention) {
43177
- const [first, ...rest] = found;
43178
- const also = rest.length ? ` Also: ${list(rest.map((item) => item.heading))}.` : "";
43179
- const rose = clicksChange(site) === "rose" ? ` Search clicks rose ${percent(site)}%.` : "";
43180
- out.push("", `### ${siteName(site.property)}: ${first.heading}`, "", `- ${first.line}${also}${rose}`, `- Next step: ${first.next}`, ...site.link ? [`- [View site](${site.link})`] : []);
43181
- }
43182
- }
43183
- if (quiet.length) {
43184
- const risen = quiet.filter((site) => clicksChange(site) === "rose");
43185
- out.push("", "## All quiet", "", `${list(quiet.map((site) => siteName(site.property)))}: no drops, no new issues.${risen.map((site) => ` Search clicks rose ${percent(site)}% on ${siteName(site.property)}.`).join("")}`);
43186
- }
43187
- if (waiting.length) out.push("", "## Not checked yet", "", `${list(waiting.map((site) => siteName(site.property)))}: the first crawl or Google checks are still running.`);
43188
- const first = attention[0];
43189
- const prompt = first ? first.found[0].prompt : `What are the best quick wins on ${siteName((quiet[0] ?? sites[0]).property)} this month?`;
43190
- out.push("", "## Ask your agent", "", "Paste this into your agent:", "", "```", prompt, "```");
43195
+ for (const { site, found } of rows) out.push("", `## ${siteName(site.property)}${found.length ? `: ${list(found.map((item) => item.heading))}` : ""}`, "", ...siteLines(site, startMs, endMs).map((line) => `- ${line}`), ...site.link ? [`- [View site](${site.link})`] : []);
43191
43196
  return out.join("\n");
43192
43197
  }
43193
43198
  async function runAllSites(deps, sites) {
@@ -43247,15 +43252,38 @@ const SHARED_TOOLS = [
43247
43252
  name: "seo_sites",
43248
43253
  command: "data",
43249
43254
  title: "List sites",
43250
- description: "Lists the Search Console and Google Analytics properties the connected Google accounts can read, the Bing Webmaster site for each, and which research keys are set. Call it first.",
43251
- input: z.object({}),
43252
- run: listSites
43255
+ description: "Lists the Search Console and Google Analytics properties the connected Google accounts can read, the Bing Webmaster site for each, and which research keys are set. Call it first. With add: starts the weekly site audit of that site on the hosted server (a weekly crawl, daily Google index checks, a Monday email and webhook with what changed, and alerts when a page drops out of Google's index). A site that needs paying for returns a Stripe Checkout link: give it to the person to open, and the audit starts once they pay.",
43256
+ input: z.object({ add: site.optional().describe("Optional. A site to add to the weekly site audit. Only when the person asks for it: a site can cost money.") }),
43257
+ run: async (surface, input) => {
43258
+ if (!input.add) return listSites(surface);
43259
+ const start = surface.deps.startAudit;
43260
+ if (!start) throw new CommandError("INVALID_INPUT", "The weekly site audit runs on the hosted server only. Connect https://seoskill.dev/mcp and call seo_sites with add there.");
43261
+ const property = await surface.resolveSite(input.add);
43262
+ const result = await start(property);
43263
+ return {
43264
+ text: {
43265
+ added: `Added ${property} to the weekly site audit. Its first crawl and index checks have started; ask ${surface.deps.call("report", {
43266
+ site: property,
43267
+ section: AUDIT_SECTION
43268
+ })} for the findings once the crawl is done.`,
43269
+ exists: `${property} is already in the weekly site audit.`,
43270
+ pending: "The payment went through and the plan is starting. Call seo_sites with add again in a minute.",
43271
+ checkout: result.status === "checkout" ? `${property} needs a plan: $${result.price} a month per site, cancel at any time. Give the person this Stripe Checkout link to open and pay: ${result.url}\nThe audit of ${property} starts once they pay. Call seo_sites with add again afterwards to confirm.` : "",
43272
+ full: result.status === "full" ? `This account already audits ${result.limit} sites, the most it can. Remove one on the account page first.` : "",
43273
+ payment_failed: `Stripe could not take the payment for another site, so ${property} was not added. The person can check their card under Manage billing on the account page.`
43274
+ }[result.status],
43275
+ data: {
43276
+ property,
43277
+ ...result
43278
+ }
43279
+ };
43280
+ }
43253
43281
  }),
43254
43282
  tool({
43255
43283
  name: "seo_report",
43256
43284
  command: "report",
43257
43285
  title: "Search Console report",
43258
- description: `Start here. Without site: a short summary of every site in the person's weekly site audit (beta) for last week, with what needs a look and the next step for each, ending with the site to ask about next; an account outside that beta gets its site list to pick from. With site: the main report for that Search Console property, the overview plus each section's row count and top rows. With site and section: that section's rows; page sections also check their top 20 URLs live. Sections:\n${Object.entries(SECTIONS).map(([id, text]) => `- ${id}: ${text}`).join("\n")}`,
43286
+ description: `Start here. Without site: a short summary of every site in the person's weekly site audit (beta) for last week, with each site's Google index, weekly crawl and search clicks, sites with changes first, ending with the site to ask about next; an account outside that beta gets its site list to pick from. With site: the main report for that Search Console property, the overview plus each section's row count and top rows. With site and section: that section's rows; page sections also check their top 20 URLs live. Sections:\n${Object.entries(SECTIONS).map(([id, text]) => `- ${id}: ${text}`).join("\n")}`,
43259
43287
  input: z.object({
43260
43288
  site: site.optional().describe("Leave it out for the summary of every audited site (weekly site audit beta). Otherwise a Search Console property or site, such as sc-domain:example.com, https://example.com/ or example.com."),
43261
43289
  section: z.enum(SECTION_IDS).optional().describe("Optional, needs site. Leave it out first; then ask for one section."),