seo 0.17.7 → 0.17.8

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-D2vwEHEA.js";
2
+ import { i as __toESM, n as version, r as __commonJSMin, t as load } from "./esm-R3uezpJ-.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";
@@ -14688,6 +14688,7 @@ const ID_COLUMNS = [
14688
14688
  "changeDate",
14689
14689
  "query",
14690
14690
  "queryFlags",
14691
+ "shape",
14691
14692
  "keyword",
14692
14693
  "url",
14693
14694
  "page",
@@ -22713,10 +22714,251 @@ async function pageOpportunitiesReport(input, dependencies = defaultDependencies
22713
22714
  recommendations: pageOpportunityRecommendations(analysis)
22714
22715
  };
22715
22716
  }
22717
+ // packages/core/dist/analyze/ai-queries.js
22718
+ const RULES = [
22719
+ ["agent_prompt", "^(search the web for|browse the web|find sources)|do not invent|return the [0-9]+ most relevant|include source urls|context: location|do not include location|question: |reply only with|the model you are using"],
22720
+ ["tracker", "\\. ?my location is |\\?\\. ?my( |$)|^evaluate the .+ on "],
22721
+ ["reply", "^(yes|yeah|yep|ok|okay|sure|yes please|go on|continue|keep going|tell me more|why not|how so|really|exactly|show me|and then|thanks|thank you|got it|what else|anything else)[?!.,]*$"],
22722
+ ["follow_up", "^(what|how) about .{1,40}$|^(and|so|ok so|okay so|but) (what|which|how|why) "],
22723
+ ["operator", "(^|\\s)-?(site|before|after|intitle|inurl|intext|filetype):|\"[^\"]*\" or \""],
22724
+ ["chat", "\\b(please|can you|could you|give me|show me|tell me|i want|i need|i have|i am|should i|do i need|is it worth|help me|walk me through)\\b|^(what|how|why|is|does|can|will|would) (it|that|this|they)\\b"],
22725
+ ["long", "^(\\S+\\s+){9,}\\S+$"]
22726
+ ];
22727
+ const AI_QUERY_KINDS = {
22728
+ agent_prompt: "text from an agent prompt, such as \"search the web for\"",
22729
+ tracker: "a visibility-tool probe, such as \"my location is\"",
22730
+ reply: "a bare reply, such as \"yes\" or \"tell me more\"",
22731
+ follow_up: "a follow-up, such as \"what about …\"",
22732
+ operator: "search operators, such as site:, before: or \"a\" or \"b\"",
22733
+ chat: "chat phrasing, such as \"can you\" or \"should i\"",
22734
+ long: "ten or more words with no other sign"
22735
+ };
22736
+ const MATCHERS = RULES.map(([kind, pattern]) => [kind, new RegExp(pattern)]);
22737
+ const AI_QUERY_PATTERN = RULES.map(([, pattern]) => `(?:${pattern})`).join("|");
22738
+ const NOISE = [
22739
+ ["spaced_letters", /(^|\s)(\S\s){3,}\S(\s|$)/u],
22740
+ ["broken_encoding", /^(яю|ÿþ|þÿ)|&#[0-9]+;?|&[a-z]+;|[âÃÂ][\u0080-\u00bf€™œ“”]|\ufffd/u],
22741
+ ["pasted_text", /^(p [a-z]{3,} |here (are|is) (all )?the |here's the |done[,.!]? (you|here) |current state: )/u]
22742
+ ];
22743
+ function aiQueryNoise(query) {
22744
+ const text = query.trim().toLowerCase();
22745
+ return NOISE.find(([, pattern]) => pattern.test(text))?.[0] ?? null;
22746
+ }
22747
+ const QUESTION = /^(how|what|what's|whats|which|why|when|where|who|is|are|can|could|does|do|should|would|will|i need|i want|i have|i'm looking|we need|we want)\b|\?$/u;
22748
+ const ASKABLE_KINDS = /* @__PURE__ */ new Set(["chat", "long"]);
22749
+ const PROMPT_CHARACTERS = 500;
22750
+ function askable(query, kind) {
22751
+ const text = query.trim().toLowerCase().replace(/^["'“]+/u, "");
22752
+ return Boolean(kind && ASKABLE_KINDS.has(kind)) && text.length <= PROMPT_CHARACTERS && QUESTION.test(text);
22753
+ }
22754
+ function aiQueryKind(query) {
22755
+ const text = query.trim().toLowerCase();
22756
+ return MATCHERS.find(([, pattern]) => pattern.test(text))?.[0] ?? null;
22757
+ }
22758
+ const STOP = new Set("the and for with that this what which who how why when where are is was can does do did you your our from about into than then them they their there have has had will would should could not but its it’s me my i am of to in on at by or an as be if so".split(" "));
22759
+ function words$3(query) {
22760
+ return new Set(query.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter((word) => word.length >= 3 && !STOP.has(word)).map((word) => word.length > 4 && word.endsWith("s") ? word.slice(0, -1) : word));
22761
+ }
22762
+ const SAME_QUESTION = .6;
22763
+ const MAX_ROWS = 25e3;
22764
+ const EXAMPLES = 3;
22765
+ const CANDIDATES = 200;
22766
+ const overlap = (a, b, weight) => {
22767
+ let shared = 0;
22768
+ let union = 0;
22769
+ for (const word of a) {
22770
+ union += weight(word);
22771
+ if (b.has(word)) shared += weight(word);
22772
+ }
22773
+ for (const word of b) if (!a.has(word)) union += weight(word);
22774
+ return union ? shared / union : 0;
22775
+ };
22776
+ const round$2 = (value, places) => Math.round(value * 10 ** places) / 10 ** places;
22777
+ async function aiQueriesReport(input, searchAnalytics) {
22778
+ const range = {
22779
+ startDate: input.startDate,
22780
+ endDate: input.endDate
22781
+ };
22782
+ const [matched, site] = await Promise.all([searchAnalytics(input.site, {
22783
+ ...range,
22784
+ dimensions: ["query", "page"],
22785
+ type: "web",
22786
+ dataState: "final",
22787
+ maxRows: MAX_ROWS,
22788
+ dimensionFilterGroups: [{ filters: [{
22789
+ dimension: "query",
22790
+ operator: "includingRegex",
22791
+ expression: AI_QUERY_PATTERN
22792
+ }] }]
22793
+ }), searchAnalytics(input.site, {
22794
+ ...range,
22795
+ dimensions: [],
22796
+ type: "web",
22797
+ dataState: "final"
22798
+ })]);
22799
+ const rows = [...matched.rows].sort((a, b) => b.impressions - a.impressions || String(a.keys[0]).localeCompare(String(b.keys[0])) || String(a.keys[1]).localeCompare(String(b.keys[1])));
22800
+ const usage = /* @__PURE__ */ new Map();
22801
+ const unique = new Set(rows.map((row) => String(row.keys[0] ?? "")));
22802
+ for (const query of unique) for (const word of words$3(query)) usage.set(word, (usage.get(word) ?? 0) + 1);
22803
+ const weight = (word) => Math.log((unique.size + 1) / (usage.get(word) ?? 1));
22804
+ const groups = [];
22805
+ const byWord = /* @__PURE__ */ new Map();
22806
+ const byText = /* @__PURE__ */ new Map();
22807
+ const kindOf = /* @__PURE__ */ new Map();
22808
+ const noise = /* @__PURE__ */ new Map();
22809
+ for (const row of rows) {
22810
+ const query = String(row.keys[0] ?? "");
22811
+ const page = String(row.keys[1] ?? "");
22812
+ const kind = aiQueryKind(query);
22813
+ if (!kind) continue;
22814
+ const junk = aiQueryNoise(query);
22815
+ if (junk) {
22816
+ const seen = noise.get(junk) ?? /* @__PURE__ */ new Set();
22817
+ seen.add(query.trim().toLowerCase());
22818
+ noise.set(junk, seen);
22819
+ continue;
22820
+ }
22821
+ const text = query.trim().toLowerCase();
22822
+ const own = words$3(query);
22823
+ let group = byText.get(text);
22824
+ if (!group) {
22825
+ let checked = 0;
22826
+ for (const word of own) {
22827
+ for (const candidate of byWord.get(word) ?? []) {
22828
+ if (++checked > CANDIDATES) break;
22829
+ if (overlap(own, candidate.words, weight) >= SAME_QUESTION) {
22830
+ group = candidate;
22831
+ break;
22832
+ }
22833
+ }
22834
+ if (group || checked > CANDIDATES) break;
22835
+ }
22836
+ }
22837
+ if (!group) {
22838
+ group = {
22839
+ words: own,
22840
+ queries: /* @__PURE__ */ new Map(),
22841
+ pages: /* @__PURE__ */ new Map(),
22842
+ kinds: /* @__PURE__ */ new Map(),
22843
+ clicks: 0,
22844
+ impressions: 0,
22845
+ positionWeight: 0
22846
+ };
22847
+ groups.push(group);
22848
+ for (const word of own) {
22849
+ const list = byWord.get(word) ?? [];
22850
+ list.push(group);
22851
+ byWord.set(word, list);
22852
+ }
22853
+ }
22854
+ byText.set(text, group);
22855
+ if (!kindOf.has(text)) {
22856
+ kindOf.set(text, kind);
22857
+ group.kinds.set(kind, (group.kinds.get(kind) ?? 0) + 1);
22858
+ }
22859
+ group.queries.set(query, (group.queries.get(query) ?? 0) + row.impressions);
22860
+ group.pages.set(page, (group.pages.get(page) ?? 0) + row.impressions);
22861
+ group.clicks += row.clicks;
22862
+ group.impressions += row.impressions;
22863
+ group.positionWeight += row.position * row.impressions;
22864
+ }
22865
+ const byKind = /* @__PURE__ */ new Map();
22866
+ for (const kind of kindOf.values()) {
22867
+ const entry = byKind.get(kind) ?? {
22868
+ queries: 0,
22869
+ impressions: 0
22870
+ };
22871
+ entry.queries += 1;
22872
+ byKind.set(kind, entry);
22873
+ }
22874
+ for (const row of rows) {
22875
+ const kind = kindOf.get(String(row.keys[0] ?? "").trim().toLowerCase());
22876
+ const entry = kind && byKind.get(kind);
22877
+ if (entry) entry.impressions += row.impressions;
22878
+ }
22879
+ const queries = kindOf.size;
22880
+ const impressions = groups.reduce((sum, g) => sum + g.impressions, 0);
22881
+ const clicks = groups.reduce((sum, g) => sum + g.clicks, 0);
22882
+ const total = site.rows[0] ?? {
22883
+ clicks: 0,
22884
+ impressions: 0
22885
+ };
22886
+ const items = groups.map((group) => {
22887
+ const most = (map) => [...map].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([name]) => name);
22888
+ const [first, ...rest] = most(group.queries);
22889
+ const kind = [...group.kinds].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0]?.[0];
22890
+ return {
22891
+ query: first ?? "",
22892
+ page: most(group.pages)[0] ?? "",
22893
+ askable: askable(first ?? "", kind),
22894
+ pages: group.pages.size,
22895
+ kind,
22896
+ wordings: group.queries.size,
22897
+ impressions: group.impressions,
22898
+ clicks: group.clicks,
22899
+ ctr: group.impressions ? round$2(group.clicks / group.impressions, 4) : 0,
22900
+ position: group.impressions ? round$2(group.positionWeight / group.impressions, 1) : 0,
22901
+ otherWordings: rest.slice(0, EXAMPLES)
22902
+ };
22903
+ }).sort((a, b) => b.impressions - a.impressions || b.wordings - a.wordings || a.query.localeCompare(b.query) || a.page.localeCompare(b.page));
22904
+ const pct = (part, whole) => whole ? round$2(part / whole * 100, 1) : null;
22905
+ const kinds = [...byKind].sort((a, b) => b[1].impressions - a[1].impressions || a[0].localeCompare(b[0])).map(([kind, entry]) => `${kind} ${entry.queries}`).join(", ");
22906
+ const leftOut = [...noise].sort((a, b) => a[0].localeCompare(b[0])).map(([reason, seen]) => `${reason.replace("_", " ")} ${seen.size}`).join(", ");
22907
+ const asked = items.filter((item) => item.askable).length;
22908
+ const capped = matched.rowsFetched >= MAX_ROWS;
22909
+ return {
22910
+ range,
22911
+ verdict: queries ? `${queries} queries in ${groups.length} questions have the shape of AI conversations or agent searches.` : "No queries with the shape of AI conversations or agent searches.",
22912
+ summary: {
22913
+ queries,
22914
+ questions: groups.length,
22915
+ askable: asked,
22916
+ leftOut: leftOut || "none",
22917
+ impressions,
22918
+ clicks,
22919
+ shareOfImpressionsPct: pct(impressions, total.impressions),
22920
+ byKind: kinds || "none",
22921
+ ctr: impressions ? round$2(clicks / impressions, 4) : 0,
22922
+ siteCtr: total.impressions ? round$2(total.clicks / total.impressions, 4) : 0
22923
+ },
22924
+ kinds: AI_QUERY_KINDS,
22925
+ items,
22926
+ caveats: [
22927
+ "A heuristic: these queries match the patterns of AI conversations and agent searches. Search Console does not mark AI Mode or AI Overviews, and people type some of these too.",
22928
+ "A minimum: Search Console leaves out rare queries, and these are rare by nature.",
22929
+ "Rewordings of one question are grouped by their shared words; page is the page with the most impressions for it.",
22930
+ "Left out and counted, not shown: letters split by spaces, text broken by a wrong encoding, and text pasted from a tool or an agent’s output.",
22931
+ "askable: a chat or long question that opens with a question word or a request such as \"i need\", or ends with a question mark, so an AI engine can be asked it as it is. ai_answers checks the top askable questions only.",
22932
+ "Search Console’s Generative AI report is not in its API, so it is not here.",
22933
+ ...capped ? [`Capped at the first ${MAX_ROWS} matching query and page rows.`] : []
22934
+ ]
22935
+ };
22936
+ }
22937
+ // packages/core/dist/analyze/query-shape.js
22938
+ const COMPARISON = /\b(vs|versus|alternative|alternatives|compare|comparison|best)\b/;
22939
+ function queryShape(query) {
22940
+ const text = query.trim().toLowerCase();
22941
+ if (COMPARISON.test(text)) return "comparison";
22942
+ const kind = aiQueryKind(text);
22943
+ if (kind && kind !== "chat" && kind !== "long") return kind;
22944
+ if (QUESTION.test(text)) return "question";
22945
+ return kind;
22946
+ }
22947
+ function queryShapeLine(queries) {
22948
+ const counts = /* @__PURE__ */ new Map();
22949
+ for (const query of queries) {
22950
+ const shape = queryShape(query);
22951
+ if (shape) counts.set(shape, (counts.get(shape) ?? 0) + 1);
22952
+ }
22953
+ if (!counts.size) return null;
22954
+ const shaped = [...counts.values()].reduce((sum, n) => sum + n, 0);
22955
+ const parts = [...counts].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([shape, n]) => `${shape} ${n}`);
22956
+ return `Query shapes, ${shaped} of ${queries.length} queries: ${parts.join(", ")}.`;
22957
+ }
22716
22958
  // packages/core/dist/analyze/content-optimization.js
22717
22959
  function intentFor(query) {
22718
22960
  const value = query.toLowerCase();
22719
- if (/\b(vs|versus|alternative|alternatives|compare|comparison|best)\b/.test(value)) return "comparison";
22961
+ if (COMPARISON.test(value)) return "comparison";
22720
22962
  if (/\b(price|pricing|cost|buy|deal|coupon|review|reviews)\b/.test(value)) return "commercial";
22721
22963
  if (/\b(how|steps|guide|tutorial|setup|fix|create|make)\b/.test(value)) return "how-to";
22722
22964
  if (/\b(what is|meaning|definition|explained|why)\b/.test(value)) return "definition";
@@ -29309,7 +29551,7 @@ const NAVIGATIONAL_STEM_THRESHOLDS = {
29309
29551
  function compact(value) {
29310
29552
  return normalizeBrandText(value).replace(/\s+/g, "");
29311
29553
  }
29312
- function round$2(value, digits) {
29554
+ function round$1(value, digits) {
29313
29555
  return Number(value.toFixed(digits));
29314
29556
  }
29315
29557
  function stemQueryEvidence(rows, stem) {
@@ -29336,8 +29578,8 @@ function stemQueryEvidence(rows, stem) {
29336
29578
  query,
29337
29579
  clicks,
29338
29580
  impressions,
29339
- ctr: round$2(clicks / impressions, 4),
29340
- position: round$2(weightedPosition / impressions, 2),
29581
+ ctr: round$1(clicks / impressions, 4),
29582
+ position: round$1(weightedPosition / impressions, 2),
29341
29583
  sourceRows
29342
29584
  };
29343
29585
  }
@@ -35072,7 +35314,7 @@ const GENERIC_ANCHORS = /^(click here|here|read more|learn more|more|this|this p
35072
35314
  function normalise$1(value) {
35073
35315
  return value.normalize("NFKD").replace(/\p{Diacritic}/gu, "").normalize("NFC").replace(/([\p{L}\p{N}])[’'`]([\p{L}\p{N}])/gu, "$1$2").toLowerCase().replace(/&/g, " and ").replace(/[^\p{L}\p{N}]+/gu, " ").replace(/\s+/g, " ").trim();
35074
35316
  }
35075
- const words$3 = (value) => normalise$1(value).split(" ").filter(Boolean);
35317
+ const words$2 = (value) => normalise$1(value).split(" ").filter(Boolean);
35076
35318
  const FUNCTION_WORDS = new Set("a an and are as at be but by for from has have how if in into is it its of on or that the their then there these they this to was we were what when where which who why will with you your our can do does not just more most also than too very about after before over under again all any each other some such no nor only own same so up out off one two both every few several many much should would could because while since although though until unless whether however".split(" "));
35077
35319
  const NOT_PLURAL = /* @__PURE__ */ new Set([
35078
35320
  "always",
@@ -35133,7 +35375,7 @@ function stem(word) {
35133
35375
  if (one.length > 6 && one.endsWith("ing")) return one.slice(0, -3);
35134
35376
  return one;
35135
35377
  }
35136
- const terms = (text) => words$3(text).filter((word) => word.length > 1 && !FUNCTION_WORDS.has(word) && !/^\d+$/.test(word)).map(stem);
35378
+ const terms = (text) => words$2(text).filter((word) => word.length > 1 && !FUNCTION_WORDS.has(word) && !/^\d+$/.test(word)).map(stem);
35137
35379
  const slugWords = (url) => {
35138
35380
  try {
35139
35381
  return new URL(url).pathname.split(/[/._-]+/).filter(Boolean).join(" ");
@@ -35467,7 +35709,7 @@ function siteStartUrl(site) {
35467
35709
  if (value.startsWith("sc-domain:")) return `https://${value.slice(10)}/`;
35468
35710
  return `${new URL(/^https?:\/\//i.test(value) ? value : `https://${value}`).origin}/`;
35469
35711
  }
35470
- function round$1(value, places = 3) {
35712
+ function round(value, places = 3) {
35471
35713
  const factor = 10 ** places;
35472
35714
  return Math.round(value * factor) / factor;
35473
35715
  }
@@ -35823,7 +36065,7 @@ async function analyse(input, deps, crawl, context) {
35823
36065
  sentence: decision.sentence?.text ?? null,
35824
36066
  section: decision.sentence?.section || null,
35825
36067
  sentenceMatch: decision.sentence?.match ?? null,
35826
- similarity: round$1(candidate.similarity),
36068
+ similarity: round(candidate.similarity),
35827
36069
  sharedQueries: candidate.sharedQueries,
35828
36070
  targetInboundLinks: inbound[candidate.target] ?? 0,
35829
36071
  sourceType: types[candidate.source] ?? null,
@@ -40997,7 +41239,7 @@ function push(result, text, from, to) {
40997
41239
  text: text.slice(start, end)
40998
41240
  });
40999
41241
  }
41000
- function words$2(text) {
41242
+ function words$1(text) {
41001
41243
  return text.match(/[A-Za-z0-9][A-Za-z0-9'\u2019-]*/g) ?? [];
41002
41244
  }
41003
41245
  const FINITE = new Set(`am is are was were be been being has have had do does did can could will would shall should may might must
@@ -41014,7 +41256,7 @@ const FINITE = new Set(`am is are was were be been being has have had do does di
41014
41256
  happen happens happened leave leaves left bring brings brought live lives lived set sets love loves loved
41015
41257
  like likes liked hate hates`.split(/\s+/));
41016
41258
  function verbless(sentence) {
41017
- for (const raw of words$2(sentence)) {
41259
+ for (const raw of words$1(sentence)) {
41018
41260
  const word = raw.toLowerCase().replace(/\u2019/g, "'");
41019
41261
  if (FINITE.has(word)) return false;
41020
41262
  if (/(?:n't|'s|'re|'ve|'ll|'d|'m)$/.test(word)) return false;
@@ -41106,7 +41348,7 @@ var Context = class {
41106
41348
  let total = 0;
41107
41349
  let prose = 0;
41108
41350
  for (const block of doc.blocks) {
41109
- const count = words$2(block.text).length;
41351
+ const count = words$1(block.text).length;
41110
41352
  total += count;
41111
41353
  if (PROSE.includes(block.kind)) prose += count;
41112
41354
  }
@@ -42081,7 +42323,7 @@ function heroLength(ctx) {
42081
42323
  if (ctx.level(rule) === "off") return;
42082
42324
  for (const block of ctx.blocks(["heading"])) {
42083
42325
  if (block.level !== 1) continue;
42084
- const count = words$2(block.text).length;
42326
+ const count = words$1(block.text).length;
42085
42327
  if (count <= 12 && block.text.length <= 70) continue;
42086
42328
  ctx.hit(rule, block, 0, block.text.length, `The H1 is ${count} words. A headline that long is hard to take in at a glance.`, "Keep the main promise in the H1 and move the rest to the line below it.");
42087
42329
  }
@@ -42106,7 +42348,7 @@ function reviews(ctx) {
42106
42348
  PROOF.lastIndex = 0;
42107
42349
  for (const found of block.norm.matchAll(PROOF)) ctx.review("proof", block, found.index ?? 0, (found.index ?? 0) + found[0].length, `Is there a source for "${found[0]}" on the page? Link it or say where the number comes from.`);
42108
42350
  }
42109
- if (block.kind === "paragraph" && block.endsSection && sentences.length === 1 && words$2(block.text).length <= 10 && words$2(block.text).filter((word) => /[a-z]/i.test(word)).length >= 3 && /[.!?]["')]?$/.test(block.text)) ctx.review("mic-drop", block, 0, block.text.length, "Does this closing line add a fact? If it only restates the paragraph above, cut it.");
42351
+ if (block.kind === "paragraph" && block.endsSection && sentences.length === 1 && words$1(block.text).length <= 10 && words$1(block.text).filter((word) => /[a-z]/i.test(word)).length >= 3 && /[.!?]["')]?$/.test(block.text)) ctx.review("mic-drop", block, 0, block.text.length, "Does this closing line add a fact? If it only restates the paragraph above, cut it.");
42110
42352
  }
42111
42353
  if (ctx.preset === "landing" || ctx.preset === "meta") for (const block of ctx.blocks([
42112
42354
  "title",
@@ -42115,7 +42357,7 @@ function reviews(ctx) {
42115
42357
  ])) {
42116
42358
  if (block.kind === "heading" && block.level !== 1) continue;
42117
42359
  if (!block.text) continue;
42118
- const later = words$2(block.text).slice(1);
42360
+ const later = words$1(block.text).slice(1);
42119
42361
  if (/\d/.test(block.text) || later.some((word) => /^[A-Z]/.test(word))) continue;
42120
42362
  ctx.review("swap-test", block, 0, block.text.length, "Would this line work unchanged on a competitor's page? If so, add the product, number or result only you can claim.");
42121
42363
  }
@@ -42275,7 +42517,7 @@ function negativeParallelism(ctx) {
42275
42517
  const sentence = sentenceAt(sentences, start);
42276
42518
  const subject = block.norm.slice(sentence.start, start).trim();
42277
42519
  const pronoun = /^(?:but |and |so )?(?:it|this|that|they)?$/i.test(subject.replace(/(?:'s|'re)$/, ""));
42278
- const firstWords = words$2(block.norm.slice(sentence.start, end)).length;
42520
+ const firstWords = words$1(block.norm.slice(sentence.start, end)).length;
42279
42521
  let level = "warning";
42280
42522
  if (kind === "reveal" || kind === "about" || kind === "repeated") level = "error";
42281
42523
  else if (FRAMING.test(subject)) level = "error";
@@ -42329,7 +42571,7 @@ function contrastReframe(ctx) {
42329
42571
  for (const block of ctx.blocks([...SENTENCE_KINDS, "heading"])) for (const sentence of ctx.sentences(block)) {
42330
42572
  const text = sentence.text;
42331
42573
  const just = NOT_JUST.exec(text);
42332
- if (just && (just[0].startsWith(",") || words$2(text).length <= 16) && !insideQuotes(block.norm, sentence.start + just.index, sentence.start + just.index + just[0].length)) {
42574
+ if (just && (just[0].startsWith(",") || words$1(text).length <= 16) && !insideQuotes(block.norm, sentence.start + just.index, sentence.start + just.index + just[0].length)) {
42333
42575
  ctx.hit(rule, block, sentence.start, sentence.end, "A \"not just X\" contrast inflates the claim instead of stating it.", "Say what it is or does in one plain clause, and drop the \"not just\" half.");
42334
42576
  continue;
42335
42577
  }
@@ -42342,8 +42584,8 @@ function contrastReframe(ctx) {
42342
42584
  const right = rightAll.split(/[,;:.!?(]/)[0] ?? "";
42343
42585
  if (!rather && SKIP_AFTER_NOT.test(right)) continue;
42344
42586
  if (/\bor$/i.test(left.trim()) || /\bwhether\b/i.test(left)) continue;
42345
- const leftWords = words$2(left);
42346
- const rightWords = words$2(right);
42587
+ const leftWords = words$1(left);
42588
+ const rightWords = words$1(right);
42347
42589
  if (leftWords.length < 3 || !rightWords.length) continue;
42348
42590
  if (leftWords.length + rightWords.length <= 5 && verbless(text)) continue;
42349
42591
  const lastLeft = leftWords[leftWords.length - 1];
@@ -42441,12 +42683,12 @@ const ABSTRACT_TRIAD = /\b[a-z]+(?:tion|sion|ity|ness|ment|ence|ance|ism), (?:an
42441
42683
  const ECHO = new Set("to our your their my his her its every each more less no it they we you".split(" "));
42442
42684
  const COPULA = /\b(?:is|are|was|were|'s|feels?|felt|looks?|stays?|remains?|seems?)\s+$/i;
42443
42685
  function formulaTriad(items, before) {
42444
- const firsts = items.map((item) => words$2(item)[0]?.toLowerCase() ?? "");
42686
+ const firsts = items.map((item) => words$1(item)[0]?.toLowerCase() ?? "");
42445
42687
  const echo = firsts[0] ?? "";
42446
42688
  if (ECHO.has(echo) && firsts.every((first) => first === echo)) return `Each item opens with "${echo}".`;
42447
- if (items.every((item) => /^(?:the|their|our|your|its|it|they|we|you|he|she)\b/i.test(item) && words$2(item).length >= 3 && words$2(item).length <= 7 && !verbless(item))) return "Three parallel clauses in a row.";
42448
- if (items.every((item) => /^[a-z]/.test(item) && words$2(item).length <= 2 && !PREPOSITIONS.has(words$2(item)[0] ?? "")) && COPULA.test(before)) return "A string of adjectives after \"is\".";
42449
- if (items.every((item) => /^\w+ed\b/i.test(item) && words$2(item).length <= 3)) return "A string of past participles.";
42689
+ if (items.every((item) => /^(?:the|their|our|your|its|it|they|we|you|he|she)\b/i.test(item) && words$1(item).length >= 3 && words$1(item).length <= 7 && !verbless(item))) return "Three parallel clauses in a row.";
42690
+ if (items.every((item) => /^[a-z]/.test(item) && words$1(item).length <= 2 && !PREPOSITIONS.has(words$1(item)[0] ?? "")) && COPULA.test(before)) return "A string of adjectives after \"is\".";
42691
+ if (items.every((item) => /^\w+ed\b/i.test(item) && words$1(item).length <= 3)) return "A string of past participles.";
42450
42692
  return null;
42451
42693
  }
42452
42694
  function triads(ctx) {
@@ -42474,13 +42716,13 @@ function triads(ctx) {
42474
42716
  const items = [...raw];
42475
42717
  const head = raw[0] ?? "";
42476
42718
  const lead = /^.*\b(?:is|are|was|were|'s|feels?|looks?|stays?|remains?|seems?|of|for|to|with|by|from|on|in|like|including|as)\s+/i.exec(head);
42477
- if (lead && words$2(head.slice(lead[0].length)).length) {
42719
+ if (lead && words$1(head.slice(lead[0].length)).length) {
42478
42720
  items[0] = head.slice(lead[0].length);
42479
42721
  from += lead[0].length;
42480
42722
  }
42481
42723
  const end = sentence.start + (match.index ?? 0) + match[0].length;
42482
42724
  const before = block.norm.slice(sentence.start, sentence.start + from);
42483
- const echo = words$2(raw[1] ?? "")[0]?.toLowerCase() ?? "";
42725
+ const echo = words$1(raw[1] ?? "")[0]?.toLowerCase() ?? "";
42484
42726
  const inFirst = new RegExp(`\\b${echo}\\b(?!.*\\b${echo}\\b)`, "i").exec(head);
42485
42727
  if (ECHO.has(echo) && inFirst && inFirst.index > 0) {
42486
42728
  items[0] = head.slice(inFirst.index);
@@ -42531,7 +42773,7 @@ function colonDensity(ctx) {
42531
42773
  const after = block.norm.slice(at + match[0].length);
42532
42774
  if (/^["'(]/.test(after)) continue;
42533
42775
  const lead = block.norm.slice(sentenceAt(sentences, at).start, at);
42534
- if (words$2(lead).length <= 4 && verbless(lead)) continue;
42776
+ if (words$1(lead).length <= 4 && verbless(lead)) continue;
42535
42777
  const source = block.map[at] ?? -1;
42536
42778
  if (/^(?:\*\*|__)/.test(ctx.doc.source.slice(source + 1, source + 3)) || /(?:\*\*|__)$/.test(ctx.doc.source.slice(source - 2, source))) continue;
42537
42779
  if (block.links.some((link) => link.start <= at && link.end > at)) continue;
@@ -42597,7 +42839,7 @@ function heresAnnouncement(ctx) {
42597
42839
  ])) for (const sentence of ctx.sentences(block)) {
42598
42840
  const text = sentence.text;
42599
42841
  if (!/^(?:And |So |But )?Here(?:'s| is| are) (?:the|what|why|how|who|where|when|a|an|my|our|some|two|three|four|five)\b/i.test(text) || /^(?:And |So |But )?Here's the (?:thing|deal|kicker|catch|twist|truth|secret|reality)\b/i.test(text)) continue;
42600
- const count = words$2(text).length;
42842
+ const count = words$1(text).length;
42601
42843
  const colon = text.endsWith(":");
42602
42844
  const sentences = ctx.sentences(block);
42603
42845
  if (sentence === sentences[sentences.length - 1]) {
@@ -42625,7 +42867,7 @@ const LEADING_CLAUSE = /^(?:without|with|for|in|on|at|after|before|if|when|once|
42625
42867
  const MONTH = /\b(?:january|february|march|april|may|june|july|august|september|october|november|december|monday|tuesday|wednesday|thursday|friday|saturday|sunday)\b/i;
42626
42868
  const KICKER = /^(?:That's it|That's all|No exceptions|No catch|No strings attached|No surprises|No asterisks|Period|Full stop|Simple as that|It's that simple|That simple|Nothing more|Nothing else)[.!]$/i;
42627
42869
  function slogan(text) {
42628
- const list = words$2(text);
42870
+ const list = words$1(text);
42629
42871
  return /[.!]$/.test(text) && !/^Not\b/.test(text) && list.length >= 1 && list.length <= 4 && !GREETING.test(text) && !MONTH.test(text) && !list.every((word) => /^[A-Z0-9]/.test(word)) && verbless(text);
42630
42872
  }
42631
42873
  function fragmentRuns(ctx, rule) {
@@ -42634,7 +42876,7 @@ function fragmentRuns(ctx, rule) {
42634
42876
  for (let i = 1; i < sentences.length; i++) {
42635
42877
  const before = sentences[i - 1];
42636
42878
  const sentence = sentences[i];
42637
- const kicker = KICKER.test(sentence.text) && words$2(before.text).length <= 8;
42879
+ const kicker = KICKER.test(sentence.text) && words$1(before.text).length <= 8;
42638
42880
  const pair = slogan(before.text) && slogan(sentence.text);
42639
42881
  if (!kicker && !pair) continue;
42640
42882
  ctx.hit(rule, block, before.start, sentence.end, kicker ? `"${sentence.text}" is a kicker added for rhythm after a short line.` : "Two verbless fragments in a row read as a slogan, not a sentence.", "Join them into one plain sentence with a verb, such as \"Books close within 48 hours of month end, every month,\" or cut the kicker.");
@@ -42649,14 +42891,14 @@ function pithyFragment(ctx) {
42649
42891
  for (const block of ctx.blocks(RHYTHM_KINDS)) for (const sentence of ctx.sentences(block)) {
42650
42892
  const text = sentence.text;
42651
42893
  if (!/[.!]$/.test(text)) continue;
42652
- const list = words$2(text);
42894
+ const list = words$1(text);
42653
42895
  if (list.length < 2 || list.length > 6) continue;
42654
42896
  if (GREETING.test(text) || MONTH.test(text)) continue;
42655
42897
  if (list.every((word) => /^[A-Z0-9]/.test(word))) continue;
42656
42898
  if (!verbless(text)) continue;
42657
42899
  const strong = TWO_BEAT.some((re) => re.test(text));
42658
42900
  const [left = "", right = ""] = text.split(",");
42659
- const twoBeat = text.split(",").length === 2 && words$2(left).length <= 3 && words$2(right).length <= 3 && !LEADING_CLAUSE.test(left.trim()) && !LEADING_CLAUSE.test(right.trim());
42901
+ const twoBeat = text.split(",").length === 2 && words$1(left).length <= 3 && words$1(right).length <= 3 && !LEADING_CLAUSE.test(left.trim()) && !LEADING_CLAUSE.test(right.trim());
42660
42902
  if (!strong && !twoBeat) continue;
42661
42903
  ctx.hit(rule, block, sentence.start, sentence.end, "A verbless two-beat fragment reads as a slogan, not a sentence.", "Write a full sentence with a subject and a verb that says what happened, or join it to the sentence before.", strong ? void 0 : "warning");
42662
42904
  }
@@ -42678,7 +42920,7 @@ function stockCloser(ctx) {
42678
42920
  ctx.hit(rule, block, sentence.start, sentence.end, "A stock kicker that tells the reader how to feel about the last point.", "Cut it. If the text already has the number or fact that makes the point, end on that.");
42679
42921
  continue;
42680
42922
  }
42681
- if (/^(?:but |and )?(?:that|this)(?:'s| is) not (?:how|what|why|where|a|an|the)\b/i.test(text) && words$2(text).length <= 10) ctx.hit(reframe, block, sentence.start, sentence.end, "A short \"That's not ...\" line dismisses a view instead of stating one.", "Cut it, or say what is true with a fact the text already gives.");
42923
+ if (/^(?:but |and )?(?:that|this)(?:'s| is) not (?:how|what|why|where|a|an|the)\b/i.test(text) && words$1(text).length <= 10) ctx.hit(reframe, block, sentence.start, sentence.end, "A short \"That's not ...\" line dismisses a view instead of stating one.", "Cut it, or say what is true with a fact the text already gives.");
42682
42924
  }
42683
42925
  }
42684
42926
  const FIGURATIVE_NOUNS = "fights?|battles?|hills?|wars?|bets?|gambles?|races?|risks?|horses?|roads?|bridges?|doors?|games?|ships?|cards?";
@@ -42722,7 +42964,7 @@ function staccato(ctx) {
42722
42964
  }
42723
42965
  run = [];
42724
42966
  };
42725
- for (const sentence of sentences) if (words$2(sentence.text).length <= 4) run.push(sentence);
42967
+ for (const sentence of sentences) if (words$1(sentence.text).length <= 4) run.push(sentence);
42726
42968
  else report();
42727
42969
  report();
42728
42970
  }
@@ -42775,11 +43017,11 @@ function anaphora(ctx) {
42775
43017
  const sentences = ctx.sentences(block);
42776
43018
  let i = 0;
42777
43019
  while (i < sentences.length) {
42778
- const first = words$2(sentences[i].text)[0]?.toLowerCase();
43020
+ const first = words$1(sentences[i].text)[0]?.toLowerCase();
42779
43021
  let j = i + 1;
42780
- while (j < sentences.length && first && words$2(sentences[j].text)[0]?.toLowerCase() === first) j++;
43022
+ while (j < sentences.length && first && words$1(sentences[j].text)[0]?.toLowerCase() === first) j++;
42781
43023
  const run = sentences.slice(i, j);
42782
- if (first === "no" && j - i >= 2 && run.every((sentence) => /^No (?!one\b|matter\b|doubt\b|longer\b|way\b|wonder\b)[a-z$\d]/.test(sentence.text) && words$2(sentence.text).length <= 12)) ctx.hit(rule, block, sentences[i].start, sentences[j - 1].end, `${j - i} sentences in a row start with "No", a drumbeat of things the product is not.`, "Say what it is in one sentence, and keep only the one \"no\" a reader needs, such as \"One flat monthly fee with no tiers.\"");
43024
+ if (first === "no" && j - i >= 2 && run.every((sentence) => /^No (?!one\b|matter\b|doubt\b|longer\b|way\b|wonder\b)[a-z$\d]/.test(sentence.text) && words$1(sentence.text).length <= 12)) ctx.hit(rule, block, sentences[i].start, sentences[j - 1].end, `${j - i} sentences in a row start with "No", a drumbeat of things the product is not.`, "Say what it is in one sentence, and keep only the one \"no\" a reader needs, such as \"One flat monthly fee with no tiers.\"");
42783
43025
  else if (j - i >= 3 && first && ![
42784
43026
  "the",
42785
43027
  "a",
@@ -42791,7 +43033,7 @@ function anaphora(ctx) {
42791
43033
  "it",
42792
43034
  "this"
42793
43035
  ].includes(first)) {
42794
- if (run.every((sentence) => words$2(sentence.text).length <= 7) && /^(?:it's|they|we|you)$/.test(first)) ctx.hit(rule, block, sentences[i].start, sentences[j - 1].end, `${j - i} short sentences in a row start with "${first}".`, "Merge them into one sentence or a short list.");
43036
+ if (run.every((sentence) => words$1(sentence.text).length <= 7) && /^(?:it's|they|we|you)$/.test(first)) ctx.hit(rule, block, sentences[i].start, sentences[j - 1].end, `${j - i} short sentences in a row start with "${first}".`, "Merge them into one sentence or a short list.");
42795
43037
  else ctx.review("anaphora", block, sentences[i].start, sentences[j - 1].end, `${j - i} sentences in a row start with "${first}". Does the repeat help the reader follow a real list, or is it there for rhythm?`);
42796
43038
  }
42797
43039
  i = j;
@@ -43062,226 +43304,6 @@ function lintReportText(files) {
43062
43304
  if (reviews) lines.push("Errors and warnings each come with a fix. Review items are judgement calls: change a line only when it fails the question.");
43063
43305
  return lines.join("\n").trimEnd();
43064
43306
  }
43065
- // packages/core/dist/analyze/ai-queries.js
43066
- const RULES = [
43067
- ["agent_prompt", "^(search the web for|browse the web|find sources)|do not invent|return the [0-9]+ most relevant|include source urls|context: location|do not include location|question: |reply only with|the model you are using"],
43068
- ["tracker", "\\. ?my location is |\\?\\. ?my( |$)|^evaluate the .+ on "],
43069
- ["reply", "^(yes|yeah|yep|ok|okay|sure|yes please|go on|continue|keep going|tell me more|why not|how so|really|exactly|show me|and then|thanks|thank you|got it|what else|anything else)[?!.,]*$"],
43070
- ["follow_up", "^(what|how) about .{1,40}$|^(and|so|ok so|okay so|but) (what|which|how|why) "],
43071
- ["operator", "(^|\\s)-?(site|before|after|intitle|inurl|intext|filetype):|\"[^\"]*\" or \""],
43072
- ["chat", "\\b(please|can you|could you|give me|show me|tell me|i want|i need|i have|i am|should i|do i need|is it worth|help me|walk me through)\\b|^(what|how|why|is|does|can|will|would) (it|that|this|they)\\b"],
43073
- ["long", "^(\\S+\\s+){9,}\\S+$"]
43074
- ];
43075
- const AI_QUERY_KINDS = {
43076
- agent_prompt: "text from an agent prompt, such as \"search the web for\"",
43077
- tracker: "a visibility-tool probe, such as \"my location is\"",
43078
- reply: "a bare reply, such as \"yes\" or \"tell me more\"",
43079
- follow_up: "a follow-up, such as \"what about …\"",
43080
- operator: "search operators, such as site:, before: or \"a\" or \"b\"",
43081
- chat: "chat phrasing, such as \"can you\" or \"should i\"",
43082
- long: "ten or more words with no other sign"
43083
- };
43084
- const MATCHERS = RULES.map(([kind, pattern]) => [kind, new RegExp(pattern)]);
43085
- const AI_QUERY_PATTERN = RULES.map(([, pattern]) => `(?:${pattern})`).join("|");
43086
- const NOISE = [
43087
- ["spaced_letters", /(^|\s)(\S\s){3,}\S(\s|$)/u],
43088
- ["broken_encoding", /^(яю|ÿþ|þÿ)|&#[0-9]+;?|&[a-z]+;|[âÃÂ][\u0080-\u00bf€™œ“”]|\ufffd/u],
43089
- ["pasted_text", /^(p [a-z]{3,} |here (are|is) (all )?the |here's the |done[,.!]? (you|here) |current state: )/u]
43090
- ];
43091
- function aiQueryNoise(query) {
43092
- const text = query.trim().toLowerCase();
43093
- return NOISE.find(([, pattern]) => pattern.test(text))?.[0] ?? null;
43094
- }
43095
- const QUESTION = /^(how|what|what's|whats|which|why|when|where|who|is|are|can|could|does|do|should|would|will|i need|i want|i have|i'm looking|we need|we want)\b|\?$/u;
43096
- const ASKABLE_KINDS = /* @__PURE__ */ new Set(["chat", "long"]);
43097
- const PROMPT_CHARACTERS = 500;
43098
- function askable(query, kind) {
43099
- const text = query.trim().toLowerCase().replace(/^["'“]+/u, "");
43100
- return Boolean(kind && ASKABLE_KINDS.has(kind)) && text.length <= PROMPT_CHARACTERS && QUESTION.test(text);
43101
- }
43102
- function aiQueryKind(query) {
43103
- const text = query.trim().toLowerCase();
43104
- return MATCHERS.find(([, pattern]) => pattern.test(text))?.[0] ?? null;
43105
- }
43106
- const STOP = new Set("the and for with that this what which who how why when where are is was can does do did you your our from about into than then them they their there have has had will would should could not but its it’s me my i am of to in on at by or an as be if so".split(" "));
43107
- function words$1(query) {
43108
- return new Set(query.toLowerCase().split(/[^\p{L}\p{N}]+/u).filter((word) => word.length >= 3 && !STOP.has(word)).map((word) => word.length > 4 && word.endsWith("s") ? word.slice(0, -1) : word));
43109
- }
43110
- const SAME_QUESTION = .6;
43111
- const MAX_ROWS = 25e3;
43112
- const EXAMPLES = 3;
43113
- const CANDIDATES = 200;
43114
- const overlap = (a, b, weight) => {
43115
- let shared = 0;
43116
- let union = 0;
43117
- for (const word of a) {
43118
- union += weight(word);
43119
- if (b.has(word)) shared += weight(word);
43120
- }
43121
- for (const word of b) if (!a.has(word)) union += weight(word);
43122
- return union ? shared / union : 0;
43123
- };
43124
- const round = (value, places) => Math.round(value * 10 ** places) / 10 ** places;
43125
- async function aiQueriesReport(input, searchAnalytics) {
43126
- const range = {
43127
- startDate: input.startDate,
43128
- endDate: input.endDate
43129
- };
43130
- const [matched, site] = await Promise.all([searchAnalytics(input.site, {
43131
- ...range,
43132
- dimensions: ["query", "page"],
43133
- type: "web",
43134
- dataState: "final",
43135
- maxRows: MAX_ROWS,
43136
- dimensionFilterGroups: [{ filters: [{
43137
- dimension: "query",
43138
- operator: "includingRegex",
43139
- expression: AI_QUERY_PATTERN
43140
- }] }]
43141
- }), searchAnalytics(input.site, {
43142
- ...range,
43143
- dimensions: [],
43144
- type: "web",
43145
- dataState: "final"
43146
- })]);
43147
- const rows = [...matched.rows].sort((a, b) => b.impressions - a.impressions || String(a.keys[0]).localeCompare(String(b.keys[0])) || String(a.keys[1]).localeCompare(String(b.keys[1])));
43148
- const usage = /* @__PURE__ */ new Map();
43149
- const unique = new Set(rows.map((row) => String(row.keys[0] ?? "")));
43150
- for (const query of unique) for (const word of words$1(query)) usage.set(word, (usage.get(word) ?? 0) + 1);
43151
- const weight = (word) => Math.log((unique.size + 1) / (usage.get(word) ?? 1));
43152
- const groups = [];
43153
- const byWord = /* @__PURE__ */ new Map();
43154
- const byText = /* @__PURE__ */ new Map();
43155
- const kindOf = /* @__PURE__ */ new Map();
43156
- const noise = /* @__PURE__ */ new Map();
43157
- for (const row of rows) {
43158
- const query = String(row.keys[0] ?? "");
43159
- const page = String(row.keys[1] ?? "");
43160
- const kind = aiQueryKind(query);
43161
- if (!kind) continue;
43162
- const junk = aiQueryNoise(query);
43163
- if (junk) {
43164
- const seen = noise.get(junk) ?? /* @__PURE__ */ new Set();
43165
- seen.add(query.trim().toLowerCase());
43166
- noise.set(junk, seen);
43167
- continue;
43168
- }
43169
- const text = query.trim().toLowerCase();
43170
- const own = words$1(query);
43171
- let group = byText.get(text);
43172
- if (!group) {
43173
- let checked = 0;
43174
- for (const word of own) {
43175
- for (const candidate of byWord.get(word) ?? []) {
43176
- if (++checked > CANDIDATES) break;
43177
- if (overlap(own, candidate.words, weight) >= SAME_QUESTION) {
43178
- group = candidate;
43179
- break;
43180
- }
43181
- }
43182
- if (group || checked > CANDIDATES) break;
43183
- }
43184
- }
43185
- if (!group) {
43186
- group = {
43187
- words: own,
43188
- queries: /* @__PURE__ */ new Map(),
43189
- pages: /* @__PURE__ */ new Map(),
43190
- kinds: /* @__PURE__ */ new Map(),
43191
- clicks: 0,
43192
- impressions: 0,
43193
- positionWeight: 0
43194
- };
43195
- groups.push(group);
43196
- for (const word of own) {
43197
- const list = byWord.get(word) ?? [];
43198
- list.push(group);
43199
- byWord.set(word, list);
43200
- }
43201
- }
43202
- byText.set(text, group);
43203
- if (!kindOf.has(text)) {
43204
- kindOf.set(text, kind);
43205
- group.kinds.set(kind, (group.kinds.get(kind) ?? 0) + 1);
43206
- }
43207
- group.queries.set(query, (group.queries.get(query) ?? 0) + row.impressions);
43208
- group.pages.set(page, (group.pages.get(page) ?? 0) + row.impressions);
43209
- group.clicks += row.clicks;
43210
- group.impressions += row.impressions;
43211
- group.positionWeight += row.position * row.impressions;
43212
- }
43213
- const byKind = /* @__PURE__ */ new Map();
43214
- for (const kind of kindOf.values()) {
43215
- const entry = byKind.get(kind) ?? {
43216
- queries: 0,
43217
- impressions: 0
43218
- };
43219
- entry.queries += 1;
43220
- byKind.set(kind, entry);
43221
- }
43222
- for (const row of rows) {
43223
- const kind = kindOf.get(String(row.keys[0] ?? "").trim().toLowerCase());
43224
- const entry = kind && byKind.get(kind);
43225
- if (entry) entry.impressions += row.impressions;
43226
- }
43227
- const queries = kindOf.size;
43228
- const impressions = groups.reduce((sum, g) => sum + g.impressions, 0);
43229
- const clicks = groups.reduce((sum, g) => sum + g.clicks, 0);
43230
- const total = site.rows[0] ?? {
43231
- clicks: 0,
43232
- impressions: 0
43233
- };
43234
- const items = groups.map((group) => {
43235
- const most = (map) => [...map].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0])).map(([name]) => name);
43236
- const [first, ...rest] = most(group.queries);
43237
- const kind = [...group.kinds].sort((a, b) => b[1] - a[1] || a[0].localeCompare(b[0]))[0]?.[0];
43238
- return {
43239
- query: first ?? "",
43240
- page: most(group.pages)[0] ?? "",
43241
- askable: askable(first ?? "", kind),
43242
- pages: group.pages.size,
43243
- kind,
43244
- wordings: group.queries.size,
43245
- impressions: group.impressions,
43246
- clicks: group.clicks,
43247
- ctr: group.impressions ? round(group.clicks / group.impressions, 4) : 0,
43248
- position: group.impressions ? round(group.positionWeight / group.impressions, 1) : 0,
43249
- otherWordings: rest.slice(0, EXAMPLES)
43250
- };
43251
- }).sort((a, b) => b.impressions - a.impressions || b.wordings - a.wordings || a.query.localeCompare(b.query) || a.page.localeCompare(b.page));
43252
- const pct = (part, whole) => whole ? round(part / whole * 100, 1) : null;
43253
- const kinds = [...byKind].sort((a, b) => b[1].impressions - a[1].impressions || a[0].localeCompare(b[0])).map(([kind, entry]) => `${kind} ${entry.queries}`).join(", ");
43254
- const leftOut = [...noise].sort((a, b) => a[0].localeCompare(b[0])).map(([reason, seen]) => `${reason.replace("_", " ")} ${seen.size}`).join(", ");
43255
- const asked = items.filter((item) => item.askable).length;
43256
- const capped = matched.rowsFetched >= MAX_ROWS;
43257
- return {
43258
- range,
43259
- verdict: queries ? `${queries} queries in ${groups.length} questions have the shape of AI conversations or agent searches.` : "No queries with the shape of AI conversations or agent searches.",
43260
- summary: {
43261
- queries,
43262
- questions: groups.length,
43263
- askable: asked,
43264
- leftOut: leftOut || "none",
43265
- impressions,
43266
- clicks,
43267
- shareOfImpressionsPct: pct(impressions, total.impressions),
43268
- byKind: kinds || "none",
43269
- ctr: impressions ? round(clicks / impressions, 4) : 0,
43270
- siteCtr: total.impressions ? round(total.clicks / total.impressions, 4) : 0
43271
- },
43272
- kinds: AI_QUERY_KINDS,
43273
- items,
43274
- caveats: [
43275
- "A heuristic: these queries match the patterns of AI conversations and agent searches. Search Console does not mark AI Mode or AI Overviews, and people type some of these too.",
43276
- "A minimum: Search Console leaves out rare queries, and these are rare by nature.",
43277
- "Rewordings of one question are grouped by their shared words; page is the page with the most impressions for it.",
43278
- "Left out and counted, not shown: letters split by spaces, text broken by a wrong encoding, and text pasted from a tool or an agent’s output.",
43279
- "askable: a chat or long question that opens with a question word or a request such as \"i need\", or ends with a question mark, so an AI engine can be asked it as it is. ai_answers checks the top askable questions only.",
43280
- "Search Console’s Generative AI report is not in its API, so it is not here.",
43281
- ...capped ? [`Capped at the first ${MAX_ROWS} matching query and page rows.`] : []
43282
- ]
43283
- };
43284
- }
43285
43307
  // packages/core/dist/commands/research-ahrefs.js
43286
43308
  async function ahrefs(key, input, missed, totals) {
43287
43309
  const where = targetParts(input).ahrefs;
@@ -44073,12 +44095,6 @@ const DIMENSIONS = [
44073
44095
  "searchAppearance"
44074
44096
  ];
44075
44097
  const REGEX_MAX_CHARS = 4096;
44076
- const QUERY_PRESETS = {
44077
- questions: "^(who|what|where|when|why|how|is|are|can|does|do|should)\\b",
44078
- long_tail: "^(\\S+\\s+){7,}\\S+$",
44079
- comparisons: "\\b(vs|versus|alternatives?)\\b"
44080
- };
44081
- const QUERY_PRESET_NAMES = Object.keys(QUERY_PRESETS);
44082
44098
  function rowTextFilters(input) {
44083
44099
  return [
44084
44100
  [
@@ -44101,11 +44117,6 @@ function rowTextFilters(input) {
44101
44117
  "includingRegex",
44102
44118
  input.queryRegex
44103
44119
  ],
44104
- [
44105
- "query",
44106
- "includingRegex",
44107
- input.queryPreset && QUERY_PRESETS[input.queryPreset]
44108
- ],
44109
44120
  [
44110
44121
  "query",
44111
44122
  "excludingRegex",
@@ -44553,6 +44564,7 @@ async function runAiAnswers(input, headers, deps, more) {
44553
44564
  ] : []];
44554
44565
  const shown = rows.map((row) => ({
44555
44566
  question: row.question,
44567
+ shape: queryShape(row.question),
44556
44568
  impressions: row.impressions,
44557
44569
  engine: row.engine,
44558
44570
  result: row.result,
@@ -47762,6 +47774,33 @@ async function bingLead(overview, bing, origin, rowsPerList) {
47762
47774
  return null;
47763
47775
  }
47764
47776
  }
47777
+ const SHAPED = /* @__PURE__ */ new Set([
47778
+ "quick-wins",
47779
+ "low-ctr",
47780
+ "striking-distance",
47781
+ "second-page",
47782
+ "ai-queries"
47783
+ ]);
47784
+ function labelShapes(report, count) {
47785
+ const queries = [];
47786
+ const visit = (value, depth) => {
47787
+ if (depth > 3 || !value || typeof value !== "object") return;
47788
+ if (Array.isArray(value)) {
47789
+ for (const item of value) visit(item, depth + 1);
47790
+ return;
47791
+ }
47792
+ const row = value;
47793
+ if (typeof row.query === "string") {
47794
+ queries.push(row.query);
47795
+ const shape = queryShape(row.query);
47796
+ if (shape) row.shape = shape;
47797
+ }
47798
+ for (const [key, child] of Object.entries(row)) if (Array.isArray(child) && key !== "caveats") visit(child, depth + 1);
47799
+ };
47800
+ visit(report.items, 0);
47801
+ const line = count && queryShapeLine(queries);
47802
+ if (line) report.queryShapes = line;
47803
+ }
47765
47804
  async function build(read, site, section, range, now, bing) {
47766
47805
  const dependencies = {
47767
47806
  searchAnalytics: read,
@@ -47829,7 +47868,9 @@ async function build(read, site, section, range, now, bing) {
47829
47868
  }, read),
47830
47869
  bing: async () => bingSection(await bing(), read, site, range)
47831
47870
  }[section];
47832
- return factsOnly(await run());
47871
+ const report = factsOnly(await run());
47872
+ if (SHAPED.has(section)) labelShapes(report, section !== "ai-queries");
47873
+ return report;
47833
47874
  }
47834
47875
  function brandNote(report) {
47835
47876
  const brand = report.brand;
@@ -47914,6 +47955,7 @@ async function allSections(input, deps) {
47914
47955
  parts.push([
47915
47956
  `## ${id}: ${shown.total} ${shown.total === 1 ? "row" : "rows"}`,
47916
47957
  SECTIONS[id],
47958
+ typeof run.queryShapes === "string" ? run.queryShapes : null,
47917
47959
  shown.text,
47918
47960
  id === "traffic-drop" ? listOfUpdates(run.googleUpdates, run.updateWindow) : null
47919
47961
  ].filter(Boolean).join("\n"));
@@ -48006,6 +48048,7 @@ async function oneSection(input, deps) {
48006
48048
  report.pageChecks = checked;
48007
48049
  }
48008
48050
  const notes = money ? [money] : [];
48051
+ if (typeof report.queryShapes === "string") notes.push(report.queryShapes);
48009
48052
  const brand = brandNote(report);
48010
48053
  if (brand) notes.push(brand);
48011
48054
  const updates = listOfUpdates(report.googleUpdates, report.updateWindow);
@@ -48768,6 +48811,12 @@ async function runPage(input, deps) {
48768
48811
  });
48769
48812
  }
48770
48813
  rows.sort((a, b) => Number(b.clicks) - Number(a.clicks) || Number(b.impressions) - Number(a.impressions));
48814
+ const shaped = rows.map((row) => ({
48815
+ query: row.query,
48816
+ shape: queryShape(String(row.query ?? "")),
48817
+ ...row
48818
+ }));
48819
+ const shapes = queryShapeLine(rows.map((row) => String(row.query ?? "")));
48771
48820
  const sum = (list, key) => list.reduce((total, row) => total + row[key], 0);
48772
48821
  const offset = input.offset ?? 0;
48773
48822
  return {
@@ -48780,12 +48829,13 @@ async function runPage(input, deps) {
48780
48829
  ...reason ? [`Google's reason: ${reason.reason}. Label: ${reason.label}. ${reason.why} (Labels are rules over this evidence, not Google's; ${deps.call("index")} explains them.)`] : [],
48781
48830
  ...indexed && /^URL is unknown to Google$/i.test(indexed.coverage ?? "") ? [unknownNext(input, sitemap.urls.includes(input.url), deps)] : [],
48782
48831
  `Query totals: clicks ${sum(now.rows, "clicks")} (was ${sum(then.rows, "clicks")}), impressions ${sum(now.rows, "impressions")} (was ${sum(then.rows, "impressions")}). Search Console hides rare queries, so these can be lower than the page total.`,
48832
+ ...shapes ? [shapes] : [],
48783
48833
  deps.pageMarkdown ? `Main content as Markdown: ${deps.call("page", {
48784
48834
  url: input.url,
48785
48835
  detail: "full"
48786
48836
  })}.` : `Main content as Markdown: only in the CLI and the local MCP server, with \`npx -y seo page --url ${input.url} --detail full\`.`
48787
48837
  ],
48788
- rows,
48838
+ rows: shaped,
48789
48839
  offset,
48790
48840
  limit: 50,
48791
48841
  detail: input.detail ?? "summary",
@@ -48809,7 +48859,7 @@ async function runPage(input, deps) {
48809
48859
  indexInspectedAt: savedAt,
48810
48860
  reason,
48811
48861
  totalQueries: rows.length,
48812
- queries: rows.slice(offset, offset + 50),
48862
+ queries: shaped.slice(offset, offset + 50),
48813
48863
  ...full ? { markdown } : {}
48814
48864
  }
48815
48865
  };
@@ -49556,14 +49606,13 @@ const SHARED_TOOLS = [
49556
49606
  name: "seo_data",
49557
49607
  command: "data",
49558
49608
  title: "Raw rows",
49559
- description: `Raw rows for questions the report does not answer. search_console (default): rows for any dimensions, each with the previous period and the change; page and query narrow to rows whose URL or query contains that text; query_preset picks questions, long_tail (8+ words) or comparisons; *_regex take RE2 (no lookarounds). google_analytics: landing pages for visits from search, with Google Analytics’ own metric names. bing: Bing Webmaster query or page rows (first dimension) for the same site, by week. clicky: landing-page visits, traffic sources and search engines from a Clicky site the person saved (site is its domain or Clicky site ID; at most 31 days).`,
49609
+ description: `Raw rows for questions the report does not answer. search_console (default): rows for any dimensions, each with the previous period and the change; page and query narrow to rows whose URL or query contains that text; page_regex, query_regex and exclude_query_regex take RE2 regexes for custom cuts. google_analytics: landing pages for visits from search, with Google Analytics’ own metric names. bing: Bing Webmaster query or page rows (first dimension) for the same site, by week. clicky: landing-page visits, traffic sources and search engines from a Clicky site the person saved (site is its domain or Clicky site ID; at most 31 days).`,
49560
49610
  input: z.object({
49561
49611
  source: z.enum(DATA_SOURCES).default("search_console"),
49562
49612
  site: z.string().min(1).describe("search_console and bing: the property or site. google_analytics: numeric property id from seo_sites. clicky: the site or its Clicky site ID."),
49563
49613
  dimensions: z.array(z.enum(DIMENSIONS)).max(4).default(["query"]).describe("search_console; bing uses the first, query or page."),
49564
49614
  page: z.string().min(1).optional().describe("search_console only: URL text, such as /blog/."),
49565
49615
  query: z.string().min(1).optional().describe("search_console only: query text."),
49566
- query_preset: z.enum(QUERY_PRESET_NAMES).optional(),
49567
49616
  page_regex: z.string().min(1).max(REGEX_MAX_CHARS).optional().describe("search_console only: RE2 the page URL must match."),
49568
49617
  query_regex: z.string().min(1).max(REGEX_MAX_CHARS).optional().describe("search_console only: RE2 the query must match."),
49569
49618
  exclude_query_regex: z.string().min(1).max(REGEX_MAX_CHARS).optional().describe("search_console only: RE2 for queries to leave out, such as the brand."),
@@ -49608,7 +49657,6 @@ const SHARED_TOOLS = [
49608
49657
  query: input.query,
49609
49658
  pageRegex: input.page_regex,
49610
49659
  queryRegex: input.query_regex,
49611
- queryPreset: input.query_preset,
49612
49660
  excludeQueryRegex: input.exclude_query_regex
49613
49661
  }),
49614
49662
  startDate: input.start_date,